mirror of
https://github.com/kaaninchen/Gleiswechsel.git
synced 2026-09-17 16:52:47 +00:00
transitous rewrite: fix transfer
This commit is contained in:
@@ -229,6 +229,7 @@ def get_trip_details(random_connection: dict | None) -> dict | None:
|
|||||||
"duration": legs["duration"],
|
"duration": legs["duration"],
|
||||||
"departure": departure_dt.strftime("%H:%M"),
|
"departure": departure_dt.strftime("%H:%M"),
|
||||||
"arrival": arrival_dt.strftime("%H:%M"),
|
"arrival": arrival_dt.strftime("%H:%M"),
|
||||||
|
"arrival_dt": arrival_dt,
|
||||||
"mode": mode,
|
"mode": mode,
|
||||||
"stops": {}
|
"stops": {}
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-12
@@ -3,7 +3,7 @@ import asyncio
|
|||||||
import random
|
import random
|
||||||
from datetime import datetime, timedelta, date
|
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
|
from src.config import config
|
||||||
|
|
||||||
_scheduled_task: asyncio.Task | None = None
|
_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)
|
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):
|
async def _schedule_next_transfer(bot: discord.Bot, arrival_dt: datetime, voice_channel: discord.VoiceChannel, destination: str):
|
||||||
now = datetime.now()
|
now = datetime.now(LOCAL_TZ)
|
||||||
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)
|
|
||||||
|
|
||||||
wait_seconds = (arrival_dt - now).total_seconds()
|
wait_seconds = (arrival_dt - now).total_seconds()
|
||||||
announcement_countdown = random.randrange(180, 300)
|
announcement_countdown = random.randrange(180, 300)
|
||||||
announcement_countdown = 3
|
|
||||||
if wait_seconds > 0:
|
if wait_seconds > 0:
|
||||||
remaining = str(timedelta(seconds=wait_seconds))
|
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:
|
if wait_seconds > announcement_countdown:
|
||||||
wait_until_end_announcement = 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):
|
async def announcer(announcement: str, voice_channel: discord.VoiceChannel, destination = None):
|
||||||
from src.dc.embeds import build_info_embed, build_announcement_embed
|
from src.dc.embeds import build_info_embed, build_announcement_embed
|
||||||
|
now = datetime.now()
|
||||||
announcements_enabled = config.announcements.enabled
|
announcements_enabled = config.announcements.enabled
|
||||||
voice_announcement_enabled = config.announcements.voice[0].enabled
|
voice_announcement_enabled = config.announcements.voice[0].enabled
|
||||||
|
|
||||||
|
|||||||
@@ -150,7 +150,6 @@ def get_sound_path(destination) -> str | None:
|
|||||||
|
|
||||||
def get_next_station(stops: dict, train_from :str) -> dict | None:
|
def get_next_station(stops: dict, train_from :str) -> dict | None:
|
||||||
now = datetime.now(LOCAL_TZ)
|
now = datetime.now(LOCAL_TZ)
|
||||||
print(train_from)
|
|
||||||
for name, arrival_dt in stops.items():
|
for name, arrival_dt in stops.items():
|
||||||
if arrival_dt >= now:
|
if arrival_dt >= now:
|
||||||
if name == train_from:
|
if name == train_from:
|
||||||
|
|||||||
Reference in New Issue
Block a user