From 11fc9815a110315c457c32b58108b5781f25d962 Mon Sep 17 00:00:00 2001 From: Paul Warren Date: Mon, 31 Jan 2022 11:00:27 +1100 Subject: [PATCH] UTC conversions --- bom_rrd2.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/bom_rrd2.py b/bom_rrd2.py index 2215d52..8039a08 100755 --- a/bom_rrd2.py +++ b/bom_rrd2.py @@ -8,6 +8,7 @@ import collections import rrdtool from weather_au import api +from dateutil import tz # Grab current temps from sensors around the house #outside = rrdtool.fetch("/media/media/mqtt/ESP_b5952/temp/c.rrd", "AVERAGE") @@ -72,9 +73,12 @@ if wdays_dict[0]['temp_min'] is None: weather['day_after'] = wdays_dict[3] else: night = 0 - weather['today'] = wdays_dict[1] - weather['tomorrow'] = wdays_dict[2] - weather['day_after'] = wdays_dict[3] + weather['today'] = wdays_dict[0] + weather['tomorrow'] = wdays_dict[1] + weather['day_after'] = wdays_dict[2] + +utc_zone = tz.tzutc() +local_zone = tz.tzlocal() if night: for day in weather.keys(): @@ -84,7 +88,10 @@ if night: new[day]['max'] = weather['tomorrow']['temp_min'] new[day]['icon'] = bom_icons[weather['today']['icon_descriptor']] else: - new[day]['day'] = datetime.datetime.strptime(weather[day]['date'], "%Y-%m-%dT%H:%M:%S%z").strftime("%A") + utc = datetime.datetime.strptime(weather[day]['date'], "%Y-%m-%dT%H:%M:%S%z") + utc.replace(tzinfo=utc_zone) + local_date = utc.astimezone(local_zone) + new[day]['day'] = local_date.strftime("%A") new[day]['icon'] = bom_icons[weather[day]['icon_descriptor']] new[day]['max'] = weather[day]['temp_max'] @@ -92,8 +99,10 @@ else: for day in weather.keys(): new[day] = {} - new[day]['day'] = datetime.datetime.strptime(weather[day]['date'], "%Y-%m-%dT%H:%M:%S%z").strftime("%A") - + utc = datetime.datetime.strptime(weather[day]['date'], "%Y-%m-%dT%H:%M:%S%z") + utc.replace(tzinfo=utc_zone) + local_date = utc.astimezone(local_zone) + new[day]['day'] = local_date.strftime("%A") new[day]['icon'] = bom_icons[weather[day]['icon_descriptor']] new[day]['max'] = weather[day]['temp_max']