From 2b15c8458f4d19ed87b7191a9a35758e7053c0f4 Mon Sep 17 00:00:00 2001 From: Hykilpikonna Date: Fri, 3 Sep 2021 15:35:36 -0400 Subject: [PATCH] [F] courseinfo: hours might be empty --- courseinfo.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/courseinfo.py b/courseinfo.py index 731fd8e..85ac76a 100644 --- a/courseinfo.py +++ b/courseinfo.py @@ -6,10 +6,14 @@ import requests def get_course_info(id: str): link = f'https://artsci.calendar.utoronto.ca/course/{id}' html = requests.get(link).text + name: str = re.findall(r'(?<=

).*(?=<)', html)[0] name = ': '.join(name.split(': ')[1:]) - hours: str = re.findall(r'(?<=

).*(?=<)', html)[0] + + hours_raw = re.findall(r'(?<=

).*(?=<)', html) + hours: str = '0N' if len(hours_raw) == 0 else hours_raw[0] hours = '/'.join([str(int(it[:-1]) / 12) + it[-1] for it in hours.split('/')]) + return {'id': id, 'name': name, 'link': link, 'hours': hours, 'full': f'`{id}` - [{hours}] [{name}]({link})'}