From 709071dd3e20271bdd48bdaf036a865d3e4aa8cd Mon Sep 17 00:00:00 2001 From: Isaac Beh Date: Mon, 9 Oct 2023 17:35:17 +1000 Subject: [PATCH] Changed get_weight_as_int() to return 0 if no weight can be parsed --- uqcsbot/utils/uq_course_utils.py | 6 +++--- uqcsbot/whatsdue.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/uqcsbot/utils/uq_course_utils.py b/uqcsbot/utils/uq_course_utils.py index 93432227..898e82d2 100644 --- a/uqcsbot/utils/uq_course_utils.py +++ b/uqcsbot/utils/uq_course_utils.py @@ -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): diff --git a/uqcsbot/whatsdue.py b/uqcsbot/whatsdue.py index 98528c17..dbfc30e5 100644 --- a/uqcsbot/whatsdue.py +++ b/uqcsbot/whatsdue.py @@ -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(), }