From e583bb5691539db40f91cef8b7440a2327ad46ae Mon Sep 17 00:00:00 2001 From: Stefan Bethke Date: Tue, 17 Jun 2025 19:01:50 +0200 Subject: [PATCH] Filter out events that have concluded Sometimes, icalevents will return entries that have already ended. Filter them out. --- buba/animations/icalevents.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/buba/animations/icalevents.py b/buba/animations/icalevents.py index 148951c..4a74e56 100644 --- a/buba/animations/icalevents.py +++ b/buba/animations/icalevents.py @@ -18,8 +18,17 @@ class IcalEvents(BubaAnimation): return f"<{type(self).__name__}, {self.url}>" def update(self): + """ + Fetch all events from now to the end of the range. + Filter out events that have ended. Apparently, the icalecvents list can contain entries + that are slightly in the past (by an hours or two). Only use entries that have not reached + their end date/time yet. + :return: + """ tz = timezone(os.getenv("TZ", "Europe/Berlin")) - events = icalevents.icalevents.events(self.url, tzinfo=tz, sort=True, end=datetime.now(tz) + self.range) + now = datetime.now(tz) + events = icalevents.icalevents.events(self.url, tzinfo=tz, sort=True, end=now + self.range) for event in events: event.start = event.start.astimezone(tz) + events = filter(lambda e: e.end > now, events) self.rows = [[e.summary, self.countdown(e.start)] for e in events]