From 7b41c5dc809159028566367fbf1f60df67eba1cb Mon Sep 17 00:00:00 2001 From: Yves Fischer Date: Fri, 10 Nov 2017 10:02:43 +0100 Subject: improve transaction details parsing --- transaction_details.py | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) (limited to 'transaction_details.py') diff --git a/transaction_details.py b/transaction_details.py index a7ecf6c..dec0ee7 100644 --- a/transaction_details.py +++ b/transaction_details.py @@ -40,21 +40,12 @@ VERWENDUNGSZWECK_KEYS = { def parse_transaction_details(details): detail_str = ''.join(d.strip() for d in details.splitlines()) - result = {} - for key, value in DETAIL_KEYS.items(): - result[value] = None - for key, value in VERWENDUNGSZWECK_KEYS.items(): - result[value] = None + detail_str = detail_str[3:] + result = dict(map(lambda k: [k,None], DETAIL_KEYS.values())) + result.update(dict(map(lambda k: [k,None], VERWENDUNGSZWECK_KEYS.values()))) pre_result = {} - segment = '' - segment_type = '' - for index, char in enumerate(detail_str): - if char != '?': - segment += char - continue - pre_result[segment_type] = segment if not segment_type else segment[2:] - segment_type = detail_str[index+1] + detail_str[index+2] - segment = '' + for segment in detail_str.split('?'): + pre_result[segment[0:2]] = segment[2:] for key, value in pre_result.items(): if key in DETAIL_KEYS: result[DETAIL_KEYS[key]] = value -- cgit v1.2.1