From 3ffba5d92a939d161f17f8c87b2b1ca0ea00f5e1 Mon Sep 17 00:00:00 2001 From: data Date: Mon, 28 Apr 2025 13:42:29 +0200 Subject: [PATCH] =?UTF-8?q?Stats=20Docstrings=20und=20Hints=20hinzugef?= =?UTF-8?q?=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/class_media_file_stat.py | 37 ++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/app/class_media_file_stat.py b/app/class_media_file_stat.py index d0e2d55..9e6440b 100755 --- a/app/class_media_file_stat.py +++ b/app/class_media_file_stat.py @@ -1,30 +1,47 @@ import logging +from typing import TYPE_CHECKING import yaml import os +if TYPE_CHECKING: + from app.class_media_file import Media + class Stat: - def __init__(self): + """ + Handles reading and writing video conversion statistics + """ + + def __init__(self) -> None: + """ + Initialize Class with path for statistic file + """ self.path = "app/cfg/statistic.yaml" - def save_stat(self, obj): + def save_stat(self, obj: "Media") -> None: + """ + Saves the statistic in YAML file + :param obj: Media object + :type obj: Media + """ daten = self.read_stat() - # Videosammlung initialisieren, falls nötig - daten.setdefault("videos", {}) - - # Neuen Eintrag hinzufügen - daten["videos"].update(obj.to_dict_stat()) - - # Datei mit aktualisierten Daten speichern try: + # Neuen Eintrag hinzufügen + daten["videos"].update(obj.to_dict_stat()) + with open(self.path, "w", encoding="utf8") as file: yaml.dump(daten, file, default_flow_style=False, indent=4, allow_unicode=True) except Exception as e: logging.error(f"Save Stat Failure: {e}") - def read_stat(self): + def read_stat(self) -> Dict[str, any]: + """ + Read statistic from YAML file + :return: Dictionary width statistics + :rtype: Dict[str, any] + """ # Bestehende Daten laden if os.path.exists(self.path): with open(self.path, "r", encoding="utf8") as file: