def extractweatherdata(w):
data = dict(
- datetime = w.get('dt'),
- sunrise = w.get('sys').get('sunrise'),
- sunset = w.get('sys').get('sunset'),
- temp = w.get('main').get('temp'),
- pressure = w.get('main').get('pressure'),
- humidity = w.get('main').get('humidity'),
- visibility = w.get('visibility'),
- weather=w['weather'][0]['description'],
- sky=w['weather'][0]['main'],
- windspeed=w.get('wind').get('speed'),
- winddegrees=w.get('wind').get('deg'),
- cloudiness=w.get('clouds').get('all'),
- rain=w.get('rain'),
+ datetime = w['dt'],
+ sunrise = w['sys']['sunrise'],
+ sunset = w['sys']['sunset'],
+ temp = w['main']['temp'],
+ pressure = w['main']['pressure'],
+ humidity = w['main']['humidity'],
+ visibility = w['visibility'],
+ weather = w['weather'][0]['description'],
+ sky = w['weather'][0]['main'],
+ windspeed = w['wind']['speed'],
+ winddegrees = w['wind']['deg'],
+ cloudiness = w['clouds']['all'],
)
data['sunrise_t'] = fromtimestamp(data['sunrise'], '%H:%M:%S')
data['date'] = fromtimestamp(data['datetime'], '%Y-%m-%d')
data['time'] = fromtimestamp(data['datetime'], '%H:%M:%S')
data['winddirection'] = degToCompass(data['winddegrees'])
- if not data['rain'] is None:
- data['precipitation']=data['rain'].get('3h')
- else:
- data['precipitation']='N/A'
+ data['precipitation'] = w['rain']['3h'] if 'rain' in w else 'N/A'
return data