[F] courseinfo: hours might be empty

This commit is contained in:
Hykilpikonna
2021-09-03 15:35:36 -04:00
parent 3f0d9f3ff7
commit 2b15c8458f
+5 -1
View File
@@ -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'(?<=<h1 class="title page-title">).*(?=<)', html)[0]
name = ': '.join(name.split(': ')[1:])
hours: str = re.findall(r'(?<=<div class="field__item"><p>).*(?=<)', html)[0]
hours_raw = re.findall(r'(?<=<div class="field__item"><p>).*(?=<)', 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})'}