26 lines
No EOL
750 B
Python
26 lines
No EOL
750 B
Python
import yaml
|
|
import os
|
|
|
|
class Stat:
|
|
def __init__(self, obj):
|
|
self.obj = obj
|
|
|
|
def save_stat(self):
|
|
pfad = "app/cfg/statistic.yaml"
|
|
|
|
# Bestehende Daten laden
|
|
if os.path.exists(pfad):
|
|
with open(pfad, "r", encoding="utf8") as file:
|
|
daten = yaml.safe_load(file) or {}
|
|
else:
|
|
daten = {}
|
|
|
|
# Videosammlung initialisieren, falls nötig
|
|
daten.setdefault("videos", {})
|
|
|
|
# Neuen Eintrag hinzufügen
|
|
daten["videos"].update(self.obj.to_dict_stat())
|
|
|
|
# Datei mit aktualisierten Daten speichern
|
|
with open(pfad, "w", encoding="utf8") as file:
|
|
yaml.dump(daten, file, default_flow_style=False, indent=4, allow_unicode=True) |