Custom Calendar

This commit is contained in:
2024-09-29 19:21:20 +02:00
parent b0bda20baa
commit 85c129b602
14 changed files with 159 additions and 34 deletions

View File

@ -6,6 +6,7 @@ import datetime
import recurring_ical_events
from fetchMENSA import getMeals
import pytz
from init import *
shortnames = ["mon", "tue", "wed", "thu", "fri", "sat"]
longnames = ["Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag"]
@ -78,11 +79,32 @@ async def getWeek(weekstart: datetime, file: str, showsat: bool):
"weekday": estart.weekday(),
"day": estart.day,
"teacher": teacher,
"id": event["UID"]
}
eventl += [eventdict]
return eventl, await MensaDayList(start_date, showsat), prevw, nextw, mon
async def createCustomCalendar (uid: int):
hiddenEvents = HiddenVL.query.filter_by(uid=uid).all()
hiddenEventIDs = {event.eventid for event in hiddenEvents}
kurs = User.query.filter_by(id=uid).first().kurs
raplaFile = Rapla.query.filter_by(name=kurs).first().file
with open(f"calendars/{raplaFile}") as f:
calendar = icalendar.Calendar.from_ical(f.read())
newCalendar = icalendar.Calendar()
for component in calendar.walk():
if component.name != "VEVENT":
if component.name != "VCALENDAR":
newCalendar.add_component(component)
elif component["UID"] not in hiddenEventIDs:
newCalendar.add_component(component)
byteText = newCalendar.to_ical()
with open(f"calendars/{uid}.ical", 'w+') as f:
f.write(byteText.decode("utf-8"))
return uid
async def MensaDayList(weekstart: datetime, showsat: bool):
"""
Gibt die Essen einer Woche zurück.