Make use of dict consistent.
[chrisu/seepark.git] / owm.py
diff --git a/owm.py b/owm.py
index 71f367730de84ab40b206b3ca0a3fbe44f8ad282..1e03670c7dbeb9a8b4e92b86e1b98216ae4c7d7c 100755 (executable)
--- 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