From 1628ef198c749ebb2fc2f020360f6a8d5eaf9250 Mon Sep 17 00:00:00 2001 From: hubobel Date: Wed, 24 Jun 2026 16:48:11 +0200 Subject: [PATCH] =?UTF-8?q?log=20f=C3=BCr=20kategorien-Bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.py | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 66 insertions(+), 4 deletions(-) diff --git a/app.py b/app.py index 120e654..fdffb25 100644 --- a/app.py +++ b/app.py @@ -9,6 +9,32 @@ from pathlib import Path from influxdb_client import InfluxDBClient from datetime import datetime, timedelta from collections import defaultdict +from datetime import datetime +import shutil +import logging +import platform +# -------------------------------------------------- +# Logging +# -------------------------------------------------- + +if platform.system() == "Windows": + log_dir = Path(__file__).parent / "logs" +else: + log_dir = Path.home() / "logs" +category_logger = logging.getLogger("categories") +log_dir.mkdir(exist_ok=True) + +log_file = log_dir / "ing.log" + +logging.basicConfig( + filename=log_file, + level=logging.INFO, + format="%(asctime)s [%(levelname)s] %(message)s", +) + +logging.info( + "[app.py] === Scriptstart ===" +) app = Flask(__name__) @@ -557,7 +583,16 @@ def delete_category(category): "w", encoding="utf-8" ) as f: - + if CATEGORIES_FILE.exists(): + shutil.copy2( + CATEGORIES_FILE, + str(CATEGORIES_FILE) + ".bak" + ) + logging.warning( + f"Kategorien werden gespeichert. " + f"Anzahl Kategorien={len(categories)} " + f"Keys={list(categories.keys())}" + ) json.dump( categories, f, @@ -589,7 +624,16 @@ def add_category(): "w", encoding="utf-8" ) as f: - + if CATEGORIES_FILE.exists(): + shutil.copy2( + CATEGORIES_FILE, + str(CATEGORIES_FILE) + ".bak" + ) + logging.warning( + f"Kategorien werden gespeichert. " + f"Anzahl Kategorien={len(categories)} " + f"Keys={list(categories.keys())}" + ) json.dump( categories, f, @@ -645,7 +689,16 @@ def add_word(category): "w", encoding="utf-8" ) as f: - + if CATEGORIES_FILE.exists(): + shutil.copy2( + CATEGORIES_FILE, + str(CATEGORIES_FILE) + ".bak" + ) + logging.warning( + f"Kategorien werden gespeichert. " + f"Anzahl Kategorien={len(categories)} " + f"Keys={list(categories.keys())}" + ) json.dump( categories, f, @@ -679,7 +732,16 @@ def delete_word(category, word): "w", encoding="utf-8" ) as f: - + if CATEGORIES_FILE.exists(): + shutil.copy2( + CATEGORIES_FILE, + str(CATEGORIES_FILE) + ".bak" + ) + logging.warning( + f"Kategorien werden gespeichert. " + f"Anzahl Kategorien={len(categories)} " + f"Keys={list(categories.keys())}" + ) json.dump( categories, f,