mirror of
https://github.com/kaaninchen/Gleiswechsel.git
synced 2026-07-21 19:52:47 +00:00
Bug-Fixes bei Zugauswahl
This commit is contained in:
+3
-3
@@ -24,12 +24,12 @@ def format_iso_timestamp(isostr):
|
||||
return discord.utils.format_dt(parsed_time, style="t")
|
||||
|
||||
def build_info_embed() -> discord.Embed | None:
|
||||
if handlers.current is None:
|
||||
return None
|
||||
|
||||
conn = handlers.current
|
||||
info = handlers.train_info
|
||||
|
||||
if handlers.current is None and handlers.train_info is None:
|
||||
return None
|
||||
|
||||
current_operator = resolve_operator(info["operators"])
|
||||
arrival = format_iso_timestamp(info["arrival"])
|
||||
departure = format_timestamp(conn['departure'])
|
||||
|
||||
+5
-4
@@ -22,7 +22,7 @@ async def rename_vc(bot: discord.Bot):
|
||||
|
||||
attempt = 0
|
||||
while True:
|
||||
if attempt > 3:
|
||||
if attempt == 3:
|
||||
logger("Zu viele Fehlversuche. Füge einen anderen Bahnhof hinzu.")
|
||||
return "Es konnte kein Zug gefunden werden."
|
||||
|
||||
@@ -39,11 +39,12 @@ async def rename_vc(bot: discord.Bot):
|
||||
train = parts[1]
|
||||
train_ID = current['train_number']
|
||||
|
||||
train_info = get_train_info(station=current['station'], train_ID=train_ID, train_type=train_type)
|
||||
station = current['station']
|
||||
train_info = get_train_info(station=station, train_ID=train_ID, train_type=train_type)
|
||||
if train_info and train_info.get('operators') and train_info.get('arrival'):
|
||||
break
|
||||
|
||||
logger(f"Versuch {attempt}: Keine Ankunftszeit für {current['train']} verfügbar, versuche neue Verbindung...")
|
||||
logger(f"Versuch {attempt}: Fehler bei {current['train']} von {station}, versuche neue Verbindung...")
|
||||
|
||||
train_name = f"{train} nach {current['destination']} von {current['station']}"
|
||||
logger(f"Vorbereitung auf {train_name} (typ: {train_type})")
|
||||
@@ -65,7 +66,7 @@ async def _schedule_next_umstieg(bot, arrival):
|
||||
wait_seconds = (arrival - datetime.now()).total_seconds()
|
||||
if wait_seconds > 0:
|
||||
remaining = str(timedelta(seconds=wait_seconds))
|
||||
logger(f"SCHEDULER: Nächster Umstieg in {remaining.split(".")[0]} ({arrival.strftime('%H:%M:%S')} Uhr)")
|
||||
logger(f"Nächster Umstieg in {remaining.split(".")[0]} ({arrival.strftime('%H:%M:%S')} Uhr)")
|
||||
await asyncio.sleep(wait_seconds)
|
||||
logger("Zug angekommen, wähle neue Verbindung...")
|
||||
await rename_vc(bot)
|
||||
+7
-1
@@ -38,6 +38,7 @@ def random_connection():
|
||||
departures = [
|
||||
d for d in data.get("departures", [])
|
||||
if d.get("scheduledDeparture") and d.get("destination") != station
|
||||
and not d.get("train", "").startswith("S ")
|
||||
]
|
||||
|
||||
if not departures:
|
||||
@@ -60,23 +61,28 @@ def random_connection():
|
||||
|
||||
def get_train_info(station, train_ID, train_type):
|
||||
url = f"https://dbf.finalrewind.org/z/{train_type}%20{train_ID}/{station}.json"
|
||||
logger(f"Fetche {url}")
|
||||
try:
|
||||
response = requests.get(url)
|
||||
response.raise_for_status()
|
||||
data = response.json()
|
||||
except requests.RequestException:
|
||||
except requests.RequestException as e:
|
||||
logger(f"ReqestException Fehler: {e}")
|
||||
return None
|
||||
|
||||
dep = data.get("departure", [])
|
||||
if not dep:
|
||||
logger("Kein departure Feld gefunden")
|
||||
return None
|
||||
|
||||
route_post = dep.get("route_post_diff")
|
||||
if not route_post:
|
||||
logger("Kein route_post_diff Feld gefunden")
|
||||
return None
|
||||
|
||||
arrival_iso = route_post[-1].get("sched_arr")
|
||||
if not arrival_iso:
|
||||
logger("Keine Ankunftszeit gefunden")
|
||||
return None
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user