From: Mauro Scomparin Date: Wed, 12 Apr 2017 04:45:36 +0000 (+0200) Subject: Bilancio provvisorio. X-Git-Url: https://git.scompo.it/?a=commitdiff_plain;h=3768e5ad87bfa00faf9bd7839e1dd55b0d9da528;p=money.git Bilancio provvisorio. --- diff --git a/bilancio.py b/bilancio.py new file mode 100755 index 0000000..8d3a182 --- /dev/null +++ b/bilancio.py @@ -0,0 +1,46 @@ +#!/data/data/com.termux/files/usr/bin/python + +from time import localtime, strftime +from os.path import expanduser, join +from pprint import pprint +from decimal import * + +def file_output(): + home = expanduser('~') + out_file_name = 'movimenti.dat' + out_file = join(home, 'dati', out_file_name) + return out_file + +def carica_file(f): + dati = [] + with open(f, "r") as df: + for l in df: + spl = l.split(';') + d = { + 'valore' : spl[0], + 'data' : spl[1], + 'ora' : spl[2], + 'descrizione' : spl[3] + } + dati.append(d) + return dati + +print("bilancio 0.0.1") +out_file = file_output() +print('file:', out_file) +dati = carica_file(out_file) +val_attuale = Decimal('0') +spese_tot = Decimal('0') +guadagni_tot = Decimal('0') +for d in dati: + m = Decimal(d['valore']) + val_attuale = val_attuale + m + if m > Decimal('0'): + guadagni_tot = guadagni_tot + m + else: + spese_tot = spese_tot + m +print('valore attuale:', str(val_attuale)) +print('guadagni complessivi:', str(guadagni_tot)) +print('spese complessive:', str(spese_tot)) +print('grazie.') +