From 2f42edda367e161460371eeab2553f335e143ed6 Mon Sep 17 00:00:00 2001 From: Yash Sirvi <92856779+yashsirvi@users.noreply.github.com> Date: Mon, 29 Jul 2024 17:58:54 +0530 Subject: [PATCH] feat: check for emptyness of a cell before parsing it (#137) --- timetable/extractor.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/timetable/extractor.py b/timetable/extractor.py index 7c035988..0aaa79f6 100644 --- a/timetable/extractor.py +++ b/timetable/extractor.py @@ -74,11 +74,11 @@ def create_timings(_table: Tag | NavigableString) -> list[int]: course_duration: int = 0 cells = [cell for cell in row.find_all('td') if cell.attrs.get('valign') != 'top'] for index, cell in enumerate(cells): - code = cell.get_text()[:7] if cell.get_text()[:7] != "CS10001" else "CS10003" + code = cell.get_text()[:7].strip() if cell.get_text()[:7] != "CS10001" else "CS10003" + if not code: continue # continue if cell has no course in it # CS10003 is the actual code, but it is written as CS10001 in the timetable location = cell.get_text()[7:] cell_duration = int(cell.attrs.get('colspan')) - # To reuse code, uses outer scope variables def append_prev(): prev.duration = course_duration