|
1 | 1 | ''' |
2 | | -Retrieve a day's forecast of New York City and create a graph |
| 2 | +Retrieve three days' forecast of New York City and create a graph |
3 | 3 | Using https://github.com/csparpa/pyowm |
4 | 4 | ''' |
5 | 5 | import matplotlib.pyplot as plt |
6 | 6 | from pyowm import OWM |
7 | 7 |
|
8 | | -owm = OWM() |
| 8 | +owm = OWM('54c5451fcc146ce043f4f44153e4ea4b') |
9 | 9 |
|
10 | 10 | def get_forecast(city): |
11 | | - fc = owm.daily_forecast(city, limit=1) |
| 11 | + # https://github.com/csparpa/pyowm/issues/266 |
| 12 | + fc = owm.three_hours_forecast(city) |
12 | 13 | f = fc.get_forecast() |
13 | | - w = f.get_weathers()[0] |
14 | | - forecast_temp = w.get_temperature('celsius') |
15 | | - day_intervals = ['morn', 'day', 'eve', 'night'] |
| 14 | + |
| 15 | + # three_hours_forecast() returns 5 day forecast at a granularity |
| 16 | + # of three hours |
| 17 | + # we plot them all |
| 18 | + weathers = f.get_weathers() |
| 19 | + |
| 20 | + |
| 21 | + data_points = ['temp', 'temp_max', 'temp_min', 'temp_kf'] |
16 | 22 | temp = [] |
17 | | - for timeofday in day_intervals: |
18 | | - temp.append(forecast_temp[point]) |
19 | | - x = range(1, len(day_intervals)+1) |
| 23 | + for w in weathers: |
| 24 | + forecast_temp = w.get_temperature('celsius') |
| 25 | + #for point in data_points: |
| 26 | + temp.append(forecast_temp['temp']) |
| 27 | + x = range(1, len(temp)+1) |
20 | 28 | plt.plot(x, temp, 'o-') |
21 | | - plt.xticks(x, day_intervals) |
| 29 | + #plt.xticks(x, day_intervals) |
22 | 30 | plt.show() |
23 | 31 |
|
24 | 32 | if __name__ == '__main__': |
|
0 commit comments