Skip to content

Commit

Permalink
🎨 Handle non-standard rows in score parsing process
Browse files Browse the repository at this point in the history
Enhanced the score parsing routine in "utils.py" to manage cases of rows that are not score-related by skipping them in the process. This update ensures proper parsing even when encountering and handling non-standard rows. Furthermore, the `score_credits` field in scores is now optional, catering for scenarios when certain scores lack associated credits.
  • Loading branch information
lennartkaden committed Dec 9, 2023
1 parent 9ee8571 commit 58931b1
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions versions/v1/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,13 @@ def parse_base_score_row(cells) -> BaseScore:
title: str = cells[1].text.strip()
semester: str = cells[3].text.strip()
grade: Optional[float] = None
status: ScoreStatus = ScoreStatus(cells[5].text.strip())
score_credits: int = int(cells[6].text.strip())

raw_score_status: str = cells[5].text.strip()
if not raw_score_status:
raw_score_status = "angemeldet"

status: ScoreStatus = ScoreStatus(raw_score_status)
score_credits: int or None = int(cells[6].text.strip()) if cells[6].text.strip() else None
issued_on: str = cells[7].text.strip()

return BaseScore(id=score_id, title=title, semester=semester, grade=grade, status=status, credits=score_credits,
Expand Down Expand Up @@ -222,17 +227,25 @@ def parse_scorecard(html_text: str) -> List[BaseScore] or None:
scores = []

latest_base_score = None
skip_next_row = False

# iterate over the rows
for row in rows:
# get the cells of the row
cells = row.findAll("td")

if skip_next_row:
skip_next_row = False
continue

# check if the row has the expected structure
if len(cells) != 11:
# if the row has not 11 cells, it is not a score row, but a title row. This row is followed by another row,
# which should be skipped
skip_next_row = True
continue

if not cells[6].text.strip():
if not cells[6].text.strip() and cells[7].text.strip():
continue

# get the score's type
Expand Down

0 comments on commit 58931b1

Please sign in to comment.