mirror of https://github.com/stijndcl/didier
Parse publication time of notifications
parent
d75831f848
commit
000337107b
|
@ -13,7 +13,7 @@ async def get_courses_with_announcements(session: AsyncSession) -> list[UforaCou
|
|||
|
||||
|
||||
async def create_new_announcement(
|
||||
session: AsyncSession, announcement_id: int, course: UforaCourse, publication_date: datetime
|
||||
session: AsyncSession, announcement_id: int, course: UforaCourse, publication_date: datetime.datetime
|
||||
) -> UforaAnnouncement:
|
||||
"""Add a new announcement to the database"""
|
||||
new_announcement = UforaAnnouncement(
|
||||
|
|
|
@ -13,7 +13,8 @@ class Tasks(commands.Cog):
|
|||
|
||||
client: Didier
|
||||
|
||||
def __init__(self, client: Didier): # pylint: disable=no-member
|
||||
def __init__(self, client: Didier):
|
||||
# pylint: disable=no-member
|
||||
self.client = client
|
||||
|
||||
# Only pull announcements if a token was provided
|
||||
|
|
|
@ -12,6 +12,8 @@ from sqlalchemy.ext.asyncio import AsyncSession
|
|||
import settings
|
||||
from database.crud import ufora_announcements as crud
|
||||
from database.models import UforaCourse
|
||||
from didier.utils.types.datetime import int_to_weekday
|
||||
from didier.utils.types.string import leading
|
||||
|
||||
|
||||
@dataclass
|
||||
|
@ -88,8 +90,19 @@ class UforaNotification:
|
|||
|
||||
def _get_published(self) -> str:
|
||||
"""Get a formatted string that represents when this announcement was published"""
|
||||
# TODO
|
||||
return "Placeholder :) TODO make the functions to format this"
|
||||
return (
|
||||
f"{int_to_weekday(self.published_dt.weekday())} "
|
||||
f"{leading('0', str(self.published_dt.day))}"
|
||||
"/"
|
||||
f"{leading('0', str(self.published_dt.month))}"
|
||||
"/"
|
||||
f"{self.published_dt.year} "
|
||||
f"om {leading('0', str(self.published_dt.hour))}"
|
||||
":"
|
||||
f"{leading('0', str(self.published_dt.minute))}"
|
||||
":"
|
||||
f"{leading('0', str(self.published_dt.second))}"
|
||||
)
|
||||
|
||||
|
||||
def parse_ids(url: str) -> Optional[tuple[int, int]]:
|
||||
|
|
|
@ -8,7 +8,7 @@ from sqlalchemy.ext.asyncio import AsyncSession
|
|||
|
||||
import settings
|
||||
from database.engine import DBSession
|
||||
from didier.utils.prefix import get_prefix
|
||||
from didier.utils.discord.prefix import get_prefix
|
||||
|
||||
|
||||
class Didier(commands.Bot):
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
def int_to_weekday(number: int) -> str:
|
||||
"""Get the Dutch name of a weekday from the number"""
|
||||
return ["Maandag", "Dinsdag", "Woensdag", "Donderdag", "Vrijdag", "Zaterdag", "Zondag"][number]
|
|
@ -0,0 +1,21 @@
|
|||
from typing import Optional
|
||||
|
||||
|
||||
def leading(character: str, string: str, target_length: Optional[int] = 2) -> str:
|
||||
"""Add a leading [character] to [string] to make it length [target_length]
|
||||
Pass None to target length to always do it, no matter the length
|
||||
"""
|
||||
# Cast to string just in case
|
||||
string = str(string)
|
||||
|
||||
# Add no matter what
|
||||
if target_length is None:
|
||||
return character + string
|
||||
|
||||
# String is already long enough
|
||||
if len(string) >= target_length:
|
||||
return string
|
||||
|
||||
frequency = (target_length - len(string)) // len(character)
|
||||
|
||||
return (frequency * character) + string
|
Loading…
Reference in New Issue