From 7bac54599ac88aefb7c69fba7614b82da879f756 Mon Sep 17 00:00:00 2001 From: Stijn De Clercq Date: Sun, 28 Nov 2021 16:28:31 +0100 Subject: [PATCH] Update schedules & add some QOL & small fixes --- data/schedule.py | 32 ++++++++++++++++---- files/schedules/31.json | 65 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 89 insertions(+), 8 deletions(-) diff --git a/data/schedule.py b/data/schedule.py index 0844bcb..a1aa5d1 100644 --- a/data/schedule.py +++ b/data/schedule.py @@ -73,7 +73,7 @@ class Timeslot: return f"[{self.online_platform.value.get('name')}]({self.online_link})" def _get_location_str(self, offline_prefix="in", online_prefix="**online** @") -> str: - return f"{offline_prefix} {self.location}" if self.location is not None \ + return f"{offline_prefix} **{self.location}**" if self.location is not None \ else f"{online_prefix} **{self.get_link_str()}**" def get_special_fmt_str(self) -> Optional[str]: @@ -86,7 +86,7 @@ class Timeslot: # Something else is wrong return f"⚠️ {self.course} gaat vandaag door van **{timeFromInt(self.start_time)}** tot " \ - f"**{timeFromInt(self.end_time)}** **{self._get_location_str(online_prefix='op')}**" + f"**{timeFromInt(self.end_time)}** {self._get_location_str(online_prefix='op')}" @staticmethod def from_slot_dict(slot_dict: Dict, course_dict: Dict, current_week: int): @@ -95,14 +95,15 @@ class Timeslot: """ special = False - if "weeks" in slot_dict and str(current_week) in slot_dict["weeks"]: + week = find_week(str(current_week), slot_dict) + if week is not None: # 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)]) + slot_dict.update(week) # Only happens online, not on-campus - online_only = slot_dict["weeks"][str(current_week)].get("online_only", False) + online_only = week.get("online_only", False) if online_only: slot_dict.pop("location") @@ -406,7 +407,9 @@ class ScheduleEmbed(LesEmbed): if not has_link: return "" - return "\n".join(list(f"{entry.course}: **{entry.get_link_str()}**" for entry in has_link)) + # Store in a set first to remove duplicates + entries = list(set(f"{entry.course}: **{entry.get_link_str()}**" for entry in has_link)) + return "\n".join(list(sorted(entries))) def find_minor(client: commands.Bot, userid: int) -> Tuple[Optional[int]]: @@ -420,3 +423,20 @@ def find_minor(client: commands.Bot, userid: int) -> Tuple[Optional[int]]: return role.id, return None, + + +def find_week(week: str, slot_dict: Dict) -> Optional[Dict]: + """Find a week in a slot_dict""" + if "weeks" not in slot_dict: + return None + + # Split all entries based on commas + # to allow grouping weeks together + for w in slot_dict["weeks"]: + weeks = w.split(",") + + if week in weeks: + return slot_dict["weeks"][w] + + # Week was not in any of the lists + return None diff --git a/files/schedules/31.json b/files/schedules/31.json index 9dfa778..772faa2 100644 --- a/files/schedules/31.json +++ b/files/schedules/31.json @@ -26,8 +26,12 @@ "weeks": { "6": { "canceled": true + }, + "10,11,12": { + "online_only": true } }, + "online": "zoom", "location": { "campus": "Sterre", "building": "S9", @@ -50,8 +54,12 @@ }, "6": { "canceled": true + }, + "10,11,12": { + "online_only": true } }, + "online": "zoom", "location": { "campus": "Sterre", "building": "S9", @@ -67,8 +75,12 @@ "weeks": { "6": { "canceled": true + }, + "10,11,12": { + "online_only": true } }, + "online": "zoom", "location": { "campus": "Sterre", "building": "S9", @@ -85,7 +97,8 @@ { "course": "Parallelle Computersystemen", "online_links": { - "zoom": "https://ufora.ugent.be/d2l/ext/rp/449671/lti/framedlaunch/556e197e-e87b-4c27-be5d-53adc7a41826" + "zoom": "https://ufora.ugent.be/d2l/ext/rp/449671/lti/framedlaunch/556e197e-e87b-4c27-be5d-53adc7a41826", + "opencast": "https://elosp.ugent.be/opencastplanner/live/GCMobile-ocrec79" }, "slots": [ { @@ -94,6 +107,7 @@ "canceled": true } }, + "online": "opencast", "location": { "campus": "Ardoyen", "building": "iGent 126", @@ -106,6 +120,7 @@ } }, { + "online": "opencast", "location": { "campus": "Ardoyen", "building": "iGent 126", @@ -152,8 +167,12 @@ }, "6": { "canceled": true + }, + "10,11,12": { + "online_only": true } }, + "online": "zoom", "location": { "campus": "Ardoyen", "building": "iGent 125", @@ -169,13 +188,20 @@ }, { "course": "Wiskundige Modellering", + "online_links": { + "zoom": "https://ufora.ugent.be/d2l/ext/rp/446530/lti/framedlaunch/556e197e-e87b-4c27-be5d-53adc7a41826" + }, "slots": [ { "weeks": { "6": { "canceled": true + }, + "10,11,12": { + "online_only": true } }, + "online": "zoom", "location": { "campus": "Sterre", "building": "S9", @@ -191,8 +217,12 @@ "weeks": { "6": { "canceled": true + }, + "10,11,12": { + "online_only": true } }, + "online": "zoom", "location": { "campus": "Sterre", "building": "S8", @@ -208,8 +238,12 @@ "weeks": { "6": { "canceled": true + }, + "10,11,12": { + "online_only": true } }, + "online": "zoom", "location": { "campus": "Sterre", "building": "S8", @@ -242,8 +276,12 @@ "weeks": { "6": { "canceled": true + }, + "10,11,12": { + "online_only": true } }, + "online": "zoom", "location": { "campus": "Sterre", "building": "S9", @@ -259,8 +297,12 @@ "weeks": { "6": { "canceled": true + }, + "10,11,12": { + "online_only": true } }, + "online": "zoom", "location": { "campus": "Sterre", "building": "S9", @@ -276,8 +318,12 @@ "weeks": { "6": { "canceled": true + }, + "10,11,12": { + "online_only": true } }, + "online": "zoom", "location": { "campus": "Sterre", "building": "S9", @@ -301,8 +347,12 @@ "weeks": { "6": { "canceled": true + }, + "10,11,12": { + "online_only": true } }, + "online": "zoom", "location": { "campus": "Sterre", "building": "S8", @@ -318,8 +368,12 @@ "weeks": { "6": { "canceled": true + }, + "10,11,12": { + "online_only": true } }, + "online": "zoom", "location": { "campus": "Sterre", "building": "S9", @@ -338,8 +392,12 @@ }, "6": { "canceled": true + }, + "10,11,12": { + "online_only": true } }, + "online": "zoom", "location": { "campus": "Sterre", "building": "S9", @@ -356,7 +414,8 @@ { "course": "Besturingssystemen", "online_links": { - "zoom": "https://ufora.ugent.be/d2l/ext/rp/442814/lti/framedlaunch/556e197e-e87b-4c27-be5d-53adc7a41826" + "zoom": "https://ufora.ugent.be/d2l/ext/rp/442814/lti/framedlaunch/556e197e-e87b-4c27-be5d-53adc7a41826", + "opencast": "https://elosp.ugent.be/opencastplanner/live/GCMobile-ocrec79" }, "slots": [ { @@ -369,6 +428,7 @@ } } }, + "online": "opencast", "location": { "campus": "Ardoyen", "building": "iGent 126", @@ -381,6 +441,7 @@ } }, { + "online": "opencast", "location": { "campus": "Ardoyen", "building": "iGent 126",