-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcurrentWeatherFromFile.py
More file actions
30 lines (20 loc) · 932 Bytes
/
currentWeatherFromFile.py
File metadata and controls
30 lines (20 loc) · 932 Bytes
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
import json
import datetime
f = open('currentWeather.json', 'r')
data = f.read();
obj = json.loads(data)
print '{:20} {:20}'.format('city', obj.get('name'))
dt = obj.get('dt')
formattedDate = datetime.datetime.fromtimestamp(int(dt)).strftime('%Y-%m-%d %H:%M:%S')
print '{:20} {:20}'.format('date/time', formattedDate)
weatherMain = obj.get('weather')[0].get('main')
weatherDesc = obj.get('weather')[0].get('description')
print '{:20} {:20}'.format('weather', weatherMain + ' - ' + weatherDesc)
for l in obj.get('main'):
print '{:20} {:19}'.format(l, str(int(obj.get('main').get(l))))
sunrise = obj.get('sys').get('sunrise')
sunriseStr = datetime.datetime.fromtimestamp(int(sunrise)).strftime('%H:%M:%S')
print '{:20} {:20}'.format('sunrise', sunriseStr)
sunset = obj.get('sys').get('sunset')
sunsetStr = datetime.datetime.fromtimestamp(int(sunset)).strftime('%H:%M:%S')
print '{:20} {:20}'.format('sunset', sunsetStr)