Filter out events that have concluded
Some checks failed
docker-image / docker (push) Has been cancelled
Some checks failed
docker-image / docker (push) Has been cancelled
Sometimes, icalevents will return entries that have already ended. Filter them out.
This commit is contained in:
parent
ea943e89b0
commit
e583bb5691
1 changed files with 10 additions and 1 deletions
|
@ -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]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue