From 868a19293dd7896eefc89228b4c490f80c39bd8f Mon Sep 17 00:00:00 2001 From: gregor herrmann Date: Fri, 15 Jun 2018 19:17:12 +0200 Subject: [PATCH] we can have wind without degrees (only speed) --- owm.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/owm.py b/owm.py index f8d6ccb..ada2567 100755 --- a/owm.py +++ b/owm.py @@ -40,7 +40,7 @@ def fromtimestamp(timestamp, format): # https://stackoverflow.com/questions/7490660/converting-wind-direction-in-angles-to-text-words def degToCompass(num): - if num is None: + if num is None or num is math.nan: return 'N/A' val=int((num/22.5)+.5) arr=["N","NNO","NO","ONO","O","OSO", "SO", "SSO","S","SSW","SW","WSW","W","WNW","NW","NNW"] @@ -48,6 +48,7 @@ def degToCompass(num): def extractweatherdata(w): + w['wind']['deg'] = math.nan data = dict( datetime = w['dt'], sunrise = w['sys']['sunrise'], @@ -59,7 +60,6 @@ def extractweatherdata(w): weather = w['weather'][0]['description'], sky = w['weather'][0]['main'], windspeed = w['wind']['speed'], - winddegrees = w['wind']['deg'], cloudiness = w['clouds']['all'], ) @@ -67,6 +67,7 @@ def extractweatherdata(w): data['sunset_t'] = fromtimestamp(data['sunset'], '%H:%M:%S') data['date'] = fromtimestamp(data['datetime'], '%Y-%m-%d') data['time'] = fromtimestamp(data['datetime'], '%H:%M:%S') + 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 -- 2.47.3