From 80f0d4a5fd085eb9792e5cb569c8646f769d2b21 Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Thu, 30 Dec 2021 14:15:24 +0000 Subject: [PATCH] Implement recursively getting ads --- handler/agora.py | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/handler/agora.py b/handler/agora.py index b91ab98..115d8c6 100644 --- a/handler/agora.py +++ b/handler/agora.py @@ -147,6 +147,9 @@ class Agora(object): reference = self.tx.tx_to_ref(contact_id) if not reference: 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"]: messages_tmp.append(f"({message['sender']['username']}): {message['msg']}") if send_irc: @@ -155,6 +158,7 @@ class Agora(object): difference = set(messages_tmp) ^ set(self.last_messages[reference]) for x in difference: self.irc.client.msg(self.irc.client.channel, f"AUTO {reference}: {x}") + self.last_messages[reference] = messages_tmp else: self.last_messages[reference] = messages_tmp for x in messages_tmp: @@ -185,6 +189,8 @@ class Agora(object): if not reference: reference = "not_set" messages = self.get_messages(contact_id, send_irc=send_irc) + if not messages: + return False messages_tmp[reference] = messages # Purge old trades from cache @@ -194,14 +200,30 @@ class Agora(object): 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. - :return: data about our open ads - :rtype: dict + Delete all of our adverts. + :return: True or False + :rtype: bool """ - ads = self.agora.ads() - return ads + ads = self.enum_ads() + if not ads: + return False + for ad_id in ads: + self.agora.ad_delete(ad_id) def get_rates_all(self): """