CONFIG_FILE_NAME = 'money.conf'
CONFIG_FILE_LOCATION = expanduser('~') + '/.config/' + CONFIG_FILE_NAME
+TYPE_FIELD_NAME = 'tipo'
+VALUE_FIELD_NAME = 'valore'
+DATE_FIELD_NAME = 'data'
+HOUR_FIELD_NAME = 'ora'
+DESCRIPTION_FIELD_NAME = 'descrizione'
def scrivi_movimento(path, m):
with open(path, 'a') as f:
- f.write(m['tipo'] + m['valore'])
+ f.write(m[TYPE_FIELD_NAME] + m[VALUE_FIELD_NAME])
f.write(';')
- f.write(m['data'])
+ f.write(m[DATE_FIELD_NAME])
f.write(';')
- f.write(m['ora'])
+ f.write(m[HOUR_FIELD_NAME])
f.write(';')
- f.write(m['descrizione'])
+ f.write(m[DESCRIPTION_FIELD_NAME])
f.write('\n')
return
def leggi_tipo():
t = 'n'
while not (t == '' or t == '+' or t == '-'):
- t = input('tipo (+/-) [-]: ')
+ t = input('type (+/-) [-]: ')
if t == '':
t = '-'
elif t == '+':
def leggi_valore():
v = ''
while v == '':
- v = input('valore (#####.##) []: ')
+ v = input('value (#####.##) []: ')
return v
def leggi_data():
- d = input('data (DD/MM/YYYY) [oggi]: ')
+ d = input('data (DD/MM/YYYY) [today]: ')
if d == '':
d = strftime("%d/%m/%Y", localtime())
return d
def leggi_ora():
- o = input('ora (HH:MM) [adesso]: ')
+ o = input('hour (HH:MM) [now]: ')
if o == '':
o = strftime('%H:%M', localtime())
return o
def leggi_descrizione():
- d = input('descrizione () []: ')
+ d = input('description () []: ')
return d
ora = leggi_ora()
descrizione = leggi_descrizione()
m = {
- 'tipo': tipo,
- 'valore': valore,
- 'data': data,
- 'ora': ora,
- 'descrizione': descrizione
+ TYPE_FIELD_NAME: tipo,
+ VALUE_FIELD_NAME: valore,
+ DATE_FIELD_NAME: data,
+ HOUR_FIELD_NAME: ora,
+ DESCRIPTION_FIELD_NAME: descrizione
}
return m
for l in df:
spl = l.split(';')
d = {
- 'valore': spl[0],
- 'data': spl[1],
- 'ora': spl[2],
- 'descrizione': spl[3]
+ VALUE_FIELD_NAME: spl[0],
+ DATE_FIELD_NAME: spl[1],
+ HOUR_FIELD_NAME: spl[2],
+ DESCRIPTION_FIELD_NAME: spl[3]
}
dati.append(d)
return dati
return sorted(
dati,
key=lambda x: (
- data_default(x['data']),
- ora_default(x['ora'])
+ data_default(x[DATE_FIELD_NAME]),
+ ora_default(x[HOUR_FIELD_NAME])
),
reverse=True
)
return {DATA_FILE_NAME: 'movimenti.dat', LAST_MOVEMENT_NUMBER: 5}
def last_movement_number_message(n):
- return 'ultimi {} movimenti:'.format(n)
+ return 'latest {} movements:'.format(n)
def riassunto(file_dati, conf):
dati = carica_file(file_dati)
spese_tot = Decimal('0')
guadagni_tot = Decimal('0')
for d in dati:
- m = Decimal(d['valore'])
+ m = Decimal(d[VALUE_FIELD_NAME])
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('actual value:', str(val_attuale))
+ print('total incomes:', str(guadagni_tot))
+ print('total expenses:', str(spese_tot))
print(last_movement_number_message(conf[LAST_MOVEMENT_NUMBER]))
for i in range(conf[LAST_MOVEMENT_NUMBER]):
if i < len(dati_ordinati):