mirror of
https://github.com/kaaninchen/Gleiswechsel.git
synced 2026-07-21 19:52:47 +00:00
Zeitschleife anhand von Echtzeit Ankunftsuhrzeit hinzugefügt
Ein recht großer commit. Mit dabei ist ein logger, erweiterte Informationen zu den Zügen und eine Zeitschleife, welche sich anhand der echtzeit ankunftsdaten des Zuges richtet. Der Commit benötigt auf jeden fall testing
This commit is contained in:
+25
-2
@@ -1,5 +1,6 @@
|
||||
import requests
|
||||
import random
|
||||
from datetime import datetime
|
||||
from src.config import config
|
||||
from src.data.operators import OPERATORS
|
||||
|
||||
@@ -30,7 +31,8 @@ def random_connection():
|
||||
"route": dep['route'],
|
||||
"departure": dep['scheduledDeparture'],
|
||||
"via": dep['via'],
|
||||
"station": station
|
||||
"station": station,
|
||||
"train_number": dep['trainNumber']
|
||||
}
|
||||
|
||||
|
||||
@@ -46,4 +48,25 @@ def format_via_list(via: list[str]):
|
||||
return ""
|
||||
if len(via) == 1:
|
||||
return via[0]
|
||||
return ", ".join(via[:-1]) + " und " + via[-1]
|
||||
return ", ".join(via[:-1]) + " und " + via[-1]
|
||||
|
||||
def get_train_info(station, train_ID, train_type):
|
||||
url = f"https://dbf.finalrewind.org/z/{train_type}%20{train_ID}/{station}.json"
|
||||
|
||||
try:
|
||||
response = requests.get(url)
|
||||
response.raise_for_status()
|
||||
data = response.json()
|
||||
except requests.RequestException:
|
||||
return None
|
||||
|
||||
dep = data.get("departure", [])
|
||||
arrival_iso = dep["route_post_diff"][-1]["sched_arr"]
|
||||
return {
|
||||
"arrival": arrival_iso,
|
||||
"operators": dep["operators"]
|
||||
}
|
||||
|
||||
def logger(msg):
|
||||
current_time = datetime.now().strftime('%X')
|
||||
print(f"{current_time}: {msg}")
|
||||
Reference in New Issue
Block a user