-
Notifications
You must be signed in to change notification settings - Fork 0
/
pyowm_helper.py
36 lines (31 loc) · 1021 Bytes
/
pyowm_helper.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
import os
import pyowm
from datetime import datetime
from timezone_conversion import gmt_to_asian
API_KEY = os.environ['API_KEY']
owm = pyowm.OWM(API_KEY)
mgr = owm.weather_manager()
def get_temperature():
days = []
dates = []
temp_min = []
temp_max = []
forecaster = mgr.forecast_at_place('Delhi, IN', '3h')
forecast = forecaster.forecast
for weather in forecast:
day = gmt_to_asian(weather.reference_time())
date = day.date()
if date not in dates:
dates.append(date)
temp_min.append(None)
temp_max.append(None)
days.append(date)
temperature = weather.temperature('celsius')['temp']
if not temp_min[-1] or temperature < temp_min[-1]:
temp_min[-1] = temperature
if not temp_max[-1] or temperature > temp_max[-1]:
temp_max[-1] = temperature
# print(days, temp_min, temp_max)
return(days, temp_min, temp_max)
if __name__ == '__main__':
get_temperature()