Use datetime.now().date() instead of today().
build_latest / build (push) Successful in 1m53s
build_release / build (push) Successful in 17s

This commit is contained in:
2024-05-22 16:23:53 -04:00
parent ed06748984
commit 1fd1be5576
4 changed files with 16 additions and 17 deletions
+4 -5
View File
@@ -3,12 +3,9 @@ Contains the election cycle class
""" """
import collections import collections
from datetime import datetime, timedelta from datetime import UTC, datetime, timedelta
import nextcord import nextcord
from sqlalchemy import select, true, update
from sqlalchemy.orm import Session
from classes.nominate_highcouncil_views import NominateHighCouncilView from classes.nominate_highcouncil_views import NominateHighCouncilView
from classes.nominate_views import NominateView from classes.nominate_views import NominateView
from classes.voting_highcouncil_views import VoteHighcouncilView from classes.voting_highcouncil_views import VoteHighcouncilView
@@ -20,6 +17,8 @@ from database_setup.sql_data_classes import (
Votes, Votes,
engine, engine,
) )
from sqlalchemy import select, true, update
from sqlalchemy.orm import Session
from utils import ( from utils import (
TEMPLATES_DIR, TEMPLATES_DIR,
VoteType, VoteType,
@@ -143,7 +142,7 @@ class ElectionCycle:
""" """
Function checks current date to see if something needs to be run. Function checks current date to see if something needs to be run.
""" """
today = datetime.today() today = datetime.now(tz=UTC).date()
# check all dates if action is needed # check all dates if action is needed
if today.date() == self.election_start.date(): if today.date() == self.election_start.date():
+2 -2
View File
@@ -2,7 +2,7 @@
Contains commands and views for set commands. Contains commands and views for set commands.
""" """
from datetime import datetime from datetime import UTC, datetime
import nextcord import nextcord
from nextcord.ext import commands from nextcord.ext import commands
@@ -57,7 +57,7 @@ class setCog(commands.Cog, name="Set Commands"):
return return
# check if valid day # check if valid day
today = datetime.today() today = datetime.now(tz=UTC).date()
try: try:
birthday = datetime(today.year, month, day) birthday = datetime(today.year, month, day)
except ValueError: except ValueError:
+3 -3
View File
@@ -3,7 +3,7 @@ Defines the daily loop that runs the Dakiny bot functions.
""" """
import random import random
from datetime import datetime, time from datetime import UTC, datetime, time
import nextcord import nextcord
from nextcord.ext import commands, tasks from nextcord.ext import commands, tasks
@@ -92,7 +92,7 @@ class DailyLoop(commands.Cog, name="Daily Loop"):
if random.randint(0, 99) == 0: if random.randint(0, 99) == 0:
birthday_list.append(239547993106284544) birthday_list.append(239547993106284544)
today = datetime.today() today = datetime.now(tz=UTC).date()
birthday = f"{today.month}/{today.day}" birthday = f"{today.month}/{today.day}"
stmt = select(UserBirthday.UserId).where(UserBirthday.Birthday == birthday) stmt = select(UserBirthday.UserId).where(UserBirthday.Birthday == birthday)
@@ -105,7 +105,7 @@ class DailyLoop(commands.Cog, name="Daily Loop"):
Loops through the guild's humans checking for joined_at dates that match today's date. Sends a message Loops through the guild's humans checking for joined_at dates that match today's date. Sends a message
saying happy cakeday. saying happy cakeday.
""" """
today = datetime.today() today = datetime.now(tz=UTC).date()
guild: nextcord.Guild = self.bot.get_guild(self.bot.config.params.guild_id) guild: nextcord.Guild = self.bot.get_guild(self.bot.config.params.guild_id)
announce_channel: nextcord.TextChannel = guild.get_channel(self.bot.config.params.general_channel_id) announce_channel: nextcord.TextChannel = guild.get_channel(self.bot.config.params.general_channel_id)
+7 -7
View File
@@ -1,9 +1,9 @@
"""File contains util functions.""" """File contains util functions."""
import calendar import calendar
import datetime
import os import os
from collections.abc import Sequence from collections.abc import Sequence
from datetime import UTC, datetime
from enum import StrEnum from enum import StrEnum
from pathlib import Path from pathlib import Path
@@ -30,7 +30,7 @@ TEMPLATES_DIR = f"{REPO_DIR}/message_templates"
VoteType = StrEnum("VoteType", ["COUNCIL", "DISCORDMANAGER", "CLANLEADER"]) VoteType = StrEnum("VoteType", ["COUNCIL", "DISCORDMANAGER", "CLANLEADER"])
def get_datetime(day: str) -> datetime.datetime: def get_datetime(day: str) -> datetime:
""" """
Takes in a string month and day and returns a datetime object of that Month/Day this year. Takes in a string month and day and returns a datetime object of that Month/Day this year.
@@ -40,7 +40,7 @@ def get_datetime(day: str) -> datetime.datetime:
Returns: Returns:
datetime: Datetime representation of Month/Day. datetime: Datetime representation of Month/Day.
""" """
today = datetime.datetime.now(tz=datetime.UTC).date() today = datetime.now(tz=UTC).date()
year = today.year year = today.year
month = int(day.split("/")[0]) month = int(day.split("/")[0])
day = int(day.split("/")[1]) day = int(day.split("/")[1])
@@ -52,7 +52,7 @@ def get_datetime(day: str) -> datetime.datetime:
if today.month == calendar.JANUARY and month > calendar.JANUARY: if today.month == calendar.JANUARY and month > calendar.JANUARY:
year -= 1 year -= 1
return datetime.datetime(year, month, day, tzinfo=datetime.UTC) return datetime(year, month, day, tzinfo=UTC)
def get_election_name(config: DakinyConfig) -> str: def get_election_name(config: DakinyConfig) -> str:
@@ -96,7 +96,7 @@ def get_current_election_cycle(config: DakinyConfig) -> int:
Returns: Returns:
int: cycle index for active election. None for no active cycle int: cycle index for active election. None for no active cycle
""" """
today = datetime.datetime.now(tz=datetime.UTC).date() today = datetime.now(tz=UTC).date()
for cycle, election in enumerate(config.election_cycles): for cycle, election in enumerate(config.election_cycles):
if ( if (
@@ -119,7 +119,7 @@ def get_quarter_cycle(config: DakinyConfig) -> int:
Returns: Returns:
int: cycle index for current cycle. int: cycle index for current cycle.
""" """
today = datetime.datetime.now(tz=datetime.UTC).date() today = datetime.now(tz=UTC).date()
for cycle, election in enumerate(config.election_cycles): for cycle, election in enumerate(config.election_cycles):
if ( if (
today.date() >= get_datetime(election.term_start).date() today.date() >= get_datetime(election.term_start).date()
@@ -357,7 +357,7 @@ def get_allowed_points(session: Session, points_limit: int, user: str, points: i
int: how many points are allowed to be given to the user. int: how many points are allowed to be given to the user.
""" """
# check for limit # check for limit
today = datetime.datetime.now(tz=datetime.UTC).date() today = datetime.now(tz=UTC).date()
this_week = f"{today.isocalendar().year}-{today.isocalendar().week}" this_week = f"{today.isocalendar().year}-{today.isocalendar().week}"
stmt = select(EventPointsLimit).where(EventPointsLimit.UserId == user).where(EventPointsLimit.Week == this_week) stmt = select(EventPointsLimit).where(EventPointsLimit.UserId == user).where(EventPointsLimit.Week == this_week)