mirror of
https://gitlab.com/oeffi/oeffi.git
synced 2025-07-07 17:38:48 +00:00
Edit NetworkProviderFactory.java – Verbesserungen und Fehlerbehebungen in der Datei
This commit is contained in:
parent
798e233fab
commit
0738d88660
1 changed files with 20 additions and 1 deletions
|
@ -1,4 +1,23 @@
|
|||
/*
|
||||
import requests import time from datetime import datetime
|
||||
|
||||
API-Endpunkt für Abfahrtszeiten (aktualisieren mit der echten URL)
|
||||
|
||||
API_URL = "https://api.deinverkehrsverbund.de/abfahrtszeiten"
|
||||
|
||||
def get_abfahrtszeiten(station_id): """Holt die aktuellen Abfahrtszeiten von der API.""" try: response = requests.get(f"{API_URL}/{station_id}", timeout=10) response.raise_for_status() return response.json() except requests.exceptions.Timeout: print("Fehler: Die Anfrage hat zu lange gedauert.") except requests.exceptions.HTTPError as e: print(f"HTTP-Fehler: {e}") except requests.exceptions.RequestException as e: print(f"Netzwerkfehler: {e}") return []
|
||||
|
||||
def update_abfahrtszeiten_periodisch(station_id, interval=10): """Aktualisiert die Abfahrtszeiten in regelmäßigen Abständen.""" while True: print(f"[{datetime.now()}] Aktualisiere Abfahrtszeiten für Station {station_id}...") abfahrten = get_abfahrtszeiten(station_id)
|
||||
|
||||
if abfahrten:
|
||||
print(f"Neue Abfahrtszeiten: {abfahrten}")
|
||||
else:
|
||||
print("Keine Abfahrtszeiten verfügbar.")
|
||||
|
||||
time.sleep(interval * 60) # Wartezeit in Minuten
|
||||
|
||||
if name == "main": station_id = "obstwiesen_id" # Hier mit echter Stations-ID ersetzen update_abfahrtszeiten_periodisch(station_id, interval=10)
|
||||
|
||||
/*
|
||||
* Copyright the original author or authors.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue