From: Martin Pitt Date: Thu, 2 May 2024 05:54:03 +0000 (+0200) Subject: consors-report: Adjust to format change in May 2024 X-Git-Url: https://piware.de/gitweb/?a=commitdiff_plain;ds=inline;h=8e8cb09025a73f6a41c347037f70e3e9df5707e7;p=bin.git consors-report: Adjust to format change in May 2024 Consors changed back to semicolon separator (see commit 6da88a57b007c9), and added a 9th field "Währung". Convert the older CSVs with ```py import csv import sys with open(sys.argv[1], 'r') as csvfile: reader = csv.reader(csvfile, delimiter=',', quotechar='"') writer = csv.writer(sys.stdout, delimiter=';', quotechar='"') for row in reader: writer.writerow(row) ``` --- diff --git a/consors-report.py b/consors-report.py index f76deb3..272b06b 100755 --- a/consors-report.py +++ b/consors-report.py @@ -47,6 +47,8 @@ def get_category(item: str) -> str: def parse_entry(raw_fields: Iterable[str]) -> Entry: fields = [f.strip() for f in raw_fields] + # format change in May 2024, adds a 9th field "Währung"; ignore + fields = fields[:8] # last field is the value, parse as float value = float(fields.pop().replace('.', '').replace(',', '.')) # match on who, IBAN, type, or desc @@ -64,7 +66,7 @@ def parse_csv(path: Path, date_filter: str) -> Iterable[Entry]: return filter_re.search(entry.date) with path.open() as f: - reader = csv.reader(f) + reader = csv.reader(f, delimiter=';') next(reader) # skip header # first line is the column headers, chop it off entries = map(parse_entry, reader)