Aufgeräumt

This commit is contained in:
hubobel 2026-06-16 19:15:36 +02:00
parent 828cc5dbe1
commit d6e6f01329
2 changed files with 67 additions and 33 deletions

View file

@ -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 ===")
logging.info(
"[categorize] === Scriptende ==="
)

View file

@ -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")
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}"
)