32 lines
No EOL
851 B
Python
Executable file
32 lines
No EOL
851 B
Python
Executable file
import logging
|
|
|
|
import yaml
|
|
import os
|
|
|
|
class Stat:
|
|
def __init__(self):
|
|
self.path = "app/cfg/statistic.yaml"
|
|
|
|
def save_stat(self, obj):
|
|
|
|
daten = self.read_stat()
|
|
|
|
# Neuen Eintrag hinzufügen
|
|
daten["videos"].update(obj.to_dict_stat())
|
|
|
|
# Datei mit aktualisierten Daten speichern
|
|
try:
|
|
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):
|
|
# Bestehende Daten laden
|
|
if os.path.exists(self.path):
|
|
with open(self.path, "r", encoding="utf8") as file:
|
|
daten = yaml.safe_load(file) or {}
|
|
else:
|
|
daten = {}
|
|
|
|
return daten |