Custom Calendar
This commit is contained in:
@ -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.
|
||||
|
||||
Reference in New Issue
Block a user