Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adding case 3 for merging period and location for exceptions #295

Merged
merged 1 commit into from
Jun 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/configs/event/schedule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: '*',
}),
Expand Down
2 changes: 1 addition & 1 deletion src/lambda/syllabus-scraper/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
2 changes: 2 additions & 0 deletions src/lambda/syllabus-scraper/crawler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
37 changes: 20 additions & 17 deletions src/lambda/syllabus-scraper/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down