Compare commits
No commits in common. "3ffba5d92a939d161f17f8c87b2b1ca0ea00f5e1" and "d25fe773537de09f1bf1847ae669ec2567a0c9b5" have entirely different histories.
3ffba5d92a
...
d25fe77353
3 changed files with 10 additions and 27 deletions
|
|
@ -1,47 +1,30 @@
|
||||||
import logging
|
import logging
|
||||||
from typing import TYPE_CHECKING
|
|
||||||
|
|
||||||
import yaml
|
import yaml
|
||||||
import os
|
import os
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
|
||||||
from app.class_media_file import Media
|
|
||||||
|
|
||||||
class Stat:
|
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"
|
self.path = "app/cfg/statistic.yaml"
|
||||||
|
|
||||||
def save_stat(self, obj: "Media") -> None:
|
def save_stat(self, obj):
|
||||||
"""
|
|
||||||
Saves the statistic in YAML file
|
|
||||||
:param obj: Media object
|
|
||||||
:type obj: Media
|
|
||||||
"""
|
|
||||||
|
|
||||||
daten = self.read_stat()
|
daten = self.read_stat()
|
||||||
|
|
||||||
try:
|
# Videosammlung initialisieren, falls nötig
|
||||||
# Neuen Eintrag hinzufügen
|
daten.setdefault("videos", {})
|
||||||
daten["videos"].update(obj.to_dict_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:
|
with open(self.path, "w", encoding="utf8") as file:
|
||||||
yaml.dump(daten, file, default_flow_style=False, indent=4, allow_unicode=True)
|
yaml.dump(daten, file, default_flow_style=False, indent=4, allow_unicode=True)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(f"Save Stat Failure: {e}")
|
logging.error(f"Save Stat Failure: {e}")
|
||||||
|
|
||||||
def read_stat(self) -> Dict[str, any]:
|
def read_stat(self):
|
||||||
"""
|
|
||||||
Read statistic from YAML file
|
|
||||||
:return: Dictionary width statistics
|
|
||||||
:rtype: Dict[str, any]
|
|
||||||
"""
|
|
||||||
# Bestehende Daten laden
|
# Bestehende Daten laden
|
||||||
if os.path.exists(self.path):
|
if os.path.exists(self.path):
|
||||||
with open(self.path, "r", encoding="utf8") as file:
|
with open(self.path, "r", encoding="utf8") as file:
|
||||||
|
|
|
||||||
0
client/icons/close-144.png
Executable file → Normal file
0
client/icons/close-144.png
Executable file → Normal file
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
0
client/icons/stat-100.png
Executable file → Normal file
0
client/icons/stat-100.png
Executable file → Normal file
|
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.7 KiB |
Loading…
Reference in a new issue