diff --git a/modules/weather.py b/modules/weather.py index 8fd6dcb..5c6ff18 100644 --- a/modules/weather.py +++ b/modules/weather.py @@ -158,8 +158,8 @@ class WeatherSunMoonModule: import time infos = { - "sunrise": datetime.fromtimestamp(thisdayweather["sunriseTime"], tz=timezone.utc).strftime("%X"), - "sunset": datetime.fromtimestamp(thisdayweather["sunsetTime"], tz=timezone.utc).strftime("%X"), + "sunrise": WeatherAPI().read_timestamp(thisdayweather["sunriseTime"]).strftime("%X"), + "sunset": WeatherAPI().read_timestamp(thisdayweather["sunsetTime"]).strftime("%X"), "4": "", } @@ -219,7 +219,7 @@ class WeatherTemperatureModule: hours_weather = WeatherAPI().get_hourly() - line_chart.x_labels = [datetime.fromtimestamp(d["time"], tz=timezone.utc).strftime("%Hh") if datetime.fromtimestamp(d["time"]).hour % 2 == 0 else "" for d in hours_weather["data"][:self.limit_futur]] + line_chart.x_labels = [WeatherAPI().read_timestamp(d["time"]).strftime("%Hh") if datetime.fromtimestamp(d["time"]).hour % 2 == 0 else "" for d in hours_weather["data"][:self.limit_futur]] line_chart.add('Températures', [d["temperature"] for d in hours_weather["data"][:self.limit_futur]], show_dots=False) @@ -330,8 +330,8 @@ class WeatherAlertsModule: alert["title"], fill="white", anchor="lt", font=fnt_B ) - startTime = datetime.fromtimestamp(alert["time"], tz=timezone.utc) - endTime = datetime.fromtimestamp(alert["expires"], tz=timezone.utc) + startTime = WeatherAPI().read_timestamp(alert["time"]) + endTime = WeatherAPI().read_timestamp(alert["expires"]) # Show alert timing if under a day if startTime.hour != endTime.hour: draw.text( diff --git a/modules/weather_api.py b/modules/weather_api.py index 852fa3a..5aa2125 100644 --- a/modules/weather_api.py +++ b/modules/weather_api.py @@ -151,6 +151,12 @@ class DarkSkyAPI: def get_alerts(self, *args, **kwargs): return self.get_weather(*args, **kwargs)["alerts"] + def read_timestamp(self, timestamp, *args, **kwargs): + wth = self.get_weather(*args, **kwargs) + + tz = timezone(timedelta(hours=wth["offset"]), wth["timezone"]) + return datetime.fromtimestamp(timestamp, tz=tz) + WeatherAPI = DarkSkyAPI