From: Philipp Spitzer Date: Mon, 11 Jun 2018 18:10:57 +0000 (+0200) Subject: Make use of dict consistent. X-Git-Url: https://git.toastfreeware.priv.at/chrisu/seepark.git/commitdiff_plain/7ef92a3a747f972a2c5945255ef66f7c1ad4c8d7 Make use of dict consistent. --- diff --git a/owm.py b/owm.py index 71f3677..1e03670 100755 --- a/owm.py +++ b/owm.py @@ -45,19 +45,18 @@ def degToCompass(num): 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') @@ -65,10 +64,7 @@ def extractweatherdata(w): 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