Implement recursively getting ads

This commit is contained in:
Mark Veidemanis 2021-12-30 14:15:24 +00:00
parent 88d3cfba30
commit 80f0d4a5fd
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
1 changed files with 28 additions and 6 deletions

View File

@ -147,6 +147,9 @@ class Agora(object):
reference = self.tx.tx_to_ref(contact_id) reference = self.tx.tx_to_ref(contact_id)
if not reference: if not reference:
reference = "not_set" reference = "not_set"
if "data" not in messages["response"]:
self.log.error("Malformed messages: {messages}", messages=messages)
return False
for message in messages["response"]["data"]["message_list"]: for message in messages["response"]["data"]["message_list"]:
messages_tmp.append(f"({message['sender']['username']}): {message['msg']}") messages_tmp.append(f"({message['sender']['username']}): {message['msg']}")
if send_irc: if send_irc:
@ -155,6 +158,7 @@ class Agora(object):
difference = set(messages_tmp) ^ set(self.last_messages[reference]) difference = set(messages_tmp) ^ set(self.last_messages[reference])
for x in difference: for x in difference:
self.irc.client.msg(self.irc.client.channel, f"AUTO {reference}: {x}") self.irc.client.msg(self.irc.client.channel, f"AUTO {reference}: {x}")
self.last_messages[reference] = messages_tmp
else: else:
self.last_messages[reference] = messages_tmp self.last_messages[reference] = messages_tmp
for x in messages_tmp: for x in messages_tmp:
@ -185,6 +189,8 @@ class Agora(object):
if not reference: if not reference:
reference = "not_set" reference = "not_set"
messages = self.get_messages(contact_id, send_irc=send_irc) messages = self.get_messages(contact_id, send_irc=send_irc)
if not messages:
return False
messages_tmp[reference] = messages messages_tmp[reference] = messages
# Purge old trades from cache # Purge old trades from cache
@ -194,14 +200,30 @@ class Agora(object):
return messages_tmp return messages_tmp
def get_ads(self): def enum_ad_ids(self, page=0):
ads = self.agora._api_call(api_method="ads", query_values={"page": page})
ads_total = []
if not ads["success"]:
return False
for ad in ads["response"]["data"]["ad_list"]:
ads_total.append(ad["data"]["ad_id"])
if "next" in ads["response"]["pagination"]:
page += 1
for ad in self.enum_ads(page):
ads_total.append(ad)
return ads_total
def nuke_ads(self):
""" """
Get information about our ads. Delete all of our adverts.
:return: data about our open ads :return: True or False
:rtype: dict :rtype: bool
""" """
ads = self.agora.ads() ads = self.enum_ads()
return ads if not ads:
return False
for ad_id in ads:
self.agora.ad_delete(ad_id)
def get_rates_all(self): def get_rates_all(self):
""" """