From e10560836730813907c35f3cce8380c48d17ff37 Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Fri, 13 May 2022 17:11:17 +0100 Subject: [PATCH] Make ads and pubads async --- handler/ux/commands.py | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/handler/ux/commands.py b/handler/ux/commands.py index e621dd1..97294ed 100644 --- a/handler/ux/commands.py +++ b/handler/ux/commands.py @@ -162,6 +162,14 @@ class GenericCommands(object): msg(f"{message} - {message_long}") class pubads(object): + @staticmethod + def got_pubads(pubads_output, currency, msg): + if not pubads_output: + msg("No results.") + return + for ad in pubads_output[currency]: + msg(f"({ad[0]}) {ad[1]} {ad[2]} {ad[3]} {ad[4]} {ad[5]} {ad[6]}") + @staticmethod def run(cmd, spl, length, authed, msg, agora, tx, ux, asset_list, caller): if length == 3: @@ -170,12 +178,9 @@ class GenericCommands(object): msg(f"Not a valid asset: {spl[1]}") return currency = spl[2] - rtrn = caller.get_all_public_ads(assets=[asset], currencies=[currency]) - if not rtrn: - msg("No results.") - return - for ad in rtrn[currency]: - msg(f"({ad[0]}) {ad[1]} {ad[2]} {ad[3]} {ad[4]} {ad[5]} {ad[6]}") + c = caller.get_all_public_ads(assets=[asset], currencies=[currency]) + c.addCallback(GenericCommands.pubads.got_pubads, currency, msg) + elif length == 4: asset = spl[1] if asset not in loads(asset_list): @@ -183,12 +188,8 @@ class GenericCommands(object): return providers = spl[3].split(",") currency = spl[2] - rtrn = caller.get_all_public_ads(assets=[asset], currencies=[currency], providers=providers) - if not rtrn: - msg("No results.") - return - for ad in rtrn[currency]: - msg(f"({ad[0]}) {ad[1]} {ad[2]} {ad[3]} {ad[4]} {ad[5]} {ad[6]}") + c = caller.get_all_public_ads(assets=[asset], currencies=[currency], providers=providers) + c.addCallback(GenericCommands.pubads.got_pubads, currency, msg) class cheat(object): @staticmethod @@ -213,11 +214,18 @@ class GenericCommands(object): class ads(object): @staticmethod - def run(cmd, spl, length, authed, msg, agora, tx, ux, caller): - ads = caller.enum_ads() - for ad in ads: + def got_ads(ads_output, msg): + if not ads_output: + msg("Could not get ads.") + return + for ad in ads_output: msg(f"({ad[0]}) {ad[1]} {ad[2]} {ad[3]} {ad[4]}") + @staticmethod + def run(cmd, spl, length, authed, msg, agora, tx, ux, caller): + c = caller.enum_ads() + c.addCallback(GenericCommands.ads.got_ads, msg) + class withdraw(object): @staticmethod def run(cmd, spl, length, authed, msg, agora, tx, ux, caller):