import csv
import datetime
import math
+import sys
baseurl = 'http://api.openweathermap.org/data/2.5/weather'
debug = False
# 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"]
weather = w['weather'][0]['description'],
sky = w['weather'][0]['main'],
windspeed = w['wind']['speed'],
- winddegrees = w['wind']['deg'],
cloudiness = w['clouds']['all'],
)
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
config.read(configfile)
apikey = config.get('openweathermap', 'apikey')
cityid = config.get('openweathermap', 'cityid')
+ csvfile = config.get("openweathermap", 'csvfilename')
weather_raw = getweather(apikey, cityid)
if debug:
# write to db
# write to csv
- write_csv(config.get("openweathermap", 'csvfilename'), weather)
+ write_csv(os.path.expanduser(csvfile), weather)
if __name__ == '__main__':