diff --git a/src/api/transitous.py b/src/api/transitous.py index b255557..e124988 100644 --- a/src/api/transitous.py +++ b/src/api/transitous.py @@ -229,6 +229,7 @@ def get_trip_details(random_connection: dict | None) -> dict | None: "duration": legs["duration"], "departure": departure_dt.strftime("%H:%M"), "arrival": arrival_dt.strftime("%H:%M"), + "arrival_dt": arrival_dt, "mode": mode, "stops": {} } diff --git a/src/dc/handlers.py b/src/dc/handlers.py index c2c00c9..a4052f6 100644 --- a/src/dc/handlers.py +++ b/src/dc/handlers.py @@ -3,7 +3,7 @@ import asyncio import random from datetime import datetime, timedelta, date -from src.utils import logger, channel_formatting, choose_connection, get_sound_path +from src.utils import logger, channel_formatting, choose_connection, get_sound_path, LOCAL_TZ from src.config import config _scheduled_task: asyncio.Task | None = None @@ -42,23 +42,18 @@ async def rename_vc(bot: discord.Bot, voice_channel, from_scheduler: bool = Fals await announcer("umstieg", voice_channel) - _scheduled_task = asyncio.create_task(_schedule_next_transfer(bot, arrival, voice_channel, trip["to"])) + _scheduled_task = asyncio.create_task(_schedule_next_transfer(bot, trip["arrival_dt"], voice_channel, trip["to"])) -async def _schedule_next_transfer(bot: discord.Bot, arrival, voice_channel: discord.VoiceChannel, destination: str): - now = datetime.now() - parsed_time = datetime.strptime(arrival, "%H:%M").time() - arrival_dt = datetime.combine(date.today(), parsed_time) - - if arrival_dt < now: - arrival_dt += timedelta(days=1) +async def _schedule_next_transfer(bot: discord.Bot, arrival_dt: datetime, voice_channel: discord.VoiceChannel, destination: str): + now = datetime.now(LOCAL_TZ) wait_seconds = (arrival_dt - now).total_seconds() announcement_countdown = random.randrange(180, 300) - announcement_countdown = 3 + if wait_seconds > 0: remaining = str(timedelta(seconds=wait_seconds)) - logger(f"Nächster Umstieg in {remaining.split('.')[0]} ({arrival} Uhr)") + logger(f"Nächster Umstieg in {remaining.split('.')[0]} ({arrival_dt.strftime('%H:%M')} Uhr)") if wait_seconds > announcement_countdown: wait_until_end_announcement = wait_seconds - announcement_countdown @@ -73,7 +68,7 @@ async def _schedule_next_transfer(bot: discord.Bot, arrival, voice_channel: disc async def announcer(announcement: str, voice_channel: discord.VoiceChannel, destination = None): from src.dc.embeds import build_info_embed, build_announcement_embed - + now = datetime.now() announcements_enabled = config.announcements.enabled voice_announcement_enabled = config.announcements.voice[0].enabled diff --git a/src/utils.py b/src/utils.py index 2c42df2..f0ab591 100644 --- a/src/utils.py +++ b/src/utils.py @@ -150,7 +150,6 @@ def get_sound_path(destination) -> str | None: def get_next_station(stops: dict, train_from :str) -> dict | None: now = datetime.now(LOCAL_TZ) - print(train_from) for name, arrival_dt in stops.items(): if arrival_dt >= now: if name == train_from: