diff --git a/README.md b/README.md index 66ffafc..38ca1cc 100644 --- a/README.md +++ b/README.md @@ -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, diff --git a/uoftscrapers/scrapers/exams/utm.py b/uoftscrapers/scrapers/exams/utm.py index 7fc9c0b..3d1684f 100644 --- a/uoftscrapers/scrapers/exams/utm.py +++ b/uoftscrapers/scrapers/exams/utm.py @@ -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]] @@ -82,6 +83,7 @@ def retrieve_exams(courses): ('date', date), ('start_time', start), ('end_time', end), + ('duration', duration), ('sections', []) ]) @@ -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) diff --git a/uoftscrapers/scrapers/exams/utsc.py b/uoftscrapers/scrapers/exams/utsc.py index d7d4d89..42f35d7 100644 --- a/uoftscrapers/scrapers/exams/utsc.py +++ b/uoftscrapers/scrapers/exams/utsc.py @@ -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] @@ -51,6 +52,7 @@ def scrape(location='.'): ('date', date), ('start_time', start), ('end_time', end), + ('duration', duration), ('sections', []) ]) @@ -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) diff --git a/uoftscrapers/scrapers/exams/utsg.py b/uoftscrapers/scrapers/exams/utsg.py index b1ced42..ffa7e1b 100644 --- a/uoftscrapers/scrapers/exams/utsg.py +++ b/uoftscrapers/scrapers/exams/utsg.py @@ -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_), @@ -75,6 +76,7 @@ def scrape(location='.', year=None): ('date', date), ('start_time', start), ('end_time', end), + ('duration', duration), ('sections', []) ]) @@ -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: