diff --git a/gui.py b/gui.py index 4fe5e862..d8070f03 100644 --- a/gui.py +++ b/gui.py @@ -53,7 +53,7 @@ def __init__(self, pfad_fenster_layout: str = os.path.join(PATH, "tools/gui/main super().__init__() - create_missing_dirs() + create_missing_dirs(PATH) # Laden der .ui Datei und Anpassungen uic.loadUi(pfad_fenster_layout, self) diff --git a/main.py b/main.py index 5d362de6..dd457bc9 100755 --- a/main.py +++ b/main.py @@ -365,7 +365,7 @@ def validate_args(args): def main(): - create_missing_dirs() + create_missing_dirs(PATH) parser = argparse.ArgumentParser() subparsers = parser.add_subparsers(help="commands", dest="command") diff --git a/tools/utils.py b/tools/utils.py index 5734b400..529bb695 100644 --- a/tools/utils.py +++ b/tools/utils.py @@ -1,14 +1,16 @@ +import os import time import traceback -import requests +from json import JSONDecodeError from pathlib import Path - from threading import Thread + +import requests from plyer import notification -from tools.exceptions import DesktopNotificationError -from json import JSONDecodeError from requests.exceptions import ReadTimeout, ConnectionError, ConnectTimeout +from tools.exceptions import DesktopNotificationError + def retry_on_failure(retries=10): """Decorator zum Errorhandling beim Ausführen einer Methode im Loop. @@ -85,33 +87,34 @@ def remove_prefix(text, prefix): return text -def desktop_notification(operating_system:str, title: str, message: str): - """ - Starts a thread and creates a desktop notification using plyer.notification - """ - - if 'windows' not in operating_system: - return - - try: - Thread(target=notification.notify( - app_name="Impfterminservice", - title=title, - message=message) - ).start() - except Exception as exc: - raise DesktopNotificationError( - "Error in _desktop_notification: " + str(exc.__class__.__name__) - + traceback.format_exc() - ) from exc - -def create_missing_dirs(): +def desktop_notification(operating_system: str, title: str, message: str): + """ + Starts a thread and creates a desktop notification using plyer.notification + """ + + if 'windows' not in operating_system: + return + + try: + Thread(target=notification.notify( + app_name="Impfterminservice", + title=title, + message=message) + ).start() + except Exception as exc: + raise DesktopNotificationError( + "Error in _desktop_notification: " + str(exc.__class__.__name__) + + traceback.format_exc() + ) from exc + + +def create_missing_dirs(base_path): """ Erstellt benötigte Ordner, falls sie fehlen: - ./data """ - Path("./data").mkdir(parents=True, exist_ok=True) + Path(os.path.join(base_path, "data")).mkdir(parents=True, exist_ok=True) def get_grouped_impfzentren() -> dict: