Category overhaul (#20)
Reviewed-on: #20 Co-authored-by: Mathias <mathias2784@web.de>
This commit was merged in pull request #20.
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
Girokonto:Beruf / Ausbildung
|
||||
Girokonto:Beruf / Ausbildung:Gehalt
|
||||
Girokonto:Beruf / Ausbildung:Reisekosten
|
||||
Girokonto:Freizeit
|
||||
Girokonto:Freizeit:Abo
|
||||
Girokonto:Freizeit:Elektronik&Hardware
|
||||
Girokonto:Freizeit:Foto
|
||||
Girokonto:Freizeit:Medien
|
||||
Girokonto:Freizeit:Musikintrumente
|
||||
Girokonto:Freizeit:Urlaub&Ausflüge
|
||||
Girokonto:Freizeit:sonst.
|
||||
Girokonto:Lebenshaltung
|
||||
Girokonto:Lebenshaltung:Auto
|
||||
Girokonto:Lebenshaltung:Bekleidung
|
||||
Girokonto:Lebenshaltung:Fahrrad
|
||||
Girokonto:Lebenshaltung:Gesundheit
|
||||
Girokonto:Lebenshaltung:Haushalt sonst.
|
||||
Girokonto:Lebenshaltung:Heimwerken
|
||||
Girokonto:Lebenshaltung:Kontoführung
|
||||
Girokonto:Lebenshaltung:Körperpflege
|
||||
Girokonto:Lebenshaltung:Lebensmittel
|
||||
Girokonto:Lebenshaltung:Telekommunikation
|
||||
Girokonto:Lebenshaltung:Versicherungen
|
||||
Girokonto:Privat
|
||||
Girokonto:Privat:Geschenke
|
||||
Girokonto:Privat:Mitgliedsbeiträge
|
||||
Girokonto:Privat:Steuerausgleich Ehetine
|
||||
Girokonto:Sonstiges
|
||||
Girokonto:Sparen
|
||||
Girokonto:Sparen:Depot
|
||||
Girokonto:Sparen:Tagesgeld
|
||||
Girokonto:unbestimmte Verwendung:Bargeld
|
||||
Girokonto:unbestimmte Verwendung:Kreditkarte
|
||||
Haushaltskonto:Beiträge
|
||||
Umbuchung
|
||||
@@ -0,0 +1,54 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Extract unique categories from b4w CSV export."""
|
||||
|
||||
import argparse
|
||||
import csv
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def extract_unique_categories(csv_path: str, output_path: str) -> list[str]:
|
||||
"""Merge CSV categories with the existing output file, sorted, one per line."""
|
||||
|
||||
unique_categories: set[str] = set()
|
||||
|
||||
with open(csv_path, "r", encoding="utf-8") as f:
|
||||
reader = csv.DictReader(f)
|
||||
for row in reader:
|
||||
category = (row.get("Category") or "").strip()
|
||||
if category:
|
||||
unique_categories.add(category)
|
||||
|
||||
output_file_path = Path(output_path)
|
||||
if output_file_path.exists():
|
||||
with open(output_file_path, "r", encoding="utf-8") as f:
|
||||
for line in f:
|
||||
if category := line.strip():
|
||||
unique_categories.add(category)
|
||||
|
||||
sorted_categories = sorted(unique_categories)
|
||||
|
||||
with open(output_file_path, "w", encoding="utf-8") as f:
|
||||
f.writelines(f"{cat}\n" for cat in sorted_categories)
|
||||
|
||||
print(f"Extracted {len(sorted_categories)} unique categories")
|
||||
print(f"Output written to: {output_path}")
|
||||
return sorted_categories
|
||||
|
||||
|
||||
def main() -> None:
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Extract unique categories from a b4w CSV export."
|
||||
)
|
||||
parser.add_argument("--csv", required=True, help="Pfad der b4w-Exportdatei (CSV)")
|
||||
parser.add_argument(
|
||||
"--output",
|
||||
default="scripts/initial_load/categories/categories.txt",
|
||||
help="Pfad der Ausgabedatei (Default: %(default)s)",
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
extract_unique_categories(args.csv, args.output)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user