Port some commands to async

This commit is contained in:
Mark Veidemanis 2022-05-02 18:21:03 +01:00
parent 789e27d627
commit 6bf3daee4c
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
2 changed files with 29 additions and 18 deletions

View File

@ -13,7 +13,7 @@ class GenericCommands(object):
Get details of open trades and post on IRC. Get details of open trades and post on IRC.
""" """
trades = caller.get_dashboard() trades = caller.get_dashboard_irc()
if not trades: if not trades:
msg("No open trades.") msg("No open trades.")
@ -771,13 +771,17 @@ class IRCCommands(object):
helptext = "Get a list of acccounts from Nordigen. Usage: naccounts" helptext = "Get a list of acccounts from Nordigen. Usage: naccounts"
@staticmethod @staticmethod
def run(cmd, spl, length, authed, msg, agora, tx, ux): def got_accounts(accounts, msg):
if length == 1:
accounts = tx.sinks.nordigen.get_all_account_info()
for name, accounts in accounts.items(): for name, accounts in accounts.items():
for account in accounts: for account in accounts:
msg(dumps(account)) msg(dumps(account))
@staticmethod
def run(cmd, spl, length, authed, msg, agora, tx, ux):
if length == 1:
accounts = tx.sinks.nordigen.get_all_account_info()
accounts.addCallback(IRCCommands.naccounts.got_accounts, msg)
class transactions(object): class transactions(object):
name = "transactions" name = "transactions"
authed = True authed = True
@ -805,10 +809,7 @@ class IRCCommands(object):
helptext = "Get a list of transactions from Nordigen. Usage: ntransactions <account_id>" helptext = "Get a list of transactions from Nordigen. Usage: ntransactions <account_id>"
@staticmethod @staticmethod
def run(cmd, spl, length, authed, msg, agora, tx, ux): def got_transactions(transactions, msg):
if length == 2:
account_id = spl[1]
transactions = tx.sinks.nordigen.get_transactions(account_id)
for transaction in transactions: for transaction in transactions:
if "transaction_id" in transaction: if "transaction_id" in transaction:
txid = transaction["transaction_id"] txid = transaction["transaction_id"]
@ -820,20 +821,31 @@ class IRCCommands(object):
reference = transaction["reference"] reference = transaction["reference"]
msg(f"{timestamp} {txid} {amount}{currency} {reference}") msg(f"{timestamp} {txid} {amount}{currency} {reference}")
@staticmethod
def run(cmd, spl, length, authed, msg, agora, tx, ux):
if length == 2:
account_id = spl[1]
transactions = tx.sinks.nordigen.get_transactions(account_id)
transactions.addCallback(IRCCommands.ntransactions.got_transactions, msg)
class nreqs(object): class nreqs(object):
name = "nreqs" name = "nreqs"
authed = True authed = True
helptext = "Get a list of requisitions from Nordigen." helptext = "Get a list of requisitions from Nordigen."
@staticmethod @staticmethod
def run(cmd, spl, length, authed, msg, agora, tx, ux): def got_requisitions(reqs, msg):
reqs = tx.sinks.nordigen.get_requisitions()
for req in reqs: for req in reqs:
id = req["id"] id = req["id"]
institution_id = req["institution_id"] institution_id = req["institution_id"]
redirect = req["link"] redirect = req["link"]
msg(f"{id} {institution_id} {redirect}") msg(f"{id} {institution_id} {redirect}")
@staticmethod
def run(cmd, spl, length, authed, msg, agora, tx, ux):
reqs = tx.sinks.nordigen.get_requisitions()
reqs.addCallback(IRCCommands.nreqs.got_requisitions, msg)
class ndelreq(object): class ndelreq(object):
name = "ndelreq" name = "ndelreq"
authed = True authed = True

View File

@ -1,7 +1,6 @@
# Twisted/Klein imports # Twisted/Klein imports
from twisted.words.protocols import irc from twisted.words.protocols import irc
from twisted.internet import protocol, reactor, ssl from twisted.internet import protocol, reactor, ssl
from twisted.internet.task import deferLater
# Project imports # Project imports
from settings import settings from settings import settings
@ -116,7 +115,7 @@ class IRCBot(irc.IRCClient):
Join our channel. Join our channel.
""" """
self.log.info(f"Signed on as {self.nickname}") self.log.info(f"Signed on as {self.nickname}")
deferLater(reactor, 2, self.join, self.channel) self.join(self.channel)
def joined(self, channel): def joined(self, channel):
""" """