|
|
|
@ -182,23 +182,41 @@ class Agora(object):
|
|
|
|
|
return False
|
|
|
|
|
for ad in ads["response"]["data"]["ad_list"]:
|
|
|
|
|
ads_total.append(ad["data"]["ad_id"])
|
|
|
|
|
if "pagination" in ads["response"]:
|
|
|
|
|
if "next" in ads["response"]["pagination"]:
|
|
|
|
|
page += 1
|
|
|
|
|
for ad in self.enum_ads(page):
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
def nuke_ads(self):
|
|
|
|
|
"""
|
|
|
|
|
Delete all of our adverts.
|
|
|
|
|
:return: True or False
|
|
|
|
|
:rtype: bool
|
|
|
|
|
"""
|
|
|
|
|
ads = self.enum_ads()
|
|
|
|
|
ads = self.enum_ad_ids()
|
|
|
|
|
return_ids = []
|
|
|
|
|
if not ads:
|
|
|
|
|
return False
|
|
|
|
|
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):
|
|
|
|
|
"""
|
|
|
|
@ -285,6 +303,17 @@ class Agora(object):
|
|
|
|
|
return False
|
|
|
|
|
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):
|
|
|
|
|
"""
|
|
|
|
|
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
|
|
|
|
|
:rtype: bool or dict
|
|
|
|
|
"""
|
|
|
|
|
currencies = loads(settings.Agora.BruteCurrencies)
|
|
|
|
|
countries = loads(settings.Agora.BruteCountries)
|
|
|
|
|
combinations = [[country, currency] for country in countries for currency in currencies]
|
|
|
|
|
combinations = self.get_combinations()
|
|
|
|
|
for country, currency in combinations:
|
|
|
|
|
rtrn = self.create_ad(country, currency)
|
|
|
|
|
if not rtrn:
|
|
|
|
|
yield False
|
|
|
|
|
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):
|
|
|
|
|
"""
|
|
|
|
|
Release funds for a contact_id.
|
|
|
|
|