From deca95c7105427da6caeb04ebddcb986adbbd9d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Norh=C3=B8j?= Date: Tue, 15 Nov 2022 21:43:06 +0100 Subject: [PATCH] Fixed two bugs; timezones were not set (monkeypatch, real patch will be in lectio.py) and events were not updated if only location (room) was changed --- src/caldav.py | 3 ++- src/main.py | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/caldav.py b/src/caldav.py index 8aedba0..31a6695 100644 --- a/src/caldav.py +++ b/src/caldav.py @@ -42,7 +42,8 @@ def _generate_ical(start: datetime, end: datetime, summary: str, location: str, event_data.add('dtstart', start) event_data.add('dtend', end) event_data.add('summary', summary) - event_data.add('location', location) + if location: + event_data.add('location', location) event_data.add('description', desc) if color is not None: event_data.add('color', color) diff --git a/src/main.py b/src/main.py index d88ccd7..14bc3f7 100644 --- a/src/main.py +++ b/src/main.py @@ -9,6 +9,9 @@ import caldav as caldav import cooltables +# Dirty patch until timezone is implemented into lectio.py +from pytz import timezone +TIMEZONE = timezone('Europe/Copenhagen') class LectioCalDavSynchronizer: def __init__(self, lec_inst_id, lec_username, lec_password, cal_url, cal_username, cal_password) -> None: @@ -209,8 +212,9 @@ def event_module_equal(self, event: icalendar.Calendar, module: lectio.Module) - return (component.get("uid") == self._get_module_id(module) and component.get("summary") == self._get_module_title(module) and component.get("description") == self._get_module_desc(module) and - component.get("dtstart").dt.replace(tzinfo=None) == module.start_time and - component.get("dtend").dt.replace(tzinfo=None) == module.end_time and + component.get("dtstart").dt == module.start_time and + component.get("dtend").dt == module.end_time and + component.get("location") == self._get_module_location(module) and component.get("color") == self._get_module_color(module)) except AttributeError: return False @@ -236,6 +240,12 @@ def sync(self, start: datetime = None): end, False ) + + # Set astimezone to TIMEZONE for all modules + for module in sched: + module.start_time = module.start_time.astimezone(TIMEZONE) + module.end_time = module.end_time.astimezone(TIMEZONE) + self.log.debug(f"Got {len(sched)} modules from lectio") sched_lookup = [self._get_module_id(module) for module in sched]