Browse code

Boobank now provides amounts and balances as strings.

Xavier G authored on09/01/2019 20:27:59
Showing3 changed files

... ...
@@ -38,7 +38,7 @@ def main():
38 38
         timestamp = accounts.get('timestamp', time.time())
39 39
         for account in accounts.get('data', []):
40 40
             add_account(table, account, timestamp)
41
-            total += account.get('balance')
41
+            total += float(account.get('balance'))
42 42
     print(table)
43 43
     total_line = '%-60s' % ''
44 44
     total_line += colored('Total: ', 'white', attrs=['bold'])
... ...
@@ -64,7 +64,7 @@ def add_account(table, account, cache_timestamp):
64 64
     account_id = colored(account.get('id'), 'cyan')
65 65
     label = colored(account.get('label'), 'cyan')
66 66
     currency = account.get('currency', DEFAULT_CURRENCY)
67
-    balance = format_amount(account['balance'], currency, COLORING_THRESHOLD)
67
+    balance = format_amount(float(account['balance']), currency, COLORING_THRESHOLD)
68 68
     cache_date = format_timestamp_colored(cache_timestamp, MAX_AGE)
69 69
     table.add_row([account_id, label, balance, cache_date])
70 70
 
... ...
@@ -69,7 +69,7 @@ def send_account(graphite_socket, account, timestamp):
69 69
     socket.
70 70
     """
71 71
     pattern = '%s %.2f %d\n'
72
-    values = (get_path(account), account['balance'], int(timestamp))
72
+    values = (get_path(account), float(account['balance']), int(timestamp))
73 73
     line = pattern % values
74 74
     graphite_socket.send(line)
75 75
 
... ...
@@ -66,7 +66,7 @@ def add_operation(table, operation):
66 66
     date = colored(operation.get('date'), 'cyan')
67 67
     label = colored(operation.get('label')[:80], 'cyan')
68 68
     currency = operation.get('currency', DEFAULT_CURRENCY)
69
-    amount = format_amount(operation['amount'], currency, COLORING_SIMPLE)
69
+    amount = format_amount(float(operation['amount']), currency, COLORING_SIMPLE)
70 70
     table.add_row([date, label, amount])
71 71
 
72 72
 if __name__ == '__main__':