Skip to content

Commit 626d3e0

Browse files
committed
do parsing in python
1 parent 8618f16 commit 626d3e0

File tree

4 files changed

+51
-5
lines changed

4 files changed

+51
-5
lines changed

scrapers/fireroad.py

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,26 @@ def parse_schedule(schedule):
138138
return result
139139

140140

141+
def decode_quarter_date(date: str):
142+
"""
143+
Decodes a quarter date into a month and day.
144+
145+
Args:
146+
* date (str): The date in the format "4/4" or "apr 4".
147+
148+
Returns:
149+
* tuple[int, int]: The month and day.
150+
"""
151+
if "/" in date:
152+
month, day = date.split("/")
153+
return int(month), int(day)
154+
elif " " in date:
155+
month, day = utils.MONTHS[(date.split())[0]], (date.split())[1]
156+
return int(month), int(day)
157+
158+
return None
159+
160+
141161
def parse_quarter_info(course):
142162
"""
143163
Parses quarter info from the course.
@@ -160,13 +180,24 @@ def parse_quarter_info(course):
160180
quarter_info = course.get("quarter_information", "")
161181
if quarter_info:
162182
quarter_info = quarter_info.split(",")
183+
163184
if quarter_info[0] == "0":
164-
return {"quarterInfo": {"end": quarter_info[1]}}
185+
end_date = decode_quarter_date(quarter_info[1])
186+
if end_date:
187+
return {"quarterInfo": {"end": end_date}}
188+
165189
elif quarter_info[0] == "1":
166-
return {"quarterInfo": {"start": quarter_info[1]}}
190+
start_date = decode_quarter_date(quarter_info[1])
191+
if start_date:
192+
return {"quarterInfo": {"start": start_date}}
193+
167194
elif quarter_info[0] == "2" and "to" in quarter_info[1]:
168195
dates = quarter_info[1].split(" to ")
169-
return {"quarterInfo": {"start": dates[0], "end": dates[1]}}
196+
start_date = decode_quarter_date(dates[0])
197+
end_date = decode_quarter_date(dates[1])
198+
if start_date and end_date:
199+
return {"quarterInfo": {"start": start_date, "end": end_date}}
200+
170201
return {}
171202

172203

scrapers/utils.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,21 @@
8787
"10.30": 29,
8888
}
8989

90+
MONTHS = {
91+
"jan": 1,
92+
"feb": 2,
93+
"mar": 3,
94+
"apr": 4,
95+
"may": 5,
96+
"jun": 6,
97+
"jul": 7,
98+
"aug": 8,
99+
"sep": 9,
100+
"oct": 10,
101+
"nov": 11,
102+
"dec": 12,
103+
}
104+
90105

91106
class Term(Enum):
92107
FA = "fall"

src/lib/gapi.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ function toICalEvents(activity: Activity, term: Term): Array<ICalEventData> {
8888
const endDate = term.endDateFor(slot.startSlot);
8989
const exDates = term.exDatesFor(slot.startSlot);
9090
const rDate = term.rDateFor(slot.startSlot);
91-
console.log(event.name, startDate);
91+
9292
return {
9393
summary: event.name,
9494
location: event.room,

src/lib/rawClass.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,5 +113,5 @@ export type RawClass = {
113113
size: number;
114114

115115
/** Record with start and end time information */
116-
quarterInfo: Partial<Record<"start" | "end", string>> | undefined;
116+
quarterInfo: Partial<Record<"start" | "end", [number, number]>> | undefined;
117117
};

0 commit comments

Comments
 (0)