From ac4b7b073a5e1e95222573429fe8fe790a4d6adc Mon Sep 17 00:00:00 2001 From: Mauro Scomparin Date: Wed, 12 Apr 2017 05:48:57 +0200 Subject: [PATCH] Aggiunto estrai.py in utils. --- utils/estrai.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100755 utils/estrai.py diff --git a/utils/estrai.py b/utils/estrai.py new file mode 100755 index 0000000..27675c8 --- /dev/null +++ b/utils/estrai.py @@ -0,0 +1,28 @@ +from decimal import * + +dati = [] +stato = 0 +with open('dati.quif','r') as f: + for l in f: + if stato == 0 and '!Type:Cash' in l: + stato = 1 + tr = { + 'head' : l + } + dati.append(tr) + elif stato == 1 and l.startswith('D'): + dati[-1]['data'] = l + elif stato == 1 and l.startswith('M'): + dati[-1]['descrizione'] = l + elif stato == 1 and l.startswith('$'): + dati[-1]['importo'] = l + elif stato == 1 and '^' in l: + stato = 0 + +for d in dati: + data = d['data'][1:].replace('\n','') + descrizione = d['descrizione'][1:].replace('\n','') + importo = d['importo'][1:].replace('\n', '').replace(',', '.') + imp_ok = Decimal(importo) * Decimal('-1') + print(str(imp_ok) + ';' + data + ';' + ';' + descrizione) + -- 2.25.1