mirror of
https://github.com/kaaninchen/Gleiswechsel.git
synced 2026-07-21 19:52:47 +00:00
Automatisches reload bei neuen Operator metadaten
This commit is contained in:
@@ -13,7 +13,7 @@ db_bawü = {
|
|||||||
OPERATOR_ALIASES = {
|
OPERATOR_ALIASES = {
|
||||||
"DB Regio AG Baden-Württemberg": db_bawü,
|
"DB Regio AG Baden-Württemberg": db_bawü,
|
||||||
"DB Regio Stuttgart GmbH": db_bawü,
|
"DB Regio Stuttgart GmbH": db_bawü,
|
||||||
"DB Fernverkehr": db_allgemein,
|
"DB Fernverkehr AG": db_allgemein,
|
||||||
"DB Regio AG NRW": db_allgemein,
|
"DB Regio AG NRW": db_allgemein,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,5 +34,13 @@ OPERATORS = {
|
|||||||
"eurobahn": {
|
"eurobahn": {
|
||||||
"logo": "https://upload.wikimedia.org/wikipedia/commons/3/34/Digital_Logo_eurobahn.png",
|
"logo": "https://upload.wikimedia.org/wikipedia/commons/3/34/Digital_Logo_eurobahn.png",
|
||||||
"color": 0x005a9b
|
"color": 0x005a9b
|
||||||
|
},
|
||||||
|
"Arverio Bayern": {
|
||||||
|
"logo": "https://cdn.discordapp.com/attachments/1383843132906537023/1528006572805062776/Arverio_Avi_Bayern_blau_RGB.png?ex=6a5cba83&is=6a5b6903&hm=5781ae6c372c92ab4f52409c6fc91e5014ac34ccf24db665ade052e8135bdde0&animated=true", # alternative nötig!
|
||||||
|
"color": 0x0083BE
|
||||||
|
},
|
||||||
|
"Bayerische Regiobahn": {
|
||||||
|
"logo": "https://upload.wikimedia.org/wikipedia/commons/thumb/9/9e/Logo_BRB_2015.svg/1920px-Logo_BRB_2015.svg.png",
|
||||||
|
"color": 0xF61526
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+34
-13
@@ -1,8 +1,27 @@
|
|||||||
import requests
|
import requests
|
||||||
import random
|
import random
|
||||||
|
import os
|
||||||
|
import importlib
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from src.config import config
|
from src.config import config
|
||||||
from src.data.operators import OPERATORS, OPERATOR_ALIASES
|
import src.data.operators as operators_module
|
||||||
|
|
||||||
|
_operators_mtime = None
|
||||||
|
|
||||||
|
def _reload_operators_if_changed():
|
||||||
|
global _operators_mtime
|
||||||
|
|
||||||
|
path = operators_module.__file__
|
||||||
|
current_mtime = os.path.getmtime(path)
|
||||||
|
|
||||||
|
if _operators_mtime is None:
|
||||||
|
_operators_mtime = current_mtime
|
||||||
|
return
|
||||||
|
|
||||||
|
if current_mtime != _operators_mtime:
|
||||||
|
importlib.reload(operators_module)
|
||||||
|
_operators_mtime = current_mtime
|
||||||
|
logger("operators.py wurde automatisch neu geladen (Änderungen erkannt)")
|
||||||
|
|
||||||
def random_connection():
|
def random_connection():
|
||||||
while True:
|
while True:
|
||||||
@@ -36,13 +55,6 @@ def random_connection():
|
|||||||
"train_number": dep['trainNumber']
|
"train_number": dep['trainNumber']
|
||||||
}
|
}
|
||||||
|
|
||||||
def format_via_list(via: list[str]):
|
|
||||||
if not via:
|
|
||||||
return ""
|
|
||||||
if len(via) == 1:
|
|
||||||
return via[0]
|
|
||||||
return ", ".join(via[:-1]) + " und " + via[-1]
|
|
||||||
|
|
||||||
def get_train_info(station, train_ID, train_type):
|
def get_train_info(station, train_ID, train_type):
|
||||||
url = f"https://dbf.finalrewind.org/z/{train_type}%20{train_ID}/{station}.json"
|
url = f"https://dbf.finalrewind.org/z/{train_type}%20{train_ID}/{station}.json"
|
||||||
try:
|
try:
|
||||||
@@ -56,17 +68,26 @@ def get_train_info(station, train_ID, train_type):
|
|||||||
arrival_iso = dep.get("route_post_diff", [])[-1].get("sched_arr")
|
arrival_iso = dep.get("route_post_diff", [])[-1].get("sched_arr")
|
||||||
return {
|
return {
|
||||||
"arrival": arrival_iso,
|
"arrival": arrival_iso,
|
||||||
"operators": dep["operators"]
|
"operators": dep.get("operators")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def format_via_list(via: list[str]):
|
||||||
|
if not via:
|
||||||
|
return ""
|
||||||
|
if len(via) == 1:
|
||||||
|
return via[0]
|
||||||
|
return ", ".join(via[:-1]) + " und " + via[-1]
|
||||||
|
|
||||||
def operator_metadata(operator):
|
def operator_metadata(operator):
|
||||||
|
_reload_operators_if_changed()
|
||||||
|
|
||||||
if not operator:
|
if not operator:
|
||||||
return OPERATORS["fallback"]
|
return operators_module.OPERATORS["fallback"]
|
||||||
|
|
||||||
if operator in OPERATOR_ALIASES:
|
if operator in operators_module.OPERATOR_ALIASES:
|
||||||
return OPERATOR_ALIASES[operator]
|
return operators_module.OPERATOR_ALIASES[operator]
|
||||||
|
|
||||||
return OPERATORS.get(operator, OPERATORS["fallback"])
|
return operators_module.OPERATORS.get(operator, operators_module.OPERATORS["fallback"])
|
||||||
|
|
||||||
def logger(msg):
|
def logger(msg):
|
||||||
current_time = datetime.now().strftime('%X')
|
current_time = datetime.now().strftime('%X')
|
||||||
|
|||||||
Reference in New Issue
Block a user