Files
zeus-filter/app/filter.py
2026-03-17 21:56:24 +01:00

31 lines
857 B
Python

from ics import Calendar
td_titles = ["TD"]
sh_titles = ["ANGLAIS", "Anglais", "ETHIQUE"]
def _filter_group(name: str, titles: list[str], group: str) -> bool | None:
for title in titles:
if title in name:
return "Examen" in name or group == "all" or group in name
return None
def _filter_event(name: str, td_group: str, sh_group: str) -> bool:
res = _filter_group(name, td_titles, td_group)
if res is not None:
return res
if _filter_group(name, sh_titles, sh_group) == False:
return False
return True
def filter_calendar(calendar: Calendar, td_group: str, sh_group: str) -> Calendar:
filtered_calendar = Calendar()
for event in calendar.events:
if _filter_event(event.name, td_group, sh_group):
filtered_calendar.events.add(event)
return filtered_calendar