-
Notifications
You must be signed in to change notification settings - Fork 0
/
weather.py
37 lines (25 loc) · 887 Bytes
/
weather.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 requests,json
from datetime import datetime
from dateutil import tz
cityname = "edmonton"
Api = 'http://api.openweathermap.org/data/2.5/forecast?q='+cityname+'&APPID=27fe580edf919569d85245294e9ae834'
r = requests.get(Api);
d = json.loads(r.text)
print(len(d),d.keys())
min_temp = d["list"][0]["main"]["temp_min"]
max_temp = d["list"][0]["main"]["temp_max"]
min_temp1 = d["list"][1]["main"]["temp_min"]
max_temp1 = d["list"][1]["main"]["temp_max"]
print(min_temp1,min_temp,len(d["list"]))
print(d["list"])
from_zone = tz.gettz('UTC')
to_zone = tz.gettz('America/Edmonton')
# METHOD 2: Auto-detect zones:
from_zone = tz.tzutc()
to_zone = tz.tzlocal()
# utc = datetime.utcnow()
# Tell the datetime object that it's in UTC time zone since
# datetime objects are 'naive' by default
utc = utc.replace(tzinfo=from_zone)
# Convert time zone
central = utc.astimezone(to_zone)