Excelexport hinzugefügt
This commit is contained in:
parent
bcffd156a2
commit
d0735c540e
1 changed files with 57 additions and 1 deletions
|
|
@ -5,6 +5,7 @@ from datetime import datetime
|
||||||
import json
|
import json
|
||||||
import csv
|
import csv
|
||||||
import sys
|
import sys
|
||||||
|
from openpyxl import Workbook
|
||||||
|
|
||||||
# --------------------------------------------------
|
# --------------------------------------------------
|
||||||
# Kalenderwoche bestimmen
|
# Kalenderwoche bestimmen
|
||||||
|
|
@ -48,10 +49,12 @@ source_json = (
|
||||||
categorized_csv_dir = year_dir / "categorized_csv"
|
categorized_csv_dir = year_dir / "categorized_csv"
|
||||||
categorized_json_dir = year_dir / "categorized_json"
|
categorized_json_dir = year_dir / "categorized_json"
|
||||||
summary_dir = year_dir / "summary"
|
summary_dir = year_dir / "summary"
|
||||||
|
excel_dir = year_dir / "excel"
|
||||||
|
|
||||||
categorized_csv_dir.mkdir(parents=True, exist_ok=True)
|
categorized_csv_dir.mkdir(parents=True, exist_ok=True)
|
||||||
categorized_json_dir.mkdir(parents=True, exist_ok=True)
|
categorized_json_dir.mkdir(parents=True, exist_ok=True)
|
||||||
summary_dir.mkdir(parents=True, exist_ok=True)
|
summary_dir.mkdir(parents=True, exist_ok=True)
|
||||||
|
excel_dir.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
csv_file = (
|
csv_file = (
|
||||||
categorized_csv_dir
|
categorized_csv_dir
|
||||||
|
|
@ -68,6 +71,11 @@ summary_file = (
|
||||||
/ f"category_summary_{year}_KW{week:02d}.json"
|
/ f"category_summary_{year}_KW{week:02d}.json"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
excel_file = (
|
||||||
|
excel_dir
|
||||||
|
/ f"transactions_{year}_KW{week:02d}.xlsx"
|
||||||
|
)
|
||||||
|
|
||||||
# --------------------------------------------------
|
# --------------------------------------------------
|
||||||
# Prüfen ob Quelldatei existiert
|
# Prüfen ob Quelldatei existiert
|
||||||
# --------------------------------------------------
|
# --------------------------------------------------
|
||||||
|
|
@ -202,6 +210,53 @@ with open(json_file, "w", encoding="utf-8") as outfile:
|
||||||
indent=2
|
indent=2
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# --------------------------------------------------
|
||||||
|
# Excel exportieren
|
||||||
|
# --------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
wb = Workbook()
|
||||||
|
|
||||||
|
ws1 = wb.active
|
||||||
|
ws1.title = "Transaktionen"
|
||||||
|
|
||||||
|
ws1.append([
|
||||||
|
"Datum",
|
||||||
|
"Betrag",
|
||||||
|
"Kategorie",
|
||||||
|
"Name",
|
||||||
|
"Verwendungszweck"
|
||||||
|
])
|
||||||
|
|
||||||
|
for t in categorized_transactions:
|
||||||
|
ws1.append([
|
||||||
|
t["date"],
|
||||||
|
t["amount"],
|
||||||
|
t["category"],
|
||||||
|
t["applicant_name"],
|
||||||
|
t["purpose"]
|
||||||
|
])
|
||||||
|
|
||||||
|
ws2 = wb.create_sheet("Kategorien")
|
||||||
|
|
||||||
|
ws2.append([
|
||||||
|
"Kategorie",
|
||||||
|
"Einnahmen",
|
||||||
|
"Ausgaben",
|
||||||
|
"Saldo"
|
||||||
|
])
|
||||||
|
|
||||||
|
for category, values in sorted(category_totals.items()):
|
||||||
|
ws2.append([
|
||||||
|
category,
|
||||||
|
values["income"],
|
||||||
|
values["expenses"],
|
||||||
|
values["saldo"]
|
||||||
|
])
|
||||||
|
|
||||||
|
wb.save(excel_file)
|
||||||
|
|
||||||
|
|
||||||
# --------------------------------------------------
|
# --------------------------------------------------
|
||||||
# Kategorien-Summen exportieren
|
# Kategorien-Summen exportieren
|
||||||
# --------------------------------------------------
|
# --------------------------------------------------
|
||||||
|
|
@ -239,4 +294,5 @@ for category, values in sorted(category_totals.items()):
|
||||||
print()
|
print()
|
||||||
print(f"CSV : {csv_file}")
|
print(f"CSV : {csv_file}")
|
||||||
print(f"JSON : {json_file}")
|
print(f"JSON : {json_file}")
|
||||||
print(f"Summary : {summary_file}")
|
print(f"Summary : {summary_file}")
|
||||||
|
print(f"Excel : {excel_file}")
|
||||||
Loading…
Add table
Add a link
Reference in a new issue