mirror of
https://github.com/kaaninchen/Gleiswechsel.git
synced 2026-09-17 16:52:47 +00:00
transitous rewrite: fix params string
This commit is contained in:
@@ -31,7 +31,7 @@ except:
|
||||
'''
|
||||
TODO
|
||||
- 1024 embed limit
|
||||
- Automatic transfer
|
||||
- automatic reload of operators
|
||||
- discord status
|
||||
- text announcements
|
||||
- voice announcements
|
||||
|
||||
@@ -17,10 +17,10 @@ endpoint = "https://api.transitous.org"
|
||||
|
||||
def get_random_stop_id() -> str:
|
||||
assigned_station = random.choice(stations)
|
||||
req = f"{endpoint}/api/v1/geocode?text={assigned_station}"
|
||||
req = f"{endpoint}/api/v1/geocode"
|
||||
|
||||
try:
|
||||
response = requests.get(req, headers=headers)
|
||||
response = requests.get(req, params={"text": assigned_station}, headers=headers)
|
||||
response.raise_for_status()
|
||||
data = response.json()
|
||||
except requests.RequestException as e:
|
||||
@@ -97,10 +97,10 @@ def get_random_connection(stop_id: str) -> str:
|
||||
}
|
||||
|
||||
def get_trip_details(trip_id: str, from_station: str) -> dict:
|
||||
req = f"{endpoint}/api/v2/trip?tripId={trip_id}"
|
||||
req = f"{endpoint}/api/v2/trip"
|
||||
|
||||
try:
|
||||
response = requests.get(req, headers=headers)
|
||||
response = requests.get(req, params={"tripId": trip_id}, headers=headers)
|
||||
response.raise_for_status()
|
||||
data = response.json()
|
||||
except requests.RequestException as e:
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
emoji_list = {
|
||||
"Fallback": "💺",
|
||||
"BUS": "🚎",
|
||||
"COACH": "🚎",
|
||||
"TRAM": "🚈",
|
||||
"REGIONAL_RAIL": "🚊",
|
||||
"HIGHSPEED_RAIL": "🚅",
|
||||
|
||||
@@ -109,10 +109,12 @@ OPERATOR_ALIASES = {
|
||||
"DB Regio AG Bayern": OPERATORS["db_bayern"],
|
||||
"DB Fernverkehr AG": OPERATORS["db_allgemein"],
|
||||
"DB Regio AG NRW": OPERATORS["db_allgemein"],
|
||||
"DB Regio AG Nord": OPERATORS["db_allgemein"],
|
||||
"DB Regio AG Südost": OPERATORS["db_allgemein"],
|
||||
"DB Regio AG Nordost": OPERATORS["db_allgemein"],
|
||||
"DB Regio AG Mitte": OPERATORS["db_allgemein"],
|
||||
"SBB GmbH": OPERATORS["SBB"],
|
||||
"Schweizerische Bundesbahnen SBB": OPERATORS["SBB"],
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
import json
|
||||
import os
|
||||
import importlib
|
||||
from datetime import datetime, timedelta
|
||||
from zoneinfo import ZoneInfo
|
||||
|
||||
import src.data.operators as operators
|
||||
from src.data.emojis import emoji_list
|
||||
|
||||
_operator_mtime = None
|
||||
|
||||
with open("config.json", "r") as file:
|
||||
config = json.load(file)
|
||||
|
||||
@@ -54,7 +57,25 @@ def get_train_name(train_name: str, mode: str) -> str:
|
||||
|
||||
return train
|
||||
|
||||
def _reload_operators_if_changed():
|
||||
global _operator_mtime
|
||||
|
||||
path = operators.__file__
|
||||
current_mtime = os.path.getmtime(path)
|
||||
|
||||
if _operator_mtime is None:
|
||||
_operator_mtime = current_mtime
|
||||
return
|
||||
|
||||
if current_mtime != _operator_mtime:
|
||||
importlib.reload(operators)
|
||||
_operator_mtime = current_mtime
|
||||
logger("operators.py wurde automatisch neu geladen (Änderungen erkannt)")
|
||||
|
||||
|
||||
def get_operator_metadata(agency: str, route_color: str) -> dict:
|
||||
_reload_operators_if_changed()
|
||||
|
||||
op_data = operators.OPERATOR_ALIASES.get(agency) or operators.OPERATORS.get(agency) or operators.OPERATORS["fallback"]
|
||||
|
||||
logo = op_data.get("logo", operators.OPERATORS["fallback"]["logo"])
|
||||
|
||||
Reference in New Issue
Block a user