Skip to content

Commit

Permalink
Changed get_weight_as_int() to return 0 if no weight can be parsed
Browse files Browse the repository at this point in the history
  • Loading branch information
49Indium committed Oct 9, 2023
1 parent 1867335 commit 709071d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions uqcsbot/utils/uq_course_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,14 @@ def is_before(self, cutoff: datetime):
return True
return start_datetime <= cutoff

def get_weight_as_int(self) -> Optional[int]:
def get_weight_as_int(self):
"""
Trys to get the weight percentage of an assessment as a percentage. Will return None
Trys to get the weight percentage of an assessment as a percentage. Will return 0
if a percentage can not be obtained.
"""
if match := re.match(r"\d+", self.weight):
return int(match.group(0))
return None
return 0


class DateSyntaxException(Exception):
Expand Down
2 changes: 1 addition & 1 deletion uqcsbot/whatsdue.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def sort_by_date(item: AssessmentItem):
] = {
"Date": sort_by_date,
"Course Name": (lambda item: item.course_name),
"Weight": (lambda item: item.get_weight_as_int() or 0),
"Weight": item.get_weight_as_int(),
}


Expand Down

0 comments on commit 709071d

Please sign in to comment.