import argparse
import collections
+import csv
import itertools
import re
from collections import namedtuple
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
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():