1111OUTPUT_DATA_DIR = "scraper_data"
1212
1313
14- async def get_reverse_subject_map (
14+ def get_term_code (year : int , season : str ) -> str :
15+ """
16+ Converts a year and academic season into a term code used by SIS.
17+ """
18+ if season is None :
19+ return ""
20+ season_lower = season .lower ().strip ()
21+ if season_lower == "fall" :
22+ return f"{ year } 09"
23+ elif season_lower == "summer" :
24+ return f"{ year } 05"
25+ elif season_lower == "spring" :
26+ return f"{ year } 01"
27+ else :
28+ return ""
29+
30+
31+ async def get_subject_name_code_map (
1532 session : aiohttp .ClientSession ,
1633 start_year : int = 1998 ,
1734 end_year : int = datetime .now ().year ,
1835 seasons : list [str ] = None ,
1936) -> dict [str , str ]:
2037 """
2138 Fetches the list of subjects from the specified range of years and seasons, and
22- returns a "reverse" mapping of subject names to subject codes.
39+ returns a mapping of subject names to subject codes.
2340
2441 Defaults to a range from 1998 to the current year, and Spring, Summer, and Fall
2542 seasons. SIS data begins in Summer 1998.
@@ -95,7 +112,7 @@ async def process_class_details(
95112 course_data [course_code ] = {
96113 "course_name" : class_entry ["courseTitle" ],
97114 "course_detail" : {
98- "description" : description_data [ "description" ] ,
115+ "description" : description_data ,
99116 "corequisite" : corequisites_data ,
100117 "prerequisite" : prerequisites_data ,
101118 "crosslist" : crosslists_data ,
@@ -105,7 +122,6 @@ async def process_class_details(
105122 "min" : float ("inf" ),
106123 "max" : 0 ,
107124 },
108- "offered" : description_data ["when_offered" ],
109125 "sections" : [],
110126 },
111127 }
@@ -218,7 +234,6 @@ async def get_term_course_data(
218234
219235 Writes data as JSON after all subjects in the term have been processed.
220236 """
221- print (f"Fetching subject list for term: { term } " )
222237 async with aiohttp .ClientSession () as session :
223238 subjects = await get_term_subjects (session , term )
224239 print (f"Processing { len (subjects )} subjects for term: { term } " )
@@ -260,23 +275,6 @@ async def get_term_course_data(
260275 json .dump (all_course_data , f , indent = 4 , ensure_ascii = False )
261276
262277
263- def get_term_code (year : int , season : str ) -> str :
264- """
265- Converts a year and academic season into a term code used by SIS.
266- """
267- if season is None :
268- return ""
269- season_lower = season .lower ().strip ()
270- if season_lower == "fall" :
271- return f"{ year } 09"
272- elif season_lower == "summer" :
273- return f"{ year } 05"
274- elif season_lower == "spring" :
275- return f"{ year } 01"
276- else :
277- return ""
278-
279-
280278async def main (start_year : int , end_year : int , seasons : list [str ] = None ) -> bool :
281279 """
282280 Runs the SIS scraper for the specified range of years and seasons.
@@ -304,10 +302,15 @@ async def main(start_year: int, end_year: int, seasons: list[str] = None) -> boo
304302 semaphore = asyncio .Semaphore (50 )
305303 limit_per_host = 20
306304
307- # Create master subject name to subject code mapping
308- print ("Fetching subject name to subject code mapping..." )
305+ print (
306+ f"Starting SIS scraper with settings:\n "
307+ f"\t Years: { start_year } - { end_year } \n "
308+ f"\t Seasons: { ', ' .join (season .capitalize () for season in seasons )} "
309+ )
310+
311+ print ("Fetching subject name to code mapping..." )
309312 async with aiohttp .ClientSession () as session :
310- subject_name_code_map = await get_reverse_subject_map (
313+ subject_name_code_map = await get_subject_name_code_map (
311314 session , seasons = seasons
312315 )
313316
0 commit comments