Make script ready for missing visibility information in JSON.
[chrisu/seepark.git] / owm.py
diff --git a/owm.py b/owm.py
index c57b2422b24550b012bd415458048e99357f2a6a..6f7ba24c720e245e908ab718ffe5b3d02322c038 100755 (executable)
--- a/owm.py
+++ b/owm.py
@@ -37,7 +37,6 @@ def extractweatherdata(w):
         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'],
@@ -51,6 +50,7 @@ def extractweatherdata(w):
     data['winddegrees'] = w['wind']['deg'] if 'deg' in w['wind'] else math.nan
     data['winddirection'] = degToCompass(data['winddegrees'])
     data['precipitation'] = w['rain']['3h'] if 'rain' in w else math.nan
+    data['visibility'] = w.get('visibility', math.nan)
 
     return data