Vorbereitungen für .exe Export

This commit is contained in:
hubobel 2025-12-26 18:52:06 +01:00
parent 4a197b73ed
commit e6379bf12f

View file

@ -12,8 +12,11 @@ import shutil
def conf(): def conf():
appname = os.path.basename(sys.argv[0]) appname = os.path.basename(sys.argv[0])
appname = appname.replace(".py", ".conf") appname = appname.replace(".py", ".conf")
absFilePath = os.path.abspath(__file__)
absFilePath = absFilePath.replace(".py", ".conf") absFilePath = os.getcwd()
absFilePath = absFilePath.replace(".exe", ".conf")
print(appname)
print(absFilePath)
if os.path.isfile(absFilePath) is False: if os.path.isfile(absFilePath) is False:
print(appname + ' scheint es nicht zu geben.') print(appname + ' scheint es nicht zu geben.')
@ -40,12 +43,22 @@ def conf():
with open(absFilePath) as file: with open(absFilePath) as file:
passw = json.load(file) passw = json.load(file)
return passw return passw
def get_app_dir():
# Fall: als .exe (z. B. mit PyInstaller gebaut)
if getattr(sys, 'frozen', False):
return Path(sys.executable).parent
# Fall: normales Python-Skript
return Path(__file__).resolve().parent
def resource_path(filename: str) -> Path:
if hasattr(sys, "_MEIPASS"):
return Path(sys._MEIPASS) / filename
return Path(__file__).resolve().parent / filename
def minuten_zu_zeit(minuten) -> str: def minuten_zu_zeit(minuten) -> str:
minuten = int(minuten) minuten = int(minuten)
stunden = minuten // 60 # volle Stunden stunden = minuten // 60 # volle Stunden
rest_min = minuten % 60 # verbleibende Minuten rest_min = minuten % 60 # verbleibende Minuten
return f"{stunden}:{rest_min:02d}" # zweistellige Minutenanzeige return f"{stunden}:{rest_min:02d}" # zweistellige Minutenanzeige
def aircr_name(aircraft_icao): def old_aircr_name(aircraft_icao):
with open("aircraft_full.json", "r", encoding="utf-8") as f: with open("aircraft_full.json", "r", encoding="utf-8") as f:
aircraft_data = json.load(f) aircraft_data = json.load(f)
if aircraft_icao in aircraft_data: if aircraft_icao in aircraft_data:
@ -54,7 +67,17 @@ def aircr_name(aircraft_icao):
print("Code nicht vorhanden") print("Code nicht vorhanden")
antwort = "unbekanntes Luftfahrzeug" antwort = "unbekanntes Luftfahrzeug"
return (antwort) return (antwort)
def start_name(ori_icao): def aircr_name(aircraft_icao: str) -> str:
json_path = resource_path("aircraft_full.json")
with json_path.open("r", encoding="utf-8") as f:
aircraft_data = json.load(f)
if aircraft_icao in aircraft_data:
return aircraft_data[aircraft_icao].get("name", "unbekanntes Luftfahrzeug")
else:
return "unbekanntes Luftfahrzeug"
def old_start_name(ori_icao):
with open("airports_full.json", "r", encoding="utf-8") as f: with open("airports_full.json", "r", encoding="utf-8") as f:
ori_data = json.load(f) ori_data = json.load(f)
@ -64,7 +87,17 @@ def start_name(ori_icao):
print("Code nicht vorhanden") print("Code nicht vorhanden")
antwort = "unbekannter Startflughafen" antwort = "unbekannter Startflughafen"
return (antwort) return (antwort)
def airlinename(name): def start_name(ori_icao: str) -> str:
global _airports_cache
if _airports_cache is None:
with resource_path("airports_full.json").open(encoding="utf-8") as f:
_airports_cache = json.load(f)
return _airports_cache.get(
ori_icao, {}
).get("name", "unbekannter Startflughafen")
def old_airlinename(name):
with open("airlines_full.json", "r", encoding="utf-8") as f: with open("airlines_full.json", "r", encoding="utf-8") as f:
airline_data = json.load(f) airline_data = json.load(f)
if name in airline_data: if name in airline_data:
@ -73,6 +106,19 @@ def airlinename(name):
print("Code nicht vorhanden") print("Code nicht vorhanden")
antwort = "unbekanntes Luftfahrzeug" antwort = "unbekanntes Luftfahrzeug"
return (antwort) return (antwort)
def airlinename(airline_icao: str) -> str:
global _airlines_cache
if _airlines_cache is None:
with resource_path("airlines_full.json").open(encoding="utf-8") as f:
_airlines_cache = json.load(f)
return _airlines_cache.get(
airline_icao, {}
).get(
"name",
"unbekannte Fluggesellschaft"
)
def replacedynamic(message): def replacedynamic(message):
message = message.replace('{AIRCRAFT_NAME}', aircraft_name) message = message.replace('{AIRCRAFT_NAME}', aircraft_name)
message = message.replace('{DESTINATION_NAME}', dest_name) message = message.replace('{DESTINATION_NAME}', dest_name)
@ -270,8 +316,23 @@ def BACKUP(Pfad):
host = os.getcwd() host = os.getcwd()
Pfad = os.getcwd() + '/Announcements/' Pfad = os.getcwd() + '/Announcements/'
_airports_cache = None
_airlines_cache = None
passw = conf()
app_dir = get_app_dir()
conf_file = app_dir / "Simbriefimport.conf"
if conf_file.exists():
print("Konfigurationsdatei gefunden:", conf_file)
with open(conf_file) as file:
passw = json.load(file)
else:
print("Keine Konfigurationsdatei vorhanden:", conf_file)
#passw = conf()
client = OpenAI( client = OpenAI(
api_key=passw['AI']['Token']) api_key=passw['AI']['Token'])