From 9a382669e5b161e21c16507a2a2a2454235b6b82 Mon Sep 17 00:00:00 2001 From: Jason Park Date: Mon, 12 Jun 2023 22:20:41 +0900 Subject: [PATCH] feat: adding case 3 for merging period and location for exceptions --- lib/configs/event/schedule.ts | 2 +- src/lambda/syllabus-scraper/const.py | 2 +- src/lambda/syllabus-scraper/crawler.py | 2 ++ src/lambda/syllabus-scraper/utils.py | 37 ++++++++++++++------------ 4 files changed, 24 insertions(+), 19 deletions(-) diff --git a/lib/configs/event/schedule.ts b/lib/configs/event/schedule.ts index 58ac75882..d71b76f2d 100644 --- a/lib/configs/event/schedule.ts +++ b/lib/configs/event/schedule.ts @@ -4,7 +4,7 @@ export const syllabusSchedule: { [name: string]: events.Schedule } = { 'regular': events.Schedule.cron({ minute: '0', hour: '16', - day: '1,2', + day: '1,12', month: '*', year: '*', }), diff --git a/src/lambda/syllabus-scraper/const.py b/src/lambda/syllabus-scraper/const.py index 3afbdf6d6..d4dbd31be 100644 --- a/src/lambda/syllabus-scraper/const.py +++ b/src/lambda/syllabus-scraper/const.py @@ -237,6 +237,6 @@ cron_schedule = ["01-01", "02-01", "02-14", "02-24", "03-01", "03-04", "03-07", "03-10", "03-16", "03-18", "03-21", "03-24", "03-27", "04-01", "04-03", "04-05", "04-08", "04-16", "04-20", "04-24", "04-26", "04-28", - "05-01", "05-09", "05-12", "05-14", "05-16", "06-01", "06-02", "07-01", "07-19", "07-21", "07-23", "08-01", + "05-01", "05-09", "05-12", "05-14", "05-16", "06-01", "06-12", "07-01", "07-19", "07-21", "07-23", "08-01", "08-19", "08-21", "08-23", "09-01", "09-04", "09-07", "09-10", "09-13", "09-15", "09-17", "09-20", "09-23", "09-25", "09-28", "09-30", "10-01", "10-03", "10-05", "10-08", "11-01", "12-01"] diff --git a/src/lambda/syllabus-scraper/crawler.py b/src/lambda/syllabus-scraper/crawler.py index 78a3e8def..94f440467 100644 --- a/src/lambda/syllabus-scraper/crawler.py +++ b/src/lambda/syllabus-scraper/crawler.py @@ -85,6 +85,8 @@ def scrape_course(self, course_id): "n": 'array', # eval "o": 'string', # code "p": 'string', # subtitle + "q": 'string', #category + "r": 'string', #modality } """ req_en = requests.Request(url=build_url( diff --git a/src/lambda/syllabus-scraper/utils.py b/src/lambda/syllabus-scraper/utils.py index 639b0222d..e58d3a6ac 100644 --- a/src/lambda/syllabus-scraper/utils.py +++ b/src/lambda/syllabus-scraper/utils.py @@ -149,24 +149,27 @@ def merge_period_location(periods, locations): for p in periods: p["l"] = locations[0] return periods - # TODO find other cases - # Case 2: multiple periods and multiple locations string divided with a '/' - elif len(periods) == len(locations): - for i in range(len(periods)): - locs = locations[i].split('/') - temp_period = periods[i] - for loc in locs: - temp_period_copy = temp_period.copy() - temp_period_copy["l"] = loc.strip() - occurrences.append(temp_period_copy) - return occurrences - - # Case 3: More no. of periods than no. of locations - else: - zipped = list(itertools.zip_longest(periods, locations)) - for (p, loc) in zipped: + # Case 2: More no. of periods than no. of locations + zipped = list(itertools.zip_longest(periods, locations)) + for (p, loc) in zipped: + if p is None: + logging.error(f"Unexpected None in periods. loc={loc}") + continue + + if loc is not None: p["l"] = loc - occurrences.append(p) + else: + logging.warning( + f"Missing location for period {p}. Assigning default value.") + p["l"] = "undecided" + + occurrences.append(p) + + # Case 3: Logging error for unusual scenarios + if not occurrences: + logging.error( + f"merge_period_location resulted in no occurrences for input periods={periods}, locations={locations}") + return occurrences