Skip to content

Commit

Permalink
Fixed two bugs; timezones were not set (monkeypatch, real patch will …
Browse files Browse the repository at this point in the history
…be in lectio.py) and events were not updated if only location (room) was changed
  • Loading branch information
dnorhoj committed Nov 15, 2022
1 parent 8fe2c5d commit deca95c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/caldav.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 12 additions & 2 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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]
Expand Down

0 comments on commit deca95c

Please sign in to comment.