diff --git a/dakiny_bot/utils.py b/dakiny_bot/utils.py index 6156682..69eb1f2 100644 --- a/dakiny_bot/utils.py +++ b/dakiny_bot/utils.py @@ -34,20 +34,20 @@ VoteType = StrEnum("VoteType", ["COUNCIL", "DISCORDMANAGER", "CLANLEADER"]) PointType = StrEnum("PointType", ["CLAN", "EVENT"]) -def get_datetime(day: str) -> datetime: +def get_datetime(month_day: str) -> datetime: """ Takes in a string month and day and returns a datetime object of that Month/Day this year. Args: - day (str): Month/Day in that format. + month_day (str): Month/Day in that format. Returns: datetime: Datetime representation of Month/Day. """ today = datetime.now(tz=UTC).date() year = today.year - month = int(day.split("/")[0]) - day = int(day.split("/")[1]) + month = int(month_day.split("/")[0]) + day = int(month_day.split("/")[1]) # ensure that year rolls over if current month is December and the next month is less than 12. if today.month == calendar.DECEMBER and month < calendar.OCTOBER: @@ -66,7 +66,10 @@ def get_election_name() -> str: Returns: str: the name of the election cycle """ - cycle = get_active_election_cycle() + if cycle := get_active_election_cycle() is None: + # undefined behavior + print("Did not find an active election cycle. Undefined behavior with return string.") # noqa: T201 + return "No-active-election-cycle" current_cycle = settings.election_cycles[cycle] return f"vote-{get_datetime(current_cycle.term_start).year}-{current_cycle.name}" @@ -78,13 +81,16 @@ def get_quarter_name() -> str: Returns: str: the name of the cycle. """ - cycle = get_quarter_cycle() + if cycle := get_quarter_cycle() is None: + # undefined behavior + print("Did not find a quarter cycle. Undefined behavior with return string.") # noqa: T201 + return "no-quarter-cycle" current_cycle = settings.election_cycles[cycle] return f"{get_datetime(current_cycle.term_start).year}-{current_cycle.name}" -def get_active_election_cycle() -> int: +def get_active_election_cycle() -> int | None: """ Returns index for active election. An election is considered active between the election start and the term start. @@ -104,7 +110,7 @@ def get_active_election_cycle() -> int: return get_quarter_cycle() -def get_quarter_cycle() -> int: +def get_quarter_cycle() -> int | None: """ Returns the index for the current cycle/quarter. Defined as between term start and end.