From d6e6f013290c188f661c7b80330d428fbf8d6139 Mon Sep 17 00:00:00 2001 From: hubobel Date: Tue, 16 Jun 2026 19:15:36 +0200 Subject: [PATCH] =?UTF-8?q?Aufger=C3=A4umt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- categorize_transactions.py | 44 ++++++++++++++++-------------- transactions.py | 56 +++++++++++++++++++++++++++++--------- 2 files changed, 67 insertions(+), 33 deletions(-) diff --git a/categorize_transactions.py b/categorize_transactions.py index 76cbf64..295b3bb 100644 --- a/categorize_transactions.py +++ b/categorize_transactions.py @@ -24,7 +24,7 @@ else: log_dir.mkdir(exist_ok=True) -log_file = log_dir / "categorize_transactions.log" +log_file = log_dir / "ing.log" logging.basicConfig( filename=log_file, @@ -32,7 +32,9 @@ logging.basicConfig( format="%(asctime)s [%(levelname)s] %(message)s", ) -logging.info("=== Scriptstart ===") +logging.info( + "[categorize] === Scriptstart ===" +) # -------------------------------------------------- # Kalenderwoche bestimmen @@ -109,7 +111,7 @@ excel_file = ( if not source_json.exists(): logging.error( - f"Transaktionsdatei nicht gefunden: {source_json}" + f"[categorize] Transaktionsdatei nicht gefunden: {source_json}" ) sys.exit(1) @@ -462,10 +464,10 @@ with open(summary_file, "w", encoding="utf-8") as outfile: # Ausgabe # -------------------------------------------------- -logging.info(f"Jahr : {year}") -logging.info(f"Kalenderwoche : {week}") +logging.info(f"[categorize] Jahr : {year}") +logging.info(f"[categorize] Kalenderwoche : {week}") logging.info( - f"Transaktionen : {len(categorized_transactions)}" + f"[categorize] Transaktionen : {len(categorized_transactions)}" ) logging.info("----------------------------------------") @@ -474,16 +476,16 @@ logging.info("----------------------------------------") for category, values in sorted(category_totals.items()): logging.info( - f"Kategorie={category}; " - f"Einnahmen={values['income']:.2f}; " - f"Ausgaben={values['expenses']:.2f}; " - f"Saldo={values['saldo']:.2f}" + f"[categorize] Kategorie={category}; " + f"[categorize] Einnahmen={values['income']:.2f}; " + f"[categorize] Ausgaben={values['expenses']:.2f}; " + f"[categorize] Saldo={values['saldo']:.2f}" ) -logging.info(f"CSV : {csv_file}") -logging.info(f"JSON : {json_file}") -logging.info(f"Summary : {summary_file}") -logging.info(f"Excel : {excel_file}") +logging.info(f"[categorize] CSV : {csv_file}") +logging.info(f"[categorize] JSON : {json_file}") +logging.info(f"[categorize] Summary : {summary_file}") +logging.info(f"[categorize] Excel : {excel_file}") # -------------------------------------------------- # Synchronisation @@ -503,11 +505,11 @@ if which("rclone"): check=True ) - logging.info("Excel nach Nextcloud synchronisiert.") + logging.info("[categorize] Excel nach Nextcloud synchronisiert.") except Exception as e: - logging.error(f"rclone Fehler: {e}") + logging.error(f"[categorize] rclone Fehler: {e}") elif platform.system() == "Windows": @@ -536,18 +538,20 @@ elif platform.system() == "Windows": ) logging.info( - f"Nextcloud-Synchronisation erfolgreich: {target_file}" + f"[categorize] Nextcloud-Synchronisation erfolgreich: {target_file}" ) except Exception as e: logging.error( - f"Nextcloud-Kopie fehlgeschlagen: {e}" + f"[categorize] Nextcloud-Kopie fehlgeschlagen: {e}" ) else: logging.warning( - "Keine Synchronisationsmethode gefunden." + "[categorize] Keine Synchronisationsmethode gefunden." ) -logging.info("=== Scriptende ===") \ No newline at end of file +logging.info( + "[categorize] === Scriptende ===" +) \ No newline at end of file diff --git a/transactions.py b/transactions.py index 204811e..dac70ef 100644 --- a/transactions.py +++ b/transactions.py @@ -7,6 +7,27 @@ from fints.client import FinTS3PinTanClient import csv import json import sys +import logging +import platform +from pathlib import Path + +if platform.system() == "Windows": + log_dir = Path(__file__).parent / "logs" +else: + log_dir = Path.home() / "logs" + +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", + force=True +) + +logging.info("[transactions] === Scriptstart ===") # -------------------------------------------------- # Konfiguration laden @@ -95,10 +116,10 @@ if end_date > today: end_date = today if start_date > today: - - print( - "Die angeforderte Kalenderwoche liegt " - "vollständig in der Zukunft." + logging.error( + "[transactions] Die angeforderte " + "Kalenderwoche liegt vollständig " + "in der Zukunft." ) sys.exit(1) @@ -148,12 +169,12 @@ with client: end_date=end_date ) - print( - f"Lade Transaktionen für KW{week:02d}/{year}" + logging.info( + f"[transactions] Lade Transaktionen für KW{week:02d}/{year}" ) - print( - f"Zeitraum: {start_date} bis {end_date}" + logging.info( + f"[transactions] Zeitraum: {start_date} bis {end_date}" ) for transaction in transactions: @@ -258,8 +279,17 @@ urlopen( # Erfolgsmeldung # -------------------------------------------------- -print(f"CSV erstellt : {CSV_FILE}") -print(f"JSON erstellt: {JSON_FILE}") -print(f"Transaktionen: {transaction_count}") -print(f"Wochensumme : {week_sum:.2f} EUR") -print(f"Ausgaben : {week_expenses:.2f} EUR") \ No newline at end of file +logging.info( + f"[transactions] Export abgeschlossen | " + f"Transaktionen={transaction_count} | " + f"Wochensumme={week_sum:.2f} EUR | " + f"Ausgaben={week_expenses:.2f} EUR" +) + +logging.info( + f"[transactions] CSV={CSV_FILE}" +) + +logging.info( + f"[transactions] JSON={JSON_FILE}" +) \ No newline at end of file