This commit is contained in:
hubobel 2026-06-16 17:32:31 +02:00
parent 3417bd248d
commit 551a4abd13

View file

@ -10,6 +10,24 @@ from openpyxl import Workbook, load_workbook
import subprocess
from shutil import which, copy2
import platform
import logging
# --------------------------------------------------
# Logging
# --------------------------------------------------
log_dir = Path.home() / "logs"
log_dir.mkdir(exist_ok=True)
log_file = log_dir / "categorize_transactions.log"
logging.basicConfig(
filename=log_file,
level=logging.INFO,
format="%(asctime)s [%(levelname)s] %(message)s",
)
logging.info("=== Scriptstart ===")
# --------------------------------------------------
# Kalenderwoche bestimmen
@ -85,7 +103,9 @@ excel_file = (
# --------------------------------------------------
if not source_json.exists():
print(f"Datei nicht gefunden: {source_json}")
logging.error(
f"Transaktionsdatei nicht gefunden: {source_json}"
)
sys.exit(1)
# --------------------------------------------------
@ -339,28 +359,28 @@ with open(summary_file, "w", encoding="utf-8") as outfile:
# Ausgabe
# --------------------------------------------------
print(f"Jahr : {year}")
print(f"Kalenderwoche : {week}")
print(f"Transaktionen : {len(categorized_transactions)}")
print()
print("Summen pro Kategorie:")
print()
for category, values in sorted(category_totals.items()):
print(
f"{category:20} "
f"Einnahmen: {values['income']:10.2f} EUR "
f"Ausgaben: {values['expenses']:10.2f} EUR "
f"Saldo: {values['saldo']:10.2f} EUR"
logging.info(f"Jahr : {year}")
logging.info(f"Kalenderwoche : {week}")
logging.info(
f"Transaktionen : {len(categorized_transactions)}"
)
print()
print(f"CSV : {csv_file}")
print(f"JSON : {json_file}")
print(f"Summary : {summary_file}")
print(f"Excel : {excel_file}")
logging.info("----------------------------------------")
logging.info("Summen pro Kategorie")
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}"
)
logging.info(f"CSV : {csv_file}")
logging.info(f"JSON : {json_file}")
logging.info(f"Summary : {summary_file}")
logging.info(f"Excel : {excel_file}")
# --------------------------------------------------
# Synchronisation
@ -380,11 +400,11 @@ if which("rclone"):
check=True
)
print("Excel nach Nextcloud synchronisiert.")
logging.info("Excel nach Nextcloud synchronisiert.")
except Exception as e:
print(f"rclone Fehler: {e}")
logging.error(f"rclone Fehler: {e}")
elif platform.system() == "Windows":
@ -412,17 +432,17 @@ elif platform.system() == "Windows":
target_file
)
print(
f"Excel nach {target_file} kopiert."
logging.info(
f"Nextcloud-Synchronisation erfolgreich: {target_file}"
)
except Exception as e:
print(
logging.error(
f"Nextcloud-Kopie fehlgeschlagen: {e}"
)
else:
print(
logging.warning(
"Keine Synchronisationsmethode gefunden."
)