Skip to content

Commit

Permalink
Ad hoc fix for math department classes.
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrc52 committed Aug 30, 2024
1 parent 0857b56 commit e23a7c6
Show file tree
Hide file tree
Showing 2 changed files with 198 additions and 1 deletion.
84 changes: 84 additions & 0 deletions scrapers/math_dept.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
"""
This isn't run automatically, but it is a temporary workaround to the math classes being wrong.
Used to generate the math overrides in package.py
"""

from bs4 import BeautifulSoup
from fireroad import parse_timeslot, parse_section
from pprint import pprint
import requests

response = requests.get("https://math.mit.edu/academics/classes.html")
soup = BeautifulSoup(response.text, features="lxml")
course_list = soup.find("ul", {"class": "course-list"})
rows = course_list.findAll("li", recursive=False)

def parse_when(when):
# special casing is good enough (otherwise this could be a for loop)
if when[1].isdigit():
r = when[:1], when[1:]
elif when[2].isdigit():
r = when[:2], when[2:]
elif when[3].isdigit():
r = when[:3], when[3:]
else:
assert False
days, times = r
# fireroad.py wants dots instead of colons
times = times.replace(":", ".")
return days, times

assert parse_when("F10:30-12") == ("F", "10.30-12")
assert parse_when("MW1") == ("MW", "1")
assert parse_when("MWF11") == ("MWF", "11")

def parse_many_timeslots(days, times):
# parse timeslot wants only one letter
return [parse_timeslot(day, times) for day in days]


def make_raw_sections(days, times, room):
return f"{room}/{days}/0/{times}"

def make_section_override(timeslots, room):
return [[timeslots, room]]
# lol this is wrong
#return [[section, room] for section in timeslots]

overrides = {}

for row in rows:
subject = row.find("div", {"class": "subject"}).text
# remove "J" from joint subjects
subject = subject.replace("J", "")

# special case specific to math, if a slash it means that there
# is an additional graduate subject ending in 1
if " / " in subject:
subject = subject.split(" / ")[0]
subjects = [subject, f"{subject}1"]
else:
subjects = [subject]
assert ["/" not in subject for subject in subjects]

where_when = row.find("div", {"class": "where-when"})
when, where = where_when.findAll("div", recursive=False)
where = where.text
when = when.text
if ";" in when:
# Don't want to handle special case - calculus, already right
continue
days, times = parse_when(when)
timeslots = parse_many_timeslots(days, times)
for subject in subjects:
lecture_raw_sections = make_raw_sections(days, times, where)
lecture_sections = make_section_override(timeslots, where)
overrides[subject] = {
"lectureRawSections": lecture_raw_sections,
"lectureSections": lecture_sections
}
# Make sure the raw thing that I do not comprehend is actually correct
assert parse_section(lecture_raw_sections) == lecture_sections[0]

pprint(overrides)
115 changes: 114 additions & 1 deletion scrapers/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,120 @@
"lectureSections": [
[[[92, 6]], '54-209']
]
}
},

# Corrected schedules for the math department.
# Generated by math_dept.py
'18.03': {'lectureRawSections': '26-100/MWF/0/1',
'lectureSections': [[[[10, 2], [70, 2], [130, 2]], '26-100']]},
'18.04': {'lectureRawSections': '2-131/MW/0/11-12.30',
'lectureSections': [[[[6, 3], [66, 3]], '2-131']]},
'18.06': {'lectureRawSections': '26-100/MWF/0/11',
'lectureSections': [[[[6, 2], [66, 2], [126, 2]], '26-100']]},
'18.062': {'lectureRawSections': '26-100/TR/0/2.30-4',
'lectureSections': [[[[43, 3], [103, 3]], '26-100']]},
'18.085': {'lectureRawSections': '2-190/TR/0/11-12.30',
'lectureSections': [[[[36, 3], [96, 3]], '2-190']]},
'18.100A': {'lectureRawSections': '1-190/TR/0/1-2.30',
'lectureSections': [[[[40, 3], [100, 3]], '1-190']]},
'18.100B': {'lectureRawSections': '4-163/TR/0/1-2.30',
'lectureSections': [[[[40, 3], [100, 3]], '4-163']]},
'18.100Q': {'lectureRawSections': '2-151/TR/0/1-2.30',
'lectureSections': [[[[40, 3], [100, 3]], '2-151']]},
'18.101': {'lectureRawSections': '2-139/TR/0/9.30-11',
'lectureSections': [[[[33, 3], [93, 3]], '2-139']]},
'18.104': {'lectureRawSections': '2-151/MW/0/11-12.30',
'lectureSections': [[[[6, 3], [66, 3]], '2-151']]},
'18.112': {'lectureRawSections': '45-102/MW/0/9.30-11',
'lectureSections': [[[[3, 3], [63, 3]], '45-102']]},
'18.137': {'lectureRawSections': '2-142/TR/0/9.30-11',
'lectureSections': [[[[33, 3], [93, 3]], '2-142']]},
'18.152': {'lectureRawSections': '56-154/MW/0/11-12.30',
'lectureSections': [[[[6, 3], [66, 3]], '56-154']]},
'18.155': {'lectureRawSections': '2-131/MW/0/1-2.30',
'lectureSections': [[[[10, 3], [70, 3]], '2-131']]},
'18.204': {'lectureRawSections': '2-151/MW/0/9.30-11',
'lectureSections': [[[[3, 3], [63, 3]], '2-151']]},
'18.211': {'lectureRawSections': '32-124/TR/0/11-12.30',
'lectureSections': [[[[36, 3], [96, 3]], '32-124']]},
'18.217': {'lectureRawSections': '2-190/MWF/0/1',
'lectureSections': [[[[10, 2], [70, 2], [130, 2]], '2-190']]},
'18.226': {'lectureRawSections': '45-102/MW/0/2.30-4',
'lectureSections': [[[[13, 3], [73, 3]], '45-102']]},
'18.338': {'lectureRawSections': '2-147/MW/0/3-4.30',
'lectureSections': [[[[14, 3], [74, 3]], '2-147']]},
'18.353': {'lectureRawSections': '2-131/TR/0/9.30-11',
'lectureSections': [[[[33, 3], [93, 3]], '2-131']]},
'18.367': {'lectureRawSections': '2-139/TR/0/1-2.30',
'lectureSections': [[[[40, 3], [100, 3]], '2-139']]},
'18.384': {'lectureRawSections': '2-151/TR/0/9.30-11',
'lectureSections': [[[[33, 3], [93, 3]], '2-151']]},
'18.404': {'lectureRawSections': '54-100/TR/0/2.30-4',
'lectureSections': [[[[43, 3], [103, 3]], '54-100']]},
'18.4041': {'lectureRawSections': '54-100/TR/0/2.30-4',
'lectureSections': [[[[43, 3], [103, 3]], '54-100']]},
'18.408': {'lectureRawSections': '2-132/TR/0/1-2.30',
'lectureSections': [[[[40, 3], [100, 3]], '2-132']]},
'18.410': {'lectureRawSections': '34-101/TR/0/11-12.30',
'lectureSections': [[[[36, 3], [96, 3]], '34-101']]},
'18.415': {'lectureRawSections': '32-123/MWF/0/2.30-4',
'lectureSections': [[[[13, 3], [73, 3], [133, 3]], '32-123']]},
'18.418': {'lectureRawSections': '8-119/MW/0/11.30-1',
'lectureSections': [[[[7, 3], [67, 3]], '8-119']]},
'18.424': {'lectureRawSections': '2-131/TR/0/2.30-4',
'lectureSections': [[[[43, 3], [103, 3]], '2-131']]},
'18.434': {'lectureRawSections': '2-146/TR/0/11-12.30',
'lectureSections': [[[[36, 3], [96, 3]], '2-146']]},
'18.435': {'lectureRawSections': '4-370/MWF/0/1',
'lectureSections': [[[[10, 2], [70, 2], [130, 2]], '4-370']]},
'18.600': {'lectureRawSections': '34-101/MW/0/11-12.30',
'lectureSections': [[[[6, 3], [66, 3]], '34-101']]},
'18.642': {'lectureRawSections': '32-124/TR/0/2.30-4',
'lectureSections': [[[[43, 3], [103, 3]], '32-124']]},
'18.650': {'lectureRawSections': '2-190/MWF/0/10',
'lectureSections': [[[[4, 2], [64, 2], [124, 2]], '2-190']]},
'18.6501': {'lectureRawSections': '2-190/MWF/0/10',
'lectureSections': [[[[4, 2], [64, 2], [124, 2]], '2-190']]},
'18.675': {'lectureRawSections': '32-155/TR/0/2.30-4',
'lectureSections': [[[[43, 3], [103, 3]], '32-155']]},
'18.700': {'lectureRawSections': '6-120/MW/0/9.30-11',
'lectureSections': [[[[3, 3], [63, 3]], '6-120']]},
'18.701': {'lectureRawSections': '2-190/TR/0/1-2.30',
'lectureSections': [[[[40, 3], [100, 3]], '2-190']]},
'18.704': {'lectureRawSections': '2-146/MW/0/1-2.30',
'lectureSections': [[[[10, 3], [70, 3]], '2-146']]},
'18.705': {'lectureRawSections': '2-139/MW/0/3-4.30',
'lectureSections': [[[[14, 3], [74, 3]], '2-139']]},
'18.725': {'lectureRawSections': '2-142/MWF/0/9',
'lectureSections': [[[[2, 2], [62, 2], [122, 2]], '2-142']]},
'18.745': {'lectureRawSections': '2-146/TR/0/2.30-4',
'lectureSections': [[[[43, 3], [103, 3]], '2-146']]},
'18.785': {'lectureRawSections': '2-139/TR/0/11-12.30',
'lectureSections': [[[[36, 3], [96, 3]], '2-139']]},
'18.821': {'lectureRawSections': '2-135/MW/0/2-4',
'lectureSections': [[[[12, 4], [72, 4]], '2-135']]},
'18.901': {'lectureRawSections': '4-163/TR/0/2.30-4',
'lectureSections': [[[[43, 3], [103, 3]], '4-163']]},
'18.905': {'lectureRawSections': '32-141/MWF/0/10',
'lectureSections': [[[[4, 2], [64, 2], [124, 2]], '32-141']]},
'18.937': {'lectureRawSections': '66-144/TR/0/9.30-11',
'lectureSections': [[[[33, 3], [93, 3]], '66-144']]},
'18.950': {'lectureRawSections': '2-131/TR/0/1-2.30',
'lectureSections': [[[[40, 3], [100, 3]], '2-131']]},
'18.9501': {'lectureRawSections': '2-131/TR/0/1-2.30',
'lectureSections': [[[[40, 3], [100, 3]], '2-131']]},
'18.965': {'lectureRawSections': '24-121/TR/0/11-12.30',
'lectureSections': [[[[36, 3], [96, 3]], '24-121']]},
'18.A11': {'lectureRawSections': '2-136/F/0/10-12',
'lectureSections': [[[[124, 4]], '2-136']]},
'18.A34': {'lectureRawSections': '2-136/MW/0/1',
'lectureSections': [[[[10, 2], [70, 2]], '2-136']]},
'18.C06': {'lectureRawSections': '45-230/MWF/0/11',
'lectureSections': [[[[6, 2], [66, 2], [126, 2]], '45-230']]},
'18.C20': {'lectureRawSections': '33-419/MW/0/3-4.30',
'lectureSections': [[[[14, 3], [74, 3]], '33-419']]},
'18.C25': {'lectureRawSections': '4-149/MW/0/1-2.30',
'lectureSections': [[[[10, 3], [70, 3]], '4-149']]}
}


Expand Down

0 comments on commit e23a7c6

Please sign in to comment.