X-Git-Url: https://piware.de/gitweb/?p=bin.git;a=blobdiff_plain;f=consors-report.py;fp=consors-report.py;h=c3d505d0e10a342434fd6fc6b810ca36ea28d37c;hp=89b24c12d87e89b90ce959119de53042546bca14;hb=6da88a57b007c9abf88e82df8cf513bfba397593;hpb=c2223f6ec6bfeb9a1acc749e8207994a96902d4a diff --git a/consors-report.py b/consors-report.py index 89b24c1..c3d505d 100755 --- a/consors-report.py +++ b/consors-report.py @@ -2,6 +2,7 @@ import argparse import collections +import csv import itertools import re from collections import namedtuple @@ -44,8 +45,8 @@ def get_category(item: str) -> str: return 'Sonstiges' -def parse_entry(line: str) -> Entry: - fields = [f.strip() for f in line.strip().split(';')] +def parse_entry(raw_fields: Iterable[str]) -> Entry: + fields = [f.strip() for f in raw_fields] # last field is the value, parse as float value = float(fields.pop().replace('.', '').replace(',', '.')) # match on who, IBAN, type, or desc @@ -63,9 +64,12 @@ 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) + next(reader) # skip header # first line is the column headers, chop it off - entries = map(parse_entry, f.readlines()[1:]) - return filter(filter_entry, entries) + entries = map(parse_entry, reader) + # do the actual iteration here, as the files get closed afterwards + return list(filter(filter_entry, entries)) def main():