Merge pull request #120 from emilyboda/feature/weather-fixes
Fix: 12/24 hour issue for forecasts. Improvement: Use local time, convert to UTC for fetching data from openweathermap.
This commit is contained in:
commit
6a9ec37390
@ -143,7 +143,7 @@ def to_hours(datetime_object, simple = False):
|
|||||||
converted_time = datetime_object.format('HH:mm')
|
converted_time = datetime_object.format('HH:mm')
|
||||||
else:
|
else:
|
||||||
if simple == True:
|
if simple == True:
|
||||||
converted_time = datetime_object.format('H a')
|
converted_time = datetime_object.format('h a')
|
||||||
else:
|
else:
|
||||||
converted_time = datetime_object.format('hh:mm')
|
converted_time = datetime_object.format('hh:mm')
|
||||||
return str(converted_time)
|
return str(converted_time)
|
||||||
@ -171,7 +171,7 @@ def generate_image():
|
|||||||
forecast = owm.three_hours_forecast(location)
|
forecast = owm.three_hours_forecast(location)
|
||||||
|
|
||||||
"""Round the hour to the nearest multiple of 3"""
|
"""Round the hour to the nearest multiple of 3"""
|
||||||
now = arrow.utcnow()
|
now = arrow.utcnow().to(get_tz())
|
||||||
if (now.hour % 3) != 0:
|
if (now.hour % 3) != 0:
|
||||||
hour_gap = 3 - (now.hour % 3)
|
hour_gap = 3 - (now.hour % 3)
|
||||||
else:
|
else:
|
||||||
@ -184,10 +184,10 @@ def generate_image():
|
|||||||
fc4 = now.replace(hours = + hour_gap + 9).floor('hour')
|
fc4 = now.replace(hours = + hour_gap + 9).floor('hour')
|
||||||
|
|
||||||
"""Prepare forecast objects for the specified timings"""
|
"""Prepare forecast objects for the specified timings"""
|
||||||
forecast_fc1 = forecast.get_weather_at(fc1.datetime)
|
forecast_fc1 = forecast.get_weather_at(fc1.datetime.astimezone(timezone('UTC')))
|
||||||
forecast_fc2 = forecast.get_weather_at(fc2.datetime)
|
forecast_fc2 = forecast.get_weather_at(fc2.datetime.astimezone(timezone('UTC')))
|
||||||
forecast_fc3 = forecast.get_weather_at(fc3.datetime)
|
forecast_fc3 = forecast.get_weather_at(fc3.datetime.astimezone(timezone('UTC')))
|
||||||
forecast_fc4 = forecast.get_weather_at(fc4.datetime)
|
forecast_fc4 = forecast.get_weather_at(fc4.datetime.astimezone(timezone('UTC')))
|
||||||
|
|
||||||
"""Get the current temperature and forcasts temperatures"""
|
"""Get the current temperature and forcasts temperatures"""
|
||||||
temperature_now = to_units(weather.get_temperature()['temp'])
|
temperature_now = to_units(weather.get_temperature()['temp'])
|
||||||
|
Loading…
Reference in New Issue
Block a user