Port some commands to async

master
Mark Veidemanis 2 years ago
parent 789e27d627
commit 6bf3daee4c
Signed by: m
GPG Key ID: 5ACFCEED46C0904F

@ -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.")
@ -770,13 +770,17 @@ class IRCCommands(object):
authed = True authed = True
helptext = "Get a list of acccounts from Nordigen. Usage: naccounts" helptext = "Get a list of acccounts from Nordigen. Usage: naccounts"
@staticmethod
def got_accounts(accounts, msg):
for name, accounts in accounts.items():
for account in accounts:
msg(dumps(account))
@staticmethod @staticmethod
def run(cmd, spl, length, authed, msg, agora, tx, ux): def run(cmd, spl, length, authed, msg, agora, tx, ux):
if length == 1: if length == 1:
accounts = tx.sinks.nordigen.get_all_account_info() accounts = tx.sinks.nordigen.get_all_account_info()
for name, accounts in accounts.items(): accounts.addCallback(IRCCommands.naccounts.got_accounts, msg)
for account in accounts:
msg(dumps(account))
class transactions(object): class transactions(object):
name = "transactions" name = "transactions"
@ -804,21 +808,25 @@ class IRCCommands(object):
authed = True authed = True
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
def got_transactions(transactions, msg):
for transaction in transactions:
if "transaction_id" in transaction:
txid = transaction["transaction_id"]
else:
txid = "not_set"
timestamp = transaction["timestamp"]
amount = transaction["amount"]
currency = transaction["currency"]
reference = transaction["reference"]
msg(f"{timestamp} {txid} {amount}{currency} {reference}")
@staticmethod @staticmethod
def run(cmd, spl, length, authed, msg, agora, tx, ux): def run(cmd, spl, length, authed, msg, agora, tx, ux):
if length == 2: if length == 2:
account_id = spl[1] account_id = spl[1]
transactions = tx.sinks.nordigen.get_transactions(account_id) transactions = tx.sinks.nordigen.get_transactions(account_id)
for transaction in transactions: transactions.addCallback(IRCCommands.ntransactions.got_transactions, msg)
if "transaction_id" in transaction:
txid = transaction["transaction_id"]
else:
txid = "not_set"
timestamp = transaction["timestamp"]
amount = transaction["amount"]
currency = transaction["currency"]
reference = transaction["reference"]
msg(f"{timestamp} {txid} {amount}{currency} {reference}")
class nreqs(object): class nreqs(object):
name = "nreqs" name = "nreqs"
@ -826,14 +834,18 @@ class IRCCommands(object):
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

@ -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):
""" """

Loading…
Cancel
Save