Skip to content

Commit 63f4503

Browse files
authored
Update nyc_forecast_owm.py
1 parent 531c62a commit 63f4503

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed
Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'''
2-
Retrieve three days' forecast of New York City and create a graph
2+
Retrieve a day's forecast of New York City and create a graph
33
Using https://github.com/csparpa/pyowm
44
'''
55
import matplotlib.pyplot as plt
@@ -9,16 +9,15 @@
99
owm = OWM('<token>')
1010

1111
def get_forecast(city):
12+
# this used to be daily_forecast
1213
# https://github.com/csparpa/pyowm/issues/266
1314
fc = owm.three_hours_forecast(city)
1415
f = fc.get_forecast()
1516

1617
# three_hours_forecast() returns 5 day forecast at a granularity
1718
# of three hours
18-
# we plot them all
19-
weathers = f.get_weathers()
20-
21-
19+
# We plot the forecast for the next 24 hours (so, first 8 intervals)
20+
weathers = f.get_weathers()[0:8]
2221
data_points = ['temp', 'temp_max', 'temp_min', 'temp_kf']
2322
temp = []
2423
date_time = []
@@ -29,12 +28,15 @@ def get_forecast(city):
2928
dt = utc_dt.astimezone(tz)
3029

3130
# print it
32-
date_time.append(dt.strftime('%Y-%m-%d %H:%M:%S %Z%z'))
31+
date_time.append(dt.strftime('%Y-%m-%d %H:%M'))
3332
temp.append(forecast_temp['temp'])
3433
x = range(1, len(temp)+1)
3534
plt.plot(x, temp, 'o-')
36-
plt.xticks(x, date_time)
35+
plt.xticks(x, date_time, rotation=45)
3736
plt.show()
3837

3938
if __name__ == '__main__':
4039
get_forecast('new york, us')
40+
41+
if __name__ == '__main__':
42+
get_forecast('new york, us')

0 commit comments

Comments
 (0)