Add release URLs and squish bug

This commit is contained in:
Mark Veidemanis 2021-12-28 13:42:31 +00:00
parent 0223b2ea7a
commit f28e42c42f
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
2 changed files with 35 additions and 4 deletions

View File

@ -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]

View File

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