From f28e42c42f9a19a07712d1c7dc9a9336ed11ca95 Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Tue, 28 Dec 2021 13:42:31 +0000 Subject: [PATCH] Add release URLs and squish bug --- handler/agora.py | 35 +++++++++++++++++++++++++++++++---- handler/app.py | 4 ++++ 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/handler/agora.py b/handler/agora.py index bf32892..db673f9 100644 --- a/handler/agora.py +++ b/handler/agora.py @@ -69,6 +69,7 @@ class Agora(object): return False if dash["response"]["data"]["contact_count"] > 0: for contact in dash["response"]["data"]["contact_list"]: + print(f"CONTACT {contact}") contact_id = contact["data"]["contact_id"] current_trades.append(contact_id) buyer = contact["data"]["buyer"]["username"] @@ -85,11 +86,37 @@ class Agora(object): self.last_dash.add(contact_id) # Purge old trades from cache - for trade in self.last_dash: + for trade in list(self.last_dash): # We're removing from the list on the fly if trade not in current_trades: self.last_dash.remove(trade) return dash_tmp + def dashboard_release_urls(self): + """ + Get information about our open trades. + Post new trades to IRC and cache trades for the future. + :return: human readable list of strings about our trades or False + :rtype: list or bool + """ + dash = self.agora.dashboard_seller() + dash_tmp = [] + if "data" not in dash["response"]: + return False + if dash["response"]["data"]["contact_count"] > 0: + for contact in dash["response"]["data"]["contact_list"]: + contact_id = contact["data"]["contact_id"] + buyer = contact["data"]["buyer"]["username"] + amount = contact["data"]["amount"] + amount_xmr = contact["data"]["amount_xmr"] + currency = contact["data"]["currency"] + release_url = contact["actions"]["release_url"] + if not contact["data"]["is_selling"]: + continue + + dash_tmp.append(f"{contact_id}: {buyer} {amount}{currency} {amount_xmr}XMR {release_url}") + + return dash_tmp + def get_messages(self, contact_id, send_irc=True): """ Get messages for a certain trade ID. @@ -113,7 +140,7 @@ class Agora(object): self.irc.client.msg(self.irc.client.channel, x) return messages_tmp - def get_all_messages(self): + def get_all_messages(self, send_irc=True): """ Get all messages for all open trades. :return: dict of lists keyed by trade/contact ID @@ -122,11 +149,11 @@ class Agora(object): dash = self.dashboard_id_only() messages_tmp = {} for contact_id in dash: - messages = self.get_messages(contact_id) + messages = self.get_messages(contact_id, send_irc=send_irc) messages_tmp[contact_id] = messages # Purge old trades from cache - for trade in self.last_messages: + for trade in list(self.last_messages): # We're removing from the list on the fly if trade not in messages_tmp: del self.last_messages[trade] diff --git a/handler/app.py b/handler/app.py index c759481..48ec31a 100755 --- a/handler/app.py +++ b/handler/app.py @@ -37,6 +37,9 @@ class WebApp(object): def __init__(self): self.log = Logger("webapp") + def set_tx(self, tx): + self.tx = tx + @app.route("/callback", methods=["POST"]) def callback(self, request): content = request.content.read() @@ -77,6 +80,7 @@ if __name__ == "__main__": # Define WebApp webapp = WebApp() + webapp.set_tx(tx) # Handle setting up JWT and request_token from an auth code if settings.Revolut.SetupToken == "1": deferLater(reactor, 1, revolut.setup_auth)