move functions to get election cycle index and name into utils.
build_develop / build (push) Successful in 1m52s

This commit is contained in:
2023-11-02 14:44:26 -04:00
parent 63e3b3edb2
commit 647af0353d
3 changed files with 36 additions and 18 deletions
+26 -2
View File
@@ -35,6 +35,30 @@ def get_election_cycle_name(config: DakinyConfig) -> str:
Returns:
str: the name of the election cycle
"""
# TODO finish
cycle = get_current_cycle(config)
current_cycle = config.election_cycles[cycle]
return f"vote-{election_start.year}-{election_cycle.name}"
return f"vote-{get_datetime(current_cycle.election_start).year}-{current_cycle.name}"
def get_current_cycle(config: DakinyConfig) -> int:
"""
Returns index for active election. An election is considered active between the election start and the term start.
Args:
config (DakinyConfig): Config object to use
Returns:
int: cycle index for active election. -1 for no active cycle
"""
today = datetime.today()
for cycle, election in enumerate(config.election_cycles):
if (
today.date() >= get_datetime(election.election_start).date()
and today.date() <= get_datetime(election.term_start).date()
):
return cycle
return -1