Skip to content

Commit

Permalink
get quarter information from fireroad
Browse files Browse the repository at this point in the history
  • Loading branch information
dtemkin1 committed Dec 16, 2024
1 parent 6e95fb4 commit 05d7034
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
37 changes: 37 additions & 0 deletions scrapers/fireroad.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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", ""),
Expand Down
3 changes: 3 additions & 0 deletions src/lib/rawClass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

0 comments on commit 05d7034

Please sign in to comment.