mirror of
https://github.com/kaaninchen/Gleiswechsel.git
synced 2026-09-17 16:52:47 +00:00
transitous rewrite: fix color from API
This commit is contained in:
+9
-10
@@ -17,7 +17,6 @@ endpoint = "https://api.transitous.org"
|
||||
|
||||
def get_random_stop_id() -> str | None:
|
||||
assigned_station = random.choice(stations)
|
||||
logger(f"Station: {assigned_station}")
|
||||
req = f"{endpoint}/api/v1/geocode"
|
||||
|
||||
try:
|
||||
@@ -50,7 +49,6 @@ def get_random_connection(stop_id: str) -> str | None:
|
||||
return None
|
||||
|
||||
now = datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")
|
||||
print(f"Aktuelle Zeit für Query: {now}")
|
||||
cursor = None
|
||||
max_pages = 5
|
||||
min_results = 5
|
||||
@@ -82,7 +80,6 @@ def get_random_connection(stop_id: str) -> str | None:
|
||||
if entry["mode"] in blacklist:
|
||||
continue
|
||||
else:
|
||||
print(entry["mode"])
|
||||
trip_ids.append(entry["tripId"])
|
||||
|
||||
if len(trip_ids) >= min_results:
|
||||
@@ -104,6 +101,7 @@ def get_random_connection(stop_id: str) -> str | None:
|
||||
from_station = entry.get("place", {}).get("name")
|
||||
break
|
||||
|
||||
logger(f"Station: {from_station}")
|
||||
return {
|
||||
"trip_id": trip_id,
|
||||
"from_station": from_station
|
||||
@@ -127,7 +125,7 @@ def get_trip_details(random_connection: dict | None) -> dict | None:
|
||||
end_time = legs["endTime"]
|
||||
from_station = random_connection["from_station"]
|
||||
display_name = legs["displayName"]
|
||||
trip_from = legs["from"]["name"]
|
||||
train_from = legs["from"]["name"]
|
||||
goes_to = legs["to"]["name"]
|
||||
start_time = legs["startTime"]
|
||||
mode = legs["mode"]
|
||||
@@ -140,15 +138,16 @@ def get_trip_details(random_connection: dict | None) -> dict | None:
|
||||
departure = convert_iso_string(start_time)
|
||||
|
||||
train_name = get_train_name(display_name, mode)
|
||||
if trip_from == from_station:
|
||||
long_name = f"{train_name} nach {goes_to} von {trip_from}"
|
||||
if train_from == from_station:
|
||||
long_name = f"{train_name} nach {goes_to} von {train_from}"
|
||||
else:
|
||||
long_name = f"{train_name} nach {goes_to} von {trip_from}, über {from_station}"
|
||||
long_name = f"{train_name} nach {goes_to} über {from_station}"
|
||||
|
||||
trip_details = {
|
||||
"long_name": long_name,
|
||||
"short_name": display_name,
|
||||
"from": from_station,
|
||||
"station": from_station,
|
||||
"from": train_from,
|
||||
"to": goes_to,
|
||||
"agency": legs["agencyName"],
|
||||
"route_color": legs.get("routeColor"),
|
||||
@@ -159,8 +158,8 @@ def get_trip_details(random_connection: dict | None) -> dict | None:
|
||||
"stops": {}
|
||||
}
|
||||
|
||||
trip_details["stops"][trip_from] = departure
|
||||
print(trip_from)
|
||||
trip_details["stops"][train_from] = departure
|
||||
|
||||
for stop in legs["intermediateStops"]:
|
||||
stop_arrival = convert_iso_string(stop["arrival"])
|
||||
trip_details["stops"][stop["name"]] = stop_arrival
|
||||
|
||||
+2
-2
@@ -27,13 +27,13 @@ def build_info_embed() -> discord.Embed:
|
||||
arrival = format_timestamp_to_dc(trip["arrival"])
|
||||
embed = discord.Embed(
|
||||
title = trip["long_name"],
|
||||
description=f"Abfahrt von {trip["from"]} um {departure}. Ankunft um {arrival}",
|
||||
description=f"Abfahrt von {trip["station"]} um {departure}. Ankunft um {arrival}",
|
||||
color = metadata["color"]
|
||||
)
|
||||
|
||||
route_lines = []
|
||||
for stop_name, stop_arrival in trip["stops"].items():
|
||||
if stop_name == trip["from"]:
|
||||
if stop_name == trip["station"]:
|
||||
route_lines.append(f"**• {stop_name} ({stop_arrival} Uhr)**")
|
||||
else:
|
||||
route_lines.append(f"• {stop_name} ({stop_arrival} Uhr)")
|
||||
|
||||
+3
-3
@@ -30,7 +30,6 @@ def choose_connection() -> dict | None:
|
||||
def validate_connection(start_time: str, end_time: str) -> bool:
|
||||
now = datetime.now(timezone.utc)
|
||||
start_dt = datetime.fromisoformat(start_time.replace("Z", "+00:00"))
|
||||
print(start_dt)
|
||||
end_dt = datetime.fromisoformat(end_time.replace("Z", "+00:00"))
|
||||
max_wait_time = config.get("max_wait_time", 6)
|
||||
|
||||
@@ -98,14 +97,15 @@ def get_operator_metadata(agency: str, route_color: str) -> dict:
|
||||
slogans = op_data.get("slogan")
|
||||
|
||||
color = op_data.get("color")
|
||||
if color is None:
|
||||
if color is None or color == 0xFFFFFF:
|
||||
if route_color is not None:
|
||||
try:
|
||||
color = int(route_color, 16)
|
||||
print(color)
|
||||
except ValueError:
|
||||
color = operators.OPERATORS["fallback"]["color"]
|
||||
else:
|
||||
logger(f"Managed to get color from API: {color}")
|
||||
logger(f"Managed to get color from API, edit src/data/operators.py if you don't like it")
|
||||
else:
|
||||
color = operators.OPERATORS["fallback"]["color"]
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user