diff --git a/dakiny_bot/election_utils.py b/dakiny_bot/election_utils.py index be18a7c..c0f581c 100644 --- a/dakiny_bot/election_utils.py +++ b/dakiny_bot/election_utils.py @@ -3,6 +3,8 @@ import calendar from datetime import UTC, datetime +from .dakiny_settings import settings + def get_datetime(month_day: str) -> datetime: """ @@ -27,3 +29,23 @@ def get_datetime(month_day: str) -> datetime: year -= 1 return datetime(year, month, day, tzinfo=UTC) + + +def get_quarter_cycle() -> int | None: + """ + Returns the index for the current cycle/quarter. Defined as between term start and end. + + Can return None if entire year isn't covered by cycles. + + Returns: + int: cycle index for current cycle. + """ + today = datetime.now(tz=UTC) + for cycle, election in enumerate(settings.election_cycles): + if ( + today.date() >= get_datetime(election.term_start).date() + and today.date() <= get_datetime(election.term_end).date() + ): + return cycle + + return None diff --git a/dakiny_bot/utils.py b/dakiny_bot/utils.py index 9c363bf..c4838b3 100644 --- a/dakiny_bot/utils.py +++ b/dakiny_bot/utils.py @@ -21,7 +21,7 @@ from dakiny_bot.database.sql_data_classes import ( ) from .dakiny_settings import settings -from .election_utils import get_datetime +from .election_utils import get_datetime, get_quarter_cycle NOMINEE_SPLITTER = "========================================\n\n" REPO_DIR = "./dakiny-messages" @@ -85,26 +85,6 @@ def get_active_election_cycle() -> int | None: return get_quarter_cycle() -def get_quarter_cycle() -> int | None: - """ - Returns the index for the current cycle/quarter. Defined as between term start and end. - - Can return None if entire year isn't covered by cycles. - - Returns: - int: cycle index for current cycle. - """ - today = datetime.now(tz=UTC) - for cycle, election in enumerate(settings.election_cycles): - if ( - today.date() >= get_datetime(election.term_start).date() - and today.date() <= get_datetime(election.term_end).date() - ): - return cycle - - return None - - def build_votes_str(guild: nextcord.Guild) -> str: """ Creates a string that contains all nominees and their votes to be sent as a discord message.