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

Exams scraper #60

Merged
merged 3 commits into from
Apr 21, 2016
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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,8 @@ uoftscrapers.Exams
"start_time": String,
"end_time": String,
"sections": [{
"section": String,
"lecture_code": String,
"exam_section": String,
"location": String
}]
}
Expand Down
18 changes: 9 additions & 9 deletions uoftscrapers/scrapers/exams/utm.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,11 @@ def retrieve_exams(courses):
soup = BeautifulSoup(html, 'html.parser')

course_code = soup.find('div', class_='title').text.strip()
lecture_code = None

# some course names include lecture code (see CHI200Y5Y)
if ' ' in course_code:
course_code, lecture_code = course_code.split(' ')
else:
lecture_code = None

data = [br.previous_sibling.string.strip()
for br in soup.find('div', class_='info').find_all('br')]
Expand All @@ -71,14 +70,14 @@ def retrieve_exams(courses):
for room in [x for x in data[3:] if 'Room:' in x]]

# append lecture code to section range if it exists
if lecture_code:
sections[0]['section'] = '%s %s' % (lecture_code,
sections[0]['section'])
for i in range(len(sections)):
sections[i]['lecture'] = lecture_code or ''

doc = OrderedDict([
('id', id_),
('course_id', course_id),
('course_code', course_code),
('campus', 'UTM'),
('period', period),
('date', date),
('start_time', start),
Expand All @@ -90,10 +89,11 @@ def retrieve_exams(courses):
exams[id_] = doc

for section in sections:
exams[id_]['sections'].append({
'section': section['section'].strip(),
'locaton': section['room']
})
exams[id_]['sections'].append(OrderedDict([
('lecture_code', section['lecture']),
('exam_section', section['section']),
('location', section['room'])
]))
return exams

@staticmethod
Expand Down
15 changes: 8 additions & 7 deletions uoftscrapers/scrapers/exams/utsc.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,13 @@ def scrape(location='.'):
for tr in table.find_all('tr')[1:]:
data = [x.text.strip() for x in tr.find_all('td')]

course_code = data[0]
course_code, lecture_code = data[0], None
if ' ' in course_code:
course_code, lecture_code = course_code.split(' ')
else:
lecture_code = None

date = data[1]
start, end = UTSCExams.parse_time(data[2], data[3], date)

location_ = data[4]

id_, course_id = UTSCExams.get_course_id(course_code, date)
Expand All @@ -47,6 +46,7 @@ def scrape(location='.'):
('id', id_),
('course_id', course_id),
('course_code', course_code),
('campus', 'UTSC'),
('period', period),
('date', date),
('start_time', start),
Expand All @@ -57,10 +57,11 @@ def scrape(location='.'):
if id_ not in exams:
exams[id_] = doc

exams[id_]['sections'].append({
'section': lecture_code or '',
'location': location_
})
exams[id_]['sections'].append(OrderedDict([
('lecture_code', lecture_code or ''),
('exam_section', ''),
('location', location_)
]))

for id_, doc in exams.items():
Scraper.save_json(doc, location, id_)
Expand Down
18 changes: 16 additions & 2 deletions uoftscrapers/scrapers/exams/utsg.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,27 @@ def scrape(location='.', year=None):
if id_ is None:
continue

section, location_ = data[1], data[4]
section = data[1]

lecture_section = exam_section = None

if ' ' in section:
lecture_section, exam_section = section.split(' ')
elif '-' in section:
exam_section = section
else:
lecture_section = section

location_ = data[4]

date_ = UTSGExams.parse_date(data[2], p[-2:]) or ''
start, end = UTSGExams.parse_time(data[3], date_) or (0, 0)

doc = OrderedDict([
('id', id_),
('course_id', course_id),
('course_code', course_code),
('campus', 'UTSG'),
('period', p.upper()),
('date', date_),
('start_time', start),
Expand All @@ -69,7 +82,8 @@ def scrape(location='.', year=None):
exams[id_] = doc

exams[id_]['sections'].append(OrderedDict([
('section', section),
('lecture_code', lecture_section or ''),
('exam_section', exam_section or ''),
('location', location_)
]))

Expand Down