Make script ready for missing visibility information in JSON.
authorPhilipp Spitzer <philipp@spitzer.priv.at>
Wed, 25 Jul 2018 20:03:18 +0000 (22:03 +0200)
committerPhilipp Spitzer <philipp@spitzer.priv.at>
Wed, 25 Jul 2018 20:03:18 +0000 (22:03 +0200)
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'],
         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'],
         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['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
 
 
     return data