mirror of
https://github.com/kaaninchen/Gleiswechsel.git
synced 2026-09-17 16:52:47 +00:00
transitous rewrite: improved via
This commit is contained in:
+18
-3
@@ -234,21 +234,36 @@ def get_trip_details(random_connection: dict | None) -> dict | None:
|
|||||||
"stops": {}
|
"stops": {}
|
||||||
}
|
}
|
||||||
|
|
||||||
trip_details["stops"][train_from] = departure_dt
|
train_from_importance = legs["from"]["importance"]
|
||||||
|
trip_details["stops"][train_from] = {
|
||||||
|
"arrival": departure_dt,
|
||||||
|
"importance": train_from_importance
|
||||||
|
}
|
||||||
|
|
||||||
departure_time_iso = start_time
|
departure_time_iso = start_time
|
||||||
|
|
||||||
for stop in legs["intermediateStops"]:
|
for stop in legs["intermediateStops"]:
|
||||||
stop_arrival_dt = parse_iso(stop["arrival"])
|
stop_arrival_dt = parse_iso(stop["arrival"])
|
||||||
trip_details["stops"][stop["name"]] = stop_arrival_dt
|
stop_importance = stop["importance"]
|
||||||
|
stop_details = {
|
||||||
|
"arrival": stop_arrival_dt,
|
||||||
|
"importance": stop_importance
|
||||||
|
}
|
||||||
|
trip_details["stops"][stop["name"]] = stop_details
|
||||||
if stop.get("name") == from_station:
|
if stop.get("name") == from_station:
|
||||||
departure_time_iso = stop["departure"]
|
departure_time_iso = stop["departure"]
|
||||||
trip_details["departure"] = parse_iso(departure_time_iso).strftime("%H:%M")
|
trip_details["departure"] = parse_iso(departure_time_iso).strftime("%H:%M")
|
||||||
|
|
||||||
trip_details["stops"][goes_to] = arrival_dt
|
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)
|
valid = validate_connection(start_time, end_time, departure_time_iso)
|
||||||
if not valid:
|
if not valid:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
logger(json.dumps(trip_details, indent=4, ensure_ascii=False, default=str))
|
||||||
return trip_details
|
return trip_details
|
||||||
|
|
||||||
|
|||||||
@@ -106,6 +106,10 @@ OPERATORS = {
|
|||||||
"Vr": {
|
"Vr": {
|
||||||
"logo": "https://upload.wikimedia.org/wikipedia/commons/thumb/1/18/Vr_Logo.png/330px-Vr_Logo.png",
|
"logo": "https://upload.wikimedia.org/wikipedia/commons/thumb/1/18/Vr_Logo.png/330px-Vr_Logo.png",
|
||||||
"color": 0x00B451
|
"color": 0x00B451
|
||||||
|
},
|
||||||
|
"GVB": {
|
||||||
|
"logo": "https://upload.wikimedia.org/wikipedia/commons/thumb/a/a3/GVB_Amsterdam_Logo_001.svg/1280px-GVB_Amsterdam_Logo_001.svg.png",
|
||||||
|
"color": 0x2B62AF
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ def build_embed_footer(mode: str, slogans):
|
|||||||
"icon": icon
|
"icon": icon
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def build_info_embed() -> discord.Embed:
|
def build_info_embed() -> discord.Embed:
|
||||||
from src.dc.handlers import trip
|
from src.dc.handlers import trip
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ async def rename_vc(bot: discord.Bot, voice_channel, from_scheduler: bool = Fals
|
|||||||
trip = choose_connection()
|
trip = choose_connection()
|
||||||
while trip is None and attempt < max_attempt:
|
while trip is None and attempt < max_attempt:
|
||||||
attempt += 1
|
attempt += 1
|
||||||
logger(f"Attempt {attempt}: Failed to select route, retrying...", "error")
|
|
||||||
trip = choose_connection()
|
trip = choose_connection()
|
||||||
|
|
||||||
if trip is None:
|
if trip is None:
|
||||||
|
|||||||
+28
-5
@@ -150,7 +150,8 @@ 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)
|
||||||
for name, arrival_dt in stops.items():
|
for name, info in stops.items():
|
||||||
|
arrival_dt = info["arrival"]
|
||||||
if arrival_dt >= now:
|
if arrival_dt >= now:
|
||||||
if name == train_from:
|
if name == train_from:
|
||||||
return None
|
return None
|
||||||
@@ -164,20 +165,42 @@ def get_next_station(stops: dict, train_from :str) -> dict | None:
|
|||||||
|
|
||||||
def format_via_list(stops: dict) -> str:
|
def format_via_list(stops: dict) -> str:
|
||||||
if len(stops) > 2:
|
if len(stops) > 2:
|
||||||
count = min(3, len(stops))
|
stations = list(stops.keys())
|
||||||
random_stops = random.sample(list(stops), k=count)
|
trip_from = stations[0]
|
||||||
via = f"{', '.join(random_stops[:-1])} und {random_stops[-1]}"
|
trip_to = stations[-1]
|
||||||
|
|
||||||
|
important_stops = sort_stations_by_importance(stops)[:3]
|
||||||
|
if trip_from in important_stops:
|
||||||
|
important_stops.remove(trip_from)
|
||||||
|
if trip_to in important_stops:
|
||||||
|
important_stops.remove(trip_to)
|
||||||
|
|
||||||
|
via = f"{', '.join(important_stops[:-1])} und {important_stops[-1]}"
|
||||||
return via
|
return via
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def sort_stations_by_importance(stops: dict) -> list:
|
||||||
|
sorted_stations_dict = dict(
|
||||||
|
sorted(
|
||||||
|
[(name, info["importance"]) for name, info in stops.items()],
|
||||||
|
key=lambda x: x[1],
|
||||||
|
reverse=True)
|
||||||
|
)
|
||||||
|
|
||||||
|
sorted_stations = list(sorted_stations_dict.keys())
|
||||||
|
return sorted_stations
|
||||||
|
|
||||||
def format_stop_list(stops: dict, next_stop: str | None) -> list[tuple[str, str]]:
|
def format_stop_list(stops: dict, next_stop: str | None) -> list[tuple[str, str]]:
|
||||||
fields = []
|
fields = []
|
||||||
field_lines, field_length, part = [], 0, 1
|
field_lines, field_length, part = [], 0, 1
|
||||||
|
|
||||||
for name, stop_arrival in stops.items():
|
for name, info in stops.items():
|
||||||
if name == next_stop:
|
if name == next_stop:
|
||||||
|
stop_arrival = info["arrival"]
|
||||||
|
print(stop_arrival)
|
||||||
line = f"• __{name}__ ({stop_arrival.strftime("%H:%M")} Uhr)"
|
line = f"• __{name}__ ({stop_arrival.strftime("%H:%M")} Uhr)"
|
||||||
else:
|
else:
|
||||||
|
stop_arrival = info["arrival"]
|
||||||
line = f"• {name} ({stop_arrival.strftime("%H:%M")} Uhr)"
|
line = f"• {name} ({stop_arrival.strftime("%H:%M")} Uhr)"
|
||||||
|
|
||||||
if field_length + len(line) + 1 > 1024:
|
if field_length + len(line) + 1 > 1024:
|
||||||
|
|||||||
Reference in New Issue
Block a user