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
33Using https://github.com/csparpa/pyowm
44'''
55import matplotlib .pyplot as plt
99owm = OWM ('<token>' )
1010
1111def 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
3938if __name__ == '__main__' :
4039 get_forecast ('new york, us' )
40+
41+ if __name__ == '__main__' :
42+ get_forecast ('new york, us' )
0 commit comments