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

Update start, end times + add duration keys #71

Merged
merged 1 commit into from
Apr 28, 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
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -403,8 +403,9 @@ uoftscrapers.Exams
"course_code": String
"period": String,
"date": String,
"start_time": String,
"end_time": String,
"start_time": Number,
"end_time": Number,
"duration": Number,
"sections": [{
"lecture_code": String,
"exam_section": String,
Expand Down
7 changes: 3 additions & 4 deletions uoftscrapers/scrapers/exams/utm.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def retrieve_exams(courses):

start, end = UTMExams.parse_time(data[1].split(': ')[1],
data[2].split(': ')[1], date)
duration = end - start

sections = [UTMExams.parse_sections(room.split(': ')[1])
for room in [x for x in data[3:] if 'Room:' in x]]
Expand All @@ -82,6 +83,7 @@ def retrieve_exams(courses):
('date', date),
('start_time', start),
('end_time', end),
('duration', duration),
('sections', [])
])

Expand Down Expand Up @@ -176,8 +178,5 @@ def parse_sections(room):
def parse_time(start, end, date):
def convert_time(t):
h, m, s = [int(x) for x in t.split(':')]
dt = datetime.strptime('%s %s %s %s' % (date, h, m, s),
'%Y-%m-%d %H %M %S')
return timezone('US/Eastern').localize(dt).isoformat()

return (h * 60 * 60) + (m * 60) + s
return convert_time(start), convert_time(end)
6 changes: 3 additions & 3 deletions uoftscrapers/scrapers/exams/utsc.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def scrape(location='.'):

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

location_ = data[4]

Expand All @@ -51,6 +52,7 @@ def scrape(location='.'):
('date', date),
('start_time', start),
('end_time', end),
('duration', duration),
('sections', [])
])

Expand Down Expand Up @@ -130,7 +132,5 @@ def get_course_id(course_code, date):
def parse_time(start, end, date):
def convert_time(t):
h, m = [int(x) for x in t.split(':')]
dt = datetime.strptime('%s %s %s' % (date, h, m), '%Y-%m-%d %H %M')
return timezone('US/Eastern').localize(dt).isoformat()

return (h * 60 * 60) + (m * 60)
return convert_time(start), convert_time(end)
7 changes: 4 additions & 3 deletions uoftscrapers/scrapers/exams/utsg.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def scrape(location='.', year=None):

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

doc = OrderedDict([
('id', id_),
Expand All @@ -75,6 +76,7 @@ def scrape(location='.', year=None):
('date', date),
('start_time', start),
('end_time', end),
('duration', duration),
('sections', [])
])

Expand Down Expand Up @@ -141,9 +143,8 @@ def parse_time(time, d):
def convert_time(t, is_pm=False):
"""Convert time from `HH:MM` to an ISO 8601 datetime."""
h, m = [int(x) for x in t.split(':')]
h += 12 if is_pm else 0
dt = datetime.strptime('%s %s %s' % (d, h, m), '%Y-%m-%d %H %M')
return timezone('US/Eastern').localize(dt).isoformat()
h += 12 if is_pm and h != 12 else 0
return (h * 60 * 60) + (m * 60)

time = list(filter(None, time.replace('-', '').split(' ')))
if len(time) == 3:
Expand Down