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:
+20
-5
@@ -232,23 +232,38 @@ def get_trip_details(random_connection: dict | None) -> dict | None:
|
||||
"arrival_dt": arrival_dt,
|
||||
"mode": mode,
|
||||
"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
|
||||
|
||||
for stop in legs["intermediateStops"]:
|
||||
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:
|
||||
departure_time_iso = stop["departure"]
|
||||
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)
|
||||
if not valid:
|
||||
return None
|
||||
|
||||
|
||||
logger(json.dumps(trip_details, indent=4, ensure_ascii=False, default=str))
|
||||
return trip_details
|
||||
|
||||
|
||||
@@ -106,6 +106,10 @@ OPERATORS = {
|
||||
"Vr": {
|
||||
"logo": "https://upload.wikimedia.org/wikipedia/commons/thumb/1/18/Vr_Logo.png/330px-Vr_Logo.png",
|
||||
"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
|
||||
}
|
||||
|
||||
|
||||
def build_info_embed() -> discord.Embed:
|
||||
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()
|
||||
while trip is None and attempt < max_attempt:
|
||||
attempt += 1
|
||||
logger(f"Attempt {attempt}: Failed to select route, retrying...", "error")
|
||||
trip = choose_connection()
|
||||
|
||||
if trip is None:
|
||||
|
||||
+29
-6
@@ -150,7 +150,8 @@ def get_sound_path(destination) -> str | None:
|
||||
|
||||
def get_next_station(stops: dict, train_from :str) -> dict | None:
|
||||
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 name == train_from:
|
||||
return None
|
||||
@@ -164,20 +165,42 @@ def get_next_station(stops: dict, train_from :str) -> dict | None:
|
||||
|
||||
def format_via_list(stops: dict) -> str:
|
||||
if len(stops) > 2:
|
||||
count = min(3, len(stops))
|
||||
random_stops = random.sample(list(stops), k=count)
|
||||
via = f"{', '.join(random_stops[:-1])} und {random_stops[-1]}"
|
||||
stations = list(stops.keys())
|
||||
trip_from = stations[0]
|
||||
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 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]]:
|
||||
fields = []
|
||||
field_lines, field_length, part = [], 0, 1
|
||||
|
||||
for name, stop_arrival in stops.items():
|
||||
for name, info in stops.items():
|
||||
if name == next_stop:
|
||||
stop_arrival = info["arrival"]
|
||||
print(stop_arrival)
|
||||
line = f"• __{name}__ ({stop_arrival.strftime("%H:%M")} Uhr)"
|
||||
else:
|
||||
stop_arrival = info["arrival"]
|
||||
line = f"• {name} ({stop_arrival.strftime("%H:%M")} Uhr)"
|
||||
|
||||
if field_length + len(line) + 1 > 1024:
|
||||
@@ -192,4 +215,4 @@ def format_stop_list(stops: dict, next_stop: str | None) -> list[tuple[str, str]
|
||||
route_page_name = "Route" if part == 1 else "Route (Fortsetzung)"
|
||||
fields.append((route_page_name, "\n".join(field_lines)))
|
||||
|
||||
return fields
|
||||
return fields
|
||||
|
||||
Reference in New Issue
Block a user