Logging
This commit is contained in:
parent
3417bd248d
commit
551a4abd13
1 changed files with 44 additions and 24 deletions
|
|
@ -10,6 +10,24 @@ from openpyxl import Workbook, load_workbook
|
||||||
import subprocess
|
import subprocess
|
||||||
from shutil import which, copy2
|
from shutil import which, copy2
|
||||||
import platform
|
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
|
# Kalenderwoche bestimmen
|
||||||
|
|
@ -85,7 +103,9 @@ excel_file = (
|
||||||
# --------------------------------------------------
|
# --------------------------------------------------
|
||||||
|
|
||||||
if not source_json.exists():
|
if not source_json.exists():
|
||||||
print(f"Datei nicht gefunden: {source_json}")
|
logging.error(
|
||||||
|
f"Transaktionsdatei nicht gefunden: {source_json}"
|
||||||
|
)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# --------------------------------------------------
|
# --------------------------------------------------
|
||||||
|
|
@ -339,28 +359,28 @@ with open(summary_file, "w", encoding="utf-8") as outfile:
|
||||||
# Ausgabe
|
# Ausgabe
|
||||||
# --------------------------------------------------
|
# --------------------------------------------------
|
||||||
|
|
||||||
print(f"Jahr : {year}")
|
logging.info(f"Jahr : {year}")
|
||||||
print(f"Kalenderwoche : {week}")
|
logging.info(f"Kalenderwoche : {week}")
|
||||||
print(f"Transaktionen : {len(categorized_transactions)}")
|
logging.info(
|
||||||
print()
|
f"Transaktionen : {len(categorized_transactions)}"
|
||||||
|
|
||||||
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"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
print()
|
logging.info("----------------------------------------")
|
||||||
print(f"CSV : {csv_file}")
|
logging.info("Summen pro Kategorie")
|
||||||
print(f"JSON : {json_file}")
|
logging.info("----------------------------------------")
|
||||||
print(f"Summary : {summary_file}")
|
|
||||||
print(f"Excel : {excel_file}")
|
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
|
# Synchronisation
|
||||||
|
|
@ -380,11 +400,11 @@ if which("rclone"):
|
||||||
check=True
|
check=True
|
||||||
)
|
)
|
||||||
|
|
||||||
print("Excel nach Nextcloud synchronisiert.")
|
logging.info("Excel nach Nextcloud synchronisiert.")
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
||||||
print(f"rclone Fehler: {e}")
|
logging.error(f"rclone Fehler: {e}")
|
||||||
|
|
||||||
elif platform.system() == "Windows":
|
elif platform.system() == "Windows":
|
||||||
|
|
||||||
|
|
@ -412,17 +432,17 @@ elif platform.system() == "Windows":
|
||||||
target_file
|
target_file
|
||||||
)
|
)
|
||||||
|
|
||||||
print(
|
logging.info(
|
||||||
f"Excel nach {target_file} kopiert."
|
f"Nextcloud-Synchronisation erfolgreich: {target_file}"
|
||||||
)
|
)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
||||||
print(
|
logging.error(
|
||||||
f"Nextcloud-Kopie fehlgeschlagen: {e}"
|
f"Nextcloud-Kopie fehlgeschlagen: {e}"
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
|
|
||||||
print(
|
logging.warning(
|
||||||
"Keine Synchronisationsmethode gefunden."
|
"Keine Synchronisationsmethode gefunden."
|
||||||
)
|
)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue