Implement smarter ad management
This commit is contained in:
parent
21fce0e685
commit
5649909385
|
@ -182,10 +182,25 @@ class Agora(object):
|
||||||
return False
|
return False
|
||||||
for ad in ads["response"]["data"]["ad_list"]:
|
for ad in ads["response"]["data"]["ad_list"]:
|
||||||
ads_total.append(ad["data"]["ad_id"])
|
ads_total.append(ad["data"]["ad_id"])
|
||||||
if "next" in ads["response"]["pagination"]:
|
if "pagination" in ads["response"]:
|
||||||
page += 1
|
if "next" in ads["response"]["pagination"]:
|
||||||
for ad in self.enum_ads(page):
|
page += 1
|
||||||
ads_total.append(ad)
|
for ad in self.enum_ad_ids(page):
|
||||||
|
ads_total.append(ad)
|
||||||
|
return ads_total
|
||||||
|
|
||||||
|
def enum_ads(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"], ad["data"]["countrycode"], ad["data"]["currency"]])
|
||||||
|
if "pagination" in ads["response"]:
|
||||||
|
if "next" in ads["response"]["pagination"]:
|
||||||
|
page += 1
|
||||||
|
for ad in self.enum_ads(page):
|
||||||
|
ads_total.append([ad[0], ad[1], ad[2]])
|
||||||
return ads_total
|
return ads_total
|
||||||
|
|
||||||
def nuke_ads(self):
|
def nuke_ads(self):
|
||||||
|
@ -194,11 +209,14 @@ class Agora(object):
|
||||||
:return: True or False
|
:return: True or False
|
||||||
:rtype: bool
|
:rtype: bool
|
||||||
"""
|
"""
|
||||||
ads = self.enum_ads()
|
ads = self.enum_ad_ids()
|
||||||
|
return_ids = []
|
||||||
if not ads:
|
if not ads:
|
||||||
return False
|
return False
|
||||||
for ad_id in ads:
|
for ad_id in ads:
|
||||||
self.agora.ad_delete(ad_id)
|
rtrn = self.agora.ad_delete(ad_id)
|
||||||
|
return_ids.append(rtrn["success"])
|
||||||
|
return all(return_ids)
|
||||||
|
|
||||||
def get_rates_all(self):
|
def get_rates_all(self):
|
||||||
"""
|
"""
|
||||||
|
@ -285,6 +303,17 @@ class Agora(object):
|
||||||
return False
|
return False
|
||||||
yield rtrn
|
yield rtrn
|
||||||
|
|
||||||
|
def get_combinations(self):
|
||||||
|
"""
|
||||||
|
Get all combinations of currencies and countries from the configuration.
|
||||||
|
:return: list of [country, currency]
|
||||||
|
:rtype: list
|
||||||
|
"""
|
||||||
|
currencies = loads(settings.Agora.BruteCurrencies)
|
||||||
|
countries = loads(settings.Agora.BruteCountries)
|
||||||
|
combinations = [[country, currency] for country in countries for currency in currencies]
|
||||||
|
return combinations
|
||||||
|
|
||||||
def dist_bruteforce(self):
|
def dist_bruteforce(self):
|
||||||
"""
|
"""
|
||||||
Bruteforce all possible ads from the currencies and countries in the config.
|
Bruteforce all possible ads from the currencies and countries in the config.
|
||||||
|
@ -292,15 +321,49 @@ class Agora(object):
|
||||||
:return: False or dict with response
|
:return: False or dict with response
|
||||||
:rtype: bool or dict
|
:rtype: bool or dict
|
||||||
"""
|
"""
|
||||||
currencies = loads(settings.Agora.BruteCurrencies)
|
combinations = self.get_combinations()
|
||||||
countries = loads(settings.Agora.BruteCountries)
|
|
||||||
combinations = [[country, currency] for country in countries for currency in currencies]
|
|
||||||
for country, currency in combinations:
|
for country, currency in combinations:
|
||||||
rtrn = self.create_ad(country, currency)
|
rtrn = self.create_ad(country, currency)
|
||||||
if not rtrn:
|
if not rtrn:
|
||||||
yield False
|
yield False
|
||||||
yield rtrn
|
yield rtrn
|
||||||
|
|
||||||
|
def bruteforce_fill_blanks(self):
|
||||||
|
"""
|
||||||
|
Get the ads that we want to configure but have not, and fill in the blanks.
|
||||||
|
:return: False or dict with response
|
||||||
|
:rtype: bool or dict
|
||||||
|
"""
|
||||||
|
existing_ads = self.enum_ads()
|
||||||
|
combinations = self.get_combinations()
|
||||||
|
for country, currency in combinations:
|
||||||
|
if not [country, currency] in existing_ads:
|
||||||
|
rtrn = self.create_ad(country, currency)
|
||||||
|
if not rtrn:
|
||||||
|
yield False
|
||||||
|
yield rtrn
|
||||||
|
|
||||||
|
def strip_duplicate_ads(self):
|
||||||
|
"""
|
||||||
|
Remove duplicate ads.
|
||||||
|
:return: list of duplicate ads
|
||||||
|
:rtype: list
|
||||||
|
"""
|
||||||
|
existing_ads = self.enum_ads()
|
||||||
|
_size = len(existing_ads)
|
||||||
|
repeated = []
|
||||||
|
for i in range(_size):
|
||||||
|
k = i + 1
|
||||||
|
for j in range(k, _size):
|
||||||
|
if existing_ads[i] == existing_ads[j] and existing_ads[i] not in repeated:
|
||||||
|
repeated.append(existing_ads[i])
|
||||||
|
|
||||||
|
actioned = []
|
||||||
|
for ad_id, country, currency in repeated:
|
||||||
|
rtrn = self.agora.ad_delete(ad_id)
|
||||||
|
actioned.append(rtrn["success"])
|
||||||
|
return all(actioned)
|
||||||
|
|
||||||
def release_funds(self, contact_id):
|
def release_funds(self, contact_id):
|
||||||
"""
|
"""
|
||||||
Release funds for a contact_id.
|
Release funds for a contact_id.
|
||||||
|
|
|
@ -93,7 +93,28 @@ class IRCCommands(object):
|
||||||
if x["success"]:
|
if x["success"]:
|
||||||
msg(f"{x['response']['data']['message']}: {x['response']['data']['ad_id']}")
|
msg(f"{x['response']['data']['message']}: {x['response']['data']['ad_id']}")
|
||||||
else:
|
else:
|
||||||
msg(x["response"]["data"]["message"])
|
msg(dumps(x))
|
||||||
|
|
||||||
|
class fillblanks(object):
|
||||||
|
name = "fillblanks"
|
||||||
|
authed = True
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def run(cmd, spl, length, authed, msg, agora, revolut, tx):
|
||||||
|
for x in agora.bruteforce_fill_blanks():
|
||||||
|
if x["success"]:
|
||||||
|
msg(f"{x['response']['data']['message']}: {x['response']['data']['ad_id']}")
|
||||||
|
else:
|
||||||
|
msg(dumps(x))
|
||||||
|
|
||||||
|
class stripdupes(object):
|
||||||
|
name = "stripdupes"
|
||||||
|
authed = True
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def run(cmd, spl, length, authed, msg, agora, revolut, tx):
|
||||||
|
rtrn = agora.strip_duplicate_ads()
|
||||||
|
msg(dumps(rtrn))
|
||||||
|
|
||||||
class find(object):
|
class find(object):
|
||||||
name = "find"
|
name = "find"
|
||||||
|
|
Loading…
Reference in New Issue