diff --git a/uoftscrapers/scrapers/exams/utm.py b/uoftscrapers/scrapers/exams/utm.py index cab97b5..7fc9c0b 100644 --- a/uoftscrapers/scrapers/exams/utm.py +++ b/uoftscrapers/scrapers/exams/utm.py @@ -2,7 +2,7 @@ from bs4 import BeautifulSoup from collections import OrderedDict from datetime import datetime -import pytz +from pytz import timezone import re @@ -176,8 +176,8 @@ def parse_sections(room): def parse_time(start, end, date): def convert_time(t): h, m, s = [int(x) for x in t.split(':')] - d = datetime.strptime('%s %s %s %s' % (date, h, m, s), - '%Y-%m-%d %H %M %S') - return d.replace(tzinfo=pytz.timezone('US/Eastern')).isoformat() + 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 convert_time(start), convert_time(end) diff --git a/uoftscrapers/scrapers/exams/utsc.py b/uoftscrapers/scrapers/exams/utsc.py index a2c609c..d7d4d89 100644 --- a/uoftscrapers/scrapers/exams/utsc.py +++ b/uoftscrapers/scrapers/exams/utsc.py @@ -2,7 +2,7 @@ from bs4 import BeautifulSoup from collections import OrderedDict from datetime import datetime -import pytz +from pytz import timezone class UTSCExams: @@ -130,6 +130,7 @@ 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(':')] - d = datetime.strptime('%s %s %s' % (date, h, m), '%Y-%m-%d %H %M') - return d.replace(tzinfo=pytz.timezone('US/Eastern')).isoformat() + dt = datetime.strptime('%s %s %s' % (date, h, m), '%Y-%m-%d %H %M') + return timezone('US/Eastern').localize(dt).isoformat() + return convert_time(start), convert_time(end) diff --git a/uoftscrapers/scrapers/exams/utsg.py b/uoftscrapers/scrapers/exams/utsg.py index c9a5b25..b1ced42 100644 --- a/uoftscrapers/scrapers/exams/utsg.py +++ b/uoftscrapers/scrapers/exams/utsg.py @@ -1,8 +1,8 @@ from ..utils import Scraper from bs4 import BeautifulSoup from collections import OrderedDict -from datetime import datetime, date -import pytz +from datetime import datetime +from pytz import timezone class UTSGExams: @@ -63,8 +63,8 @@ def scrape(location='.', year=None): location_ = data[4] - date_ = UTSGExams.parse_date(data[2], p[-2:]) or '' - start, end = UTSGExams.parse_time(data[3], date_) or (0, 0) + date = UTSGExams.parse_date(data[2], p[-2:]) or '' + start, end = UTSGExams.parse_time(data[3], date) or (0, 0) doc = OrderedDict([ ('id', id_), @@ -72,7 +72,7 @@ def scrape(location='.', year=None): ('course_code', course_code), ('campus', 'UTSG'), ('period', p.upper()), - ('date', date_), + ('date', date), ('start_time', start), ('end_time', end), ('sections', []) @@ -124,14 +124,14 @@ def parse_course_info(period, course_code): return exam_id, course_id, course_code @staticmethod - def parse_date(date_, year): + def parse_date(date, year): """Convert date of form `D DD MMM` to ISO 8601 format.""" - date_ = date_.split(' ') - if len(date_) == 3: - day, date_, month = date_ + date = date.split(' ') + if len(date) == 3: + day, date, month = date - return datetime.strptime('%s %s %s %s' % (day, date_, month, year), + return datetime.strptime('%s %s %s %s' % (day, date, month, year), '%a %d %b %y').date().isoformat() @staticmethod @@ -142,9 +142,8 @@ 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 - - date_ = datetime.strptime('%s %s %s' % (d, h, m), '%Y-%m-%d %H %M') - return date_.replace(tzinfo=pytz.timezone('US/Eastern')).isoformat() + dt = datetime.strptime('%s %s %s' % (d, h, m), '%Y-%m-%d %H %M') + return timezone('US/Eastern').localize(dt).isoformat() time = list(filter(None, time.replace('-', '').split(' '))) if len(time) == 3: @@ -156,7 +155,7 @@ def convert_time(t, is_pm=False): @staticmethod def get_exam_periods(year): if not year: - year = date.today().year + year = datetime.today().year periods = [] for m in ('dec', 'apr', 'june', 'aug'):