Make commands async and improve error handling
This commit is contained in:
parent
6aec0c1078
commit
67ed68ac5e
|
@ -316,6 +316,7 @@ class Nordigen(util.Base):
|
|||
existing_entry = loads(settings.Nordigen.Maps)
|
||||
self.banks = existing_entry
|
||||
|
||||
@inlineCallbacks
|
||||
def map_account(self, account_id): # TODO: inlineCallbacks?
|
||||
"""
|
||||
Map an account_id at a bank to an account_name.
|
||||
|
@ -323,7 +324,7 @@ class Nordigen(util.Base):
|
|||
Data type: {"monzo": [account, ids, here],
|
||||
"revolut": [account, ids, here]}
|
||||
"""
|
||||
account_data = self.get_account(account_id)
|
||||
account_data = yield self.get_account(account_id)
|
||||
currency = account_data["currency"]
|
||||
|
||||
existing_entry = loads(settings.Nordigen.Maps)
|
||||
|
@ -445,7 +446,7 @@ class Nordigen(util.Base):
|
|||
obj = AccountBalancesRoot.from_json(r.content)
|
||||
except ValidationError as err:
|
||||
self.log.error(f"Validation error: {err}")
|
||||
return
|
||||
return (False, False)
|
||||
parsed = obj.to_dict()["balances"]
|
||||
total = 0
|
||||
currency = None
|
||||
|
@ -453,7 +454,7 @@ class Nordigen(util.Base):
|
|||
if currency:
|
||||
if not currency == entry["balanceAmount"]["currency"]:
|
||||
self.log.error("Different currencies in balance query.")
|
||||
return
|
||||
return (False, False)
|
||||
if not entry["balanceType"] == "interimBooked":
|
||||
continue
|
||||
total += float(entry["balanceAmount"]["amount"])
|
||||
|
@ -471,6 +472,8 @@ class Nordigen(util.Base):
|
|||
currency, amount = self.get_balance(account_id)
|
||||
if not amount:
|
||||
continue
|
||||
if not currency:
|
||||
continue
|
||||
if currency in totals:
|
||||
totals[currency] += amount
|
||||
else:
|
||||
|
|
|
@ -887,15 +887,19 @@ class IRCCommands(object):
|
|||
authed = True
|
||||
helptext = "Enable an account_id at a bank for use in Nordigen. Usage: nmapaccount <account_id>"
|
||||
|
||||
@staticmethod
|
||||
def got_map_account(account_name, account_id, msg):
|
||||
if not account_name:
|
||||
msg(f"Failed to map the account")
|
||||
return
|
||||
msg(f"Mapped account ID {account_id} to {account_name}")
|
||||
|
||||
@staticmethod
|
||||
def run(cmd, spl, length, authed, msg, agora, tx, ux):
|
||||
if length == 2:
|
||||
account_id = spl[1]
|
||||
account_name = tx.sinks.nordigen.map_account(account_id)
|
||||
if not account_name:
|
||||
msg(f"Failed to map the account")
|
||||
return
|
||||
msg(f"Mapped account ID {account_id} to {account_name}")
|
||||
c = tx.sinks.nordigen.map_account(account_id)
|
||||
c.addCallback(IRCCommands.nmapaccount.got_map_account, account_id, msg)
|
||||
|
||||
class nunmapaccount(object):
|
||||
name = "nunmapaccount"
|
||||
|
|
Loading…
Reference in New Issue