From b3854324d42d71422dae28c10bfc6193ae0c6ee9 Mon Sep 17 00:00:00 2001 From: Stijn De Clercq Date: Sun, 8 Aug 2021 15:18:45 +0200 Subject: [PATCH] Special weeks --- data/schedule.py | 27 +++++++++++++++------------ files/schedules/31.json | 14 +++++++------- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/data/schedule.py b/data/schedule.py index b661ff3..e494855 100644 --- a/data/schedule.py +++ b/data/schedule.py @@ -57,8 +57,18 @@ class Timeslot: """ Construct a Timeslot from a dict of data """ + special = False + if "weeks" in slot_dict and str(current_week) in slot_dict["weeks"]: - return Timeslot.special_from_dict(slot_dict, course_dict, str(current_week)) + # If at least one thing was changed, this slot requires extra attention + special = True + # Overwrite the normal data with the customized entries + slot_dict.update(slot_dict["weeks"][str(current_week)]) + + # Only happens online, not on-campus + online_only = slot_dict["weeks"][str(current_week)].get("online_only", False) + if online_only: + slot_dict.pop("location") course = Course(course_dict["course"]) start_time = slot_dict["time"]["start"] @@ -71,16 +81,9 @@ class Timeslot: online_platform: Platform = get_platform(slot_dict.get("online", None)) online_link = course_dict["online_links"][Platform.value["rep"]] if online_platform is not None else None - return Timeslot(course=course, start_time=start_time, end_time=end_time, canceled=False, is_special=False, - location=location, online_platform=online_platform, online_link=online_link) + return Timeslot(course=course, start_time=start_time, end_time=end_time, canceled="canceled" in slot_dict, + is_special=special, location=location, online_platform=online_platform, online_link=online_link) - @staticmethod - def special_from_dict(slot_dict: Dict, course_dict: Dict, current_week: str): - """ - Create a SPECIAL Timeslot from a dict and data - """ - course = Course(course_dict["course"]) - # TODO @dataclass class Schedule: @@ -145,8 +148,8 @@ class Schedule: """ Load the schedule from the JSON file """ - semester = get_platform("semester") - year = get_platform("year") + semester = get("semester") + year = get("year") with open(f"files/schedules/{year}{semester}.json", "r") as fp: return json.load(fp) diff --git a/files/schedules/31.json b/files/schedules/31.json index 605459c..a11e805 100644 --- a/files/schedules/31.json +++ b/files/schedules/31.json @@ -36,7 +36,7 @@ } }, { - "online": "ZOOM", + "online": "zoom", "time": { "day": "vrijdag", "start": 1300, @@ -52,7 +52,7 @@ }, "slots": [ { - "online": "ZOOM", + "online": "zoom", "time": { "day": "dinsdag", "start": 1130, @@ -60,7 +60,7 @@ } }, { - "online": "ZOOM", + "online": "zoom", "time": { "day": "woensdag", "start": 1500, @@ -68,7 +68,7 @@ } }, { - "online": "ZOOM", + "online": "zoom", "time": { "day": "donderdag", "start": 830, @@ -85,7 +85,7 @@ }, "slots": [ { - "online": "MS Teams", + "online": "msteams", "time": { "day": "dinsdag", "start": 1430, @@ -93,7 +93,7 @@ } }, { - "online": "MS Teams", + "online": "msteams", "time": { "day": "vrijdag", "start": 830, @@ -126,7 +126,7 @@ } }, { - "online": "ZOOM", + "online": "zoom", "time": { "day": "donderdag", "start": 1000,