]> ToastFreeware Gitweb - chrisu/seepark.git/blobdiff - owm.py
remove debug rest
[chrisu/seepark.git] / owm.py
diff --git a/owm.py b/owm.py
index 878e3eba8c1dac4b37072189fcbd5f5b87b5ecea..27b9f08ed51658b3346703c742584e7bbcd4cf5f 100755 (executable)
--- a/owm.py
+++ b/owm.py
@@ -14,6 +14,7 @@ import os
 import csv
 import datetime
 import math
 import csv
 import datetime
 import math
+import sys
 
 baseurl = 'http://api.openweathermap.org/data/2.5/weather'
 debug = False
 
 baseurl = 'http://api.openweathermap.org/data/2.5/weather'
 debug = False
@@ -39,7 +40,7 @@ def fromtimestamp(timestamp, format):
 
 # https://stackoverflow.com/questions/7490660/converting-wind-direction-in-angles-to-text-words
 def degToCompass(num):
 
 # 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"]
         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"]
@@ -58,7 +59,6 @@ def extractweatherdata(w):
         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'],
-        winddegrees = w['wind']['deg'],
         cloudiness = w['clouds']['all'],
     )
 
         cloudiness = w['clouds']['all'],
     )
 
@@ -66,6 +66,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['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
 
     data['winddirection'] = degToCompass(data['winddegrees'])
     data['precipitation'] = w['rain']['3h'] if 'rain' in w else math.nan