From 102057f49063fc44976c968b02dd2d51e1088fc5 Mon Sep 17 00:00:00 2001 From: Kasownik Date: Thu, 22 Jun 2017 04:00:20 +0200 Subject: [PATCH] fetch: add account balance reports to the output log and keep balance information in cache files ~enleth --- fetch/banking-ib.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/fetch/banking-ib.py b/fetch/banking-ib.py index 37fe9ea..72a516f 100644 --- a/fetch/banking-ib.py +++ b/fetch/banking-ib.py @@ -531,6 +531,8 @@ if __name__ == "__main__": assert False, "unhandled option" lock() + + balances = {} if cached: print "[i] Cached run - will not connect to the bank" @@ -568,6 +570,10 @@ if __name__ == "__main__": cachefile.write(history) cachefile.close() history_logs[account_number] = history + balances[account_number] = (account["available_balance"],account["currency"]) + balancefile = open(CACHE_DIR+"/balance-"+account_number,'w') + balancefile.write("{} {}\n".format(account["available_balance"],account["currency"])) + balancefile.close() parsed = {} stats = {} @@ -587,7 +593,12 @@ if __name__ == "__main__": if noaction: print "[i] --no-action set, skipping row {}".format(row) session.commit() - + + if balances: + print "[i] Account balances:" + for account_number,v in balances.items(): + balance,currency = v + print "\t{}: {} {}".format(account_number, balance, currency) print "[i] Done: ", stats release() #print f.create_report().read()