Skip to content

Commit

Permalink
fix: get course name for quiz and deadlines properly
Browse files Browse the repository at this point in the history
  • Loading branch information
dantetemplar committed Feb 3, 2025
1 parent 7fe91b6 commit 5593d2c
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/modules/ics/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,15 +227,19 @@ async def get_moodle_ics(user: ViewUser) -> bytes:
Get schedule in ICS format for the user from user link to moodle calendar;
"""

def get_course_name(event: icalendar.Event) -> str:
categories = (event["categories"]).to_ical().decode(encoding="utf-8")
course_name = html.unescape(categories.split("]")[1].replace(r"\;", ";"))
return course_name

def make_deadline(event: icalendar.Event) -> icalendar.Event:
new = icalendar.Event()
end: datetime.datetime = event["dtend"].dt
end = end.astimezone(pytz.timezone("Europe/Moscow"))
new["dtstart"] = icalendar.vDate(end.date())
new["uid"] = event["uid"]
new["dtstamp"] = event["dtstamp"]
categories = (event["categories"]).to_ical().decode(encoding="utf-8")
course_name = html.unescape(categories.split("]")[1].replace(r"\;", ";"))
course_name = get_course_name(event)
new["summary"] = event["summary"] + f" - {course_name}"

new["description"] = f"Course: {course_name}\nDue to: {end.timetz().isoformat()}"
Expand All @@ -259,8 +263,7 @@ def create_quiz(quiz_name: str, opens: icalendar.Event, closes: icalendar.Event

new["uid"] = opens["uid"]
new["dtstamp"] = opens["dtstamp"]
categories = (opens["categories"]).to_ical().decode(encoding="utf-8")
course_name = categories.split("]")[1]
course_name = get_course_name(opens)
new["summary"] = quiz_name + f" - {course_name}"

new["description"] = "\n".join(
Expand Down

0 comments on commit 5593d2c

Please sign in to comment.