From 2a88e75c9f260b938bbdefa999e3ebc944bfbc13 Mon Sep 17 00:00:00 2001 From: Matthew Hague <Matthew.Hague@rhul.ac.uk> Date: Mon, 30 Sep 2024 15:05:43 +0100 Subject: [PATCH] add(timetable): streamline interface for practical groups --- timetabling/get-practical-groups.py | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/timetabling/get-practical-groups.py b/timetabling/get-practical-groups.py index baf846c..2ae4207 100644 --- a/timetabling/get-practical-groups.py +++ b/timetabling/get-practical-groups.py @@ -14,8 +14,6 @@ # USERNAME/PASSWORD -- to log into webtimetables. If you get your # password wrong it crashes.. # -# MODULE_CODE -- your module code -# # DEPARTMENTS -- all departments to look in for your students # # The script takes one command line argument: the name of a CSV file @@ -38,11 +36,12 @@ from getpass import getpass from typing import Dict, Optional -if len(sys.argv) < 2: - print("Usage: python get-practical-groups.py <student-list.csv>") +if len(sys.argv) < 3: + print("Usage: python get-practical-groups.py <mod_code> <student-list.csv>") exit(-1) -student_list_csv = sys.argv[1] +mod_code = sys.argv[1] +student_list_csv = sys.argv[2] ACADEMIC_YEAR = "2425" TT_HOST = "webtimetables.royalholloway.ac.uk" @@ -54,15 +53,8 @@ TT_DEFAULT_URL = f"{BASE_URL}/default.aspx" USER_AGENT \ = "Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/117.0" -MODULE_CODE = "CS1822" DEPARTMENTS = ["Computer Science", "Media Arts"] -GROUP_TIMES = { - "Group 01": "Monday 13:00", - "Group 02": "Monday 16:00", - "Group 03": "Friday 13:00" -} - GROUP_RE = re.compile(r".*(Group \d+).*", flags=re.DOTALL) GROUP_GRP = 1 @@ -227,7 +219,7 @@ def parse_timetable(students : Dict[str, Student], timetable : str): if current_student is None: continue for practical in tt_row.find_all("td", { "class": "Practical" }): - if MODULE_CODE in practical.text: + if mod_code in practical.text: if m := GROUP_RE.match(practical.text): current_student.group = m[GROUP_GRP] -- GitLab