Move get_quarter_cycle into election_utils.py.

This commit is contained in:
2025-04-24 09:34:53 -04:00
parent def9c4aa79
commit 0f3596692f
2 changed files with 23 additions and 21 deletions
+22
View File
@@ -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
+1 -21
View File
@@ -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.