Move get_quarter_cycle into election_utils.py.
This commit is contained in:
@@ -3,6 +3,8 @@
|
|||||||
import calendar
|
import calendar
|
||||||
from datetime import UTC, datetime
|
from datetime import UTC, datetime
|
||||||
|
|
||||||
|
from .dakiny_settings import settings
|
||||||
|
|
||||||
|
|
||||||
def get_datetime(month_day: str) -> datetime:
|
def get_datetime(month_day: str) -> datetime:
|
||||||
"""
|
"""
|
||||||
@@ -27,3 +29,23 @@ def get_datetime(month_day: str) -> datetime:
|
|||||||
year -= 1
|
year -= 1
|
||||||
|
|
||||||
return datetime(year, month, day, tzinfo=UTC)
|
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
@@ -21,7 +21,7 @@ from dakiny_bot.database.sql_data_classes import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
from .dakiny_settings import settings
|
from .dakiny_settings import settings
|
||||||
from .election_utils import get_datetime
|
from .election_utils import get_datetime, get_quarter_cycle
|
||||||
|
|
||||||
NOMINEE_SPLITTER = "========================================\n\n"
|
NOMINEE_SPLITTER = "========================================\n\n"
|
||||||
REPO_DIR = "./dakiny-messages"
|
REPO_DIR = "./dakiny-messages"
|
||||||
@@ -85,26 +85,6 @@ def get_active_election_cycle() -> int | None:
|
|||||||
return get_quarter_cycle()
|
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:
|
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.
|
Creates a string that contains all nominees and their votes to be sent as a discord message.
|
||||||
|
|||||||
Reference in New Issue
Block a user