-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplotForecasts.py
More file actions
103 lines (79 loc) · 2.84 KB
/
Copy pathplotForecasts.py
File metadata and controls
103 lines (79 loc) · 2.84 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import plotly
import csv
import time
import datetime
from WeatherUndergroundForecast import WeatherUndergroundForecast
# This script will download the lastest forecast data every hour and upload the results to plotly for viewing
KEY_FILE = 'keys/plotly_api_key'
with open(KEY_FILE,'r') as api_key:
plotly_username = csv.reader(api_key).next()[1]
plotly_api = csv.reader(api_key).next()[1]
py = plotly.plotly(plotly_username, plotly_api)
HOME_STATE = 'MA'
HOME_TOWN = 'Wilmington'
wundergnd = WeatherUndergroundForecast()
wundergnd.get_api_keyi_from_file('keys/weather_underground_api_key')
wundergnd.state = HOME_STATE
wundergnd.town = HOME_TOWN
while True:
print "Updating at ",datetime.datetime.now()
wundergnd.updateForecast()
# Temperature
times,temps = wundergnd.get_temp_forecast()
timesfl,feelslike = wundergnd.get_feels_like_temp_forecast()
# Snowfall
times_snow,snow = wundergnd.get_snow_forecast ()
snow_cum = [0]
for s in snow:
snow_cum.append( snow_cum[-1]+s )
snow_cum.pop(0)
# Probability of precip
times_pop,pop = wundergnd.get_pop_forecast()
temp_data = {
'name': "Temperature (F)",
'x': times,
'y': temps,
'line':{'color':'blue','thickness':3}
}
feels_like_data = {
'name': "Feels like (F)",
'x': times,
'y': feelslike,
'line':{'color':'red','thickness':3}
}
snow_rate_data = {
'name': "Snowfall rate (in/hour)",
'x': times_snow,
'y': snow,
'line':{'color':'red','thickness':3}
}
snow_cum_data = {
'name': "Cumulative Snowfall (in)",
'x': times_snow,
'y': snow_cum,
'line':{'color':'blue','thickness':3}
}
pop_data = {
'name': "Probability of Precipitation",
'x': times_pop,
'y': pop,
'line':{'color':'blue','thickness':3}
}
layout_temp = {'title':'Temperature Forecast'}
layout_snow = {'title':'Snow Forecast'}
layout_pop = {'title':'Probability of precip'}
try:
out=py.plot([temp_data,feels_like_data],filename="TempForecast",
fileopt="overwrite",layout=layout_temp,
world_readable=True, width=1000, height=650)
out=py.plot([snow_rate_data,snow_cum_data],filename="SnowForecast",
fileopt="overwrite",layout=layout_snow,
world_readable=True, width=1000, height=650)
out=py.plot([pop_data],filename="Pop",
fileopt="overwrite",layout=layout_pop,
world_readable=True, width=1000, height=650)
except:
print "Connection Error, no update performed at ",datetime.datetime.now()
# Wait an hour
print "...complete"
time.sleep(60*60)