-
Notifications
You must be signed in to change notification settings - Fork 0
/
forecast.py
66 lines (58 loc) · 1.88 KB
/
forecast.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
from framework import weather
#
# This File Handles displaying the weekly forcast.
# It fetches the forecast from weather underground,
# then displays it in a grid-based format.
#
# It also redirects back to the home page after 2 minutes,
# in case someone left it on this screen by accident.
#
# If you are looking for how to change it to your own location,
# You can find that option in settings.py
#
# Print the Header
print "Content-Type: text/html;charset=utf-8"
print
# Print HTML Header
print '''<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="refresh" content="120;URL=/">
<link rel="stylesheet" type="text/css" href="/css/common.css">
<link rel="stylesheet" type="text/css" href="/css/forecast.css">
</head>
<body>'''
# Get the week Forecast
parsed_json = weather.fetchWeather('forecast10day')
# Loop through the results, and print what is applicable
count = 0
for day in parsed_json['forecast']['simpleforecast']['forecastday']:
count += 1
print "<div class='box' id='box" + str(count) + "'>"
print "<span class='larger'>" + day['date']['weekday_short'] + "</span></br>"
print "<img class='larger' src=" + day['icon_url'] + " /></br>"
print "<span class='larger'>" + str(day['high']['fahrenheit']) + u'° </span> ('.encode('utf-8') + str(day['low']['fahrenheit']) + u'°) </br>'.encode('utf-8')
if day['pop'] > 0 and float(day['qpf_allday'][u'in']) > 0:
print str(day['pop']) + "% (" + str(day['qpf_allday'][u'in']) + "in)"
print "</div>"
if count >= 10:
break
weather.closeURL()
# Print the HTML Closing tags
print '''
<div class='bottombar'>
<a href="/radar.py"><div class='radar'>
Radar
</div></a>
<a href="/hourly.py"><div class='hourly'>
Hourly Forcast
</div></a>
<a href="/"><div class='back'>
<img id='logo' src='/img/back-icon.png' />
</div></a>
</div>
</body>
</html>'''