From 05d7034303ccb7bcfa566319d42c66c65b33285e Mon Sep 17 00:00:00 2001 From: Diego Temkin <65834932+dtemkin1@users.noreply.github.com> Date: Sat, 14 Dec 2024 20:29:16 -0500 Subject: [PATCH] get quarter information from fireroad --- scrapers/fireroad.py | 37 +++++++++++++++++++++++++++++++++++++ src/lib/rawClass.ts | 3 +++ 2 files changed, 40 insertions(+) diff --git a/scrapers/fireroad.py b/scrapers/fireroad.py index ef9140c0..eb4aa142 100644 --- a/scrapers/fireroad.py +++ b/scrapers/fireroad.py @@ -12,6 +12,7 @@ * parse_timeslot(day, slot, pm) * parse_section(section) * parse_schedule(course) +* parse_quarter_info(course) * parse_attributes(course) * parse_terms(course) * parse_prereqs(course) @@ -137,6 +138,39 @@ def parse_schedule(schedule): return result +def parse_quarter_info(course): + """ + Parses quarter info from the course. + If quarter information key is present, returns either start date, end date, or both. + + Can start with either 0, 1, or 2. + e.g. "0,apr 14" meaning subject ends on Apr 14, + or "1,4/4" meaning subject begins on 4/4, + or "2,4/9 to 5/9" meaning subject meets from 4/9 to 5/9. + + NOTE: dates can appear as either "4/4" or "apr 4". + + Args: + * course (dict[str, Union[bool, float, int, list[str], str]]): The course object. + + Returns: + * dict[str, dict[str, str]]: The parsed quarter info. + """ + + quarter_info = course.get("quarter_information", "") + if quarter_info: + print(course.get("subject_id"), quarter_info) + quarter_info = quarter_info.split(",") + if quarter_info[0] == "0": + return {"quarterInfo": {"end": quarter_info[1]}} + elif quarter_info[0] == "1": + return {"quarterInfo": {"start": quarter_info[1]}} + elif quarter_info[0] == "2" and "to" in quarter_info[1]: + dates = quarter_info[1].split(" to ") + return {"quarterInfo": {"start": dates[0], "end": dates[1]}} + return {} + + def parse_attributes(course): """ Parses attributes of the course. @@ -293,6 +327,9 @@ def get_course_data(courses, course, term): assert raw_class["labUnits"] == 0 assert raw_class["preparationUnits"] == 0 + # Get quarter info if available + raw_class.update(parse_quarter_info(course)) + raw_class.update( { "description": course.get("description", ""), diff --git a/src/lib/rawClass.ts b/src/lib/rawClass.ts index 43363cb8..456d25e0 100644 --- a/src/lib/rawClass.ts +++ b/src/lib/rawClass.ts @@ -111,4 +111,7 @@ export type RawClass = { hours: number; /** Class size from evals */ size: number; + + /** Record with start and end time information */ + quarter_information: Record<"start" | "end", string> | undefined; };