# https://stackoverflow.com/questions/7490660/converting-wind-direction-in-angles-to-text-words
-def degToCompass(num):
+def deg_to_compass(num):
if num is None or num is math.nan:
return 'N/A'
val=int((num/22.5)+.5)
return arr[(val % 16)]
-def extractweatherdata(w):
+def extract_weather_data(w):
data = dict(
datetime = fromtimestamp(w['dt']),
sunrise = fromtimestamp(w['sys']['sunrise']),
)
data['winddegrees'] = w['wind']['deg'] if 'deg' in w['wind'] else math.nan
- data['winddirection'] = degToCompass(data['winddegrees'])
+ data['winddirection'] = deg_to_compass(data['winddegrees'])
data['precipitation'] = w['rain']['3h'] if 'rain' in w and w['rain'].get('3h') else math.nan
data['visibility'] = w.get('visibility', math.nan)
weather_data['datetime'].time(),
weather_data['sunrise'].time(),
weather_data['sunset'].time(),
- "{:.2f}".format(weather_data['temp']),
- "{:.2f} mm/h".format(weather_data['precipitation']),
- "{:.1f} km/h {}".format(weather_data['windspeed'], weather_data['winddirection']),
+ f"{weather_data['temp']:.2f}",
+ f"{weather_data['precipitation']:.2f} mm/h",
+ f"{weather_data['windspeed']:.1f} km/h {weather_data['winddirection']}",
weather_data['weather'],
- "{}".format(weather_data['cloudiness'])
+ f"{weather_data['cloudiness']}"
])
url, weather_json = openweathermap_json(apikey, cityid)
if debug:
pprint(weather_json)
- weather_data = extractweatherdata(weather_json)
+ weather_data = extract_weather_data(weather_json)
if debug:
pprint(weather_data)