diff --git a/src/api/transitous.py b/src/api/transitous.py index b84247d..a27e525 100644 --- a/src/api/transitous.py +++ b/src/api/transitous.py @@ -110,6 +110,7 @@ def get_random_stop_id() -> str | None: if stop_name == assigned_station: stop_ids.clear() + logger(f"Exact match found! Using {stop_name}") stop_ids[stop_id] = stop_name break @@ -118,11 +119,11 @@ def get_random_stop_id() -> str | None: return None stop_ids_list = list(stop_ids.keys()) - stops_string = ", ".join(stop_ids.values()) if len(stop_ids_list) > 1: logger(f"No station associated as '{assigned_station}', choosing random from similar named station") logger(f"Run `python run main.py stations` to get exact station names") - chosen_stop_id = random.choice(stop_ids_list) + chosen_stop_id, chosen_station = random.choice(list(stop_ids.items())) + logger(f"Assigned Station: {chosen_station}") return chosen_stop_id def get_random_connection(stop_id: str) -> str | None: @@ -199,6 +200,7 @@ def get_trip_details(random_connection: dict | None) -> dict | None: except requests.RequestException as e: logger(f"An error occured while trying to get the route details: {e}", "error") return None + legs = data["legs"][0] end_time = legs["endTime"] @@ -254,12 +256,6 @@ def get_trip_details(random_connection: dict | None) -> dict | None: departure_time_iso = stop["departure"] trip_details["departure"] = parse_iso(departure_time_iso).strftime("%H:%M") - train_to_importance = legs["to"]["importance"] - trip_details["stops"][goes_to] = { - "arrival": arrival_dt, - "importance": train_to_importance - } - valid = validate_connection(start_time, end_time, departure_time_iso) if not valid: return None diff --git a/src/data/operators.py b/src/data/operators.py index bf927dd..dec5cfe 100644 --- a/src/data/operators.py +++ b/src/data/operators.py @@ -114,7 +114,7 @@ OPERATORS = { } OPERATOR_ALIASES = { - "Arverio BAyern GmbH": OPERATORS["Arverio Bayern"], + "Arverio Bayern GmbH": OPERATORS["Arverio Bayern"], "DB Regio AG Baden-Württemberg": OPERATORS["db_bawü"], "DB Regio Stuttgart GmbH": OPERATORS["db_bawü"], "Arverio Baden-Württemberg": OPERATORS["db_bawü"], diff --git a/src/dc/handlers.py b/src/dc/handlers.py index 3717aa0..40c69fd 100644 --- a/src/dc/handlers.py +++ b/src/dc/handlers.py @@ -92,7 +92,6 @@ async def voice_announcer(destination: str, voice_channel: discord.VoiceChannel) vc.play(audio_source, after=after_playing) return True - async def _schedule_next_transfer(bot: discord.Bot, arrival_dt: datetime, voice_channel: discord.VoiceChannel, destination: str): now = datetime.now(LOCAL_TZ) diff --git a/src/utils.py b/src/utils.py index 2fd5f37..000cbe0 100644 --- a/src/utils.py +++ b/src/utils.py @@ -27,8 +27,9 @@ def choose_connection() -> dict | None: return trip -def validate_connection(start_time: str, end_time: str, station_departure: str) -> bool: +def validate_connection(start_time: str, end_time: str, departure_time_iso: str) -> bool: now = datetime.now(timezone.utc) + start_dt = datetime.fromisoformat(start_time.replace("Z", "+00:00")) end_dt = datetime.fromisoformat(end_time.replace("Z", "+00:00")) if end_dt < now: @@ -36,13 +37,12 @@ def validate_connection(start_time: str, end_time: str, station_departure: str) return False max_wait_time = config.connections.max_wait_time - start_dt = datetime.fromisoformat(start_time.replace("Z", "+00:00")) if start_dt > now + timedelta(hours=max_wait_time): logger(f"Verbindung liegt zu weit in der Zukunft: {start_dt}", "error") return False - station_departure_dt = datetime.fromisoformat(station_departure.replace("Z", "+00:00")) - trip_duration = (end_dt - station_departure_dt).total_seconds() + departure_time_iso_dt = datetime.fromisoformat(departure_time_iso.replace("Z", "+00:00")) + trip_duration = (end_dt - departure_time_iso_dt).total_seconds() trip_duration_minutes = str(timedelta(seconds=trip_duration)) min_duration = config.connections.min_duration