Libraries refactor and add some sinks #4
|
@ -30,8 +30,10 @@ def handle_exceptions(func):
|
||||||
if "message" in rtrn:
|
if "message" in rtrn:
|
||||||
if not rtrn["success"] and rtrn["message"] == "API ERROR":
|
if not rtrn["success"] and rtrn["message"] == "API ERROR":
|
||||||
if "error_code" in rtrn["response"]["error"]:
|
if "error_code" in rtrn["response"]["error"]:
|
||||||
log.error("API error: {code}", code=rtrn["response"]["error"]["error_code"])
|
code = rtrn["response"]["error"]["error_code"]
|
||||||
return False
|
if not code == 136:
|
||||||
|
log.error("API error: {code}", code=code)
|
||||||
|
return False
|
||||||
else:
|
else:
|
||||||
log.error("API error: {code}", code=rtrn["response"]["error"])
|
log.error("API error: {code}", code=rtrn["response"]["error"])
|
||||||
return False
|
return False
|
||||||
|
@ -643,7 +645,7 @@ class Agora(object):
|
||||||
ad = self.agora.ad_create(**form)
|
ad = self.agora.ad_create(**form)
|
||||||
return ad
|
return ad
|
||||||
|
|
||||||
def create_distribution_list(self):
|
def create_distribution_list(self, filter_asset=None):
|
||||||
"""
|
"""
|
||||||
Create a list for distribution of ads.
|
Create a list for distribution of ads.
|
||||||
:return: generator of asset, countrycode, currency, provider
|
:return: generator of asset, countrycode, currency, provider
|
||||||
|
@ -655,16 +657,18 @@ class Agora(object):
|
||||||
for asset in loads(settings.Agora.AssetList):
|
for asset in loads(settings.Agora.AssetList):
|
||||||
# Iterate pairs of currency and country like EUR, GB
|
# Iterate pairs of currency and country like EUR, GB
|
||||||
for currency, countrycode in loads(settings.Agora.DistList):
|
for currency, countrycode in loads(settings.Agora.DistList):
|
||||||
yield (asset, countrycode, currency, provider)
|
if filter_asset:
|
||||||
|
if asset == filter_asset:
|
||||||
|
yield (asset, countrycode, currency, provider)
|
||||||
|
|
||||||
def dist_countries(self):
|
def dist_countries(self, filter_asset=None):
|
||||||
"""
|
"""
|
||||||
Distribute our advert into all countries and providers listed in the config.
|
Distribute our advert into all countries and providers listed in the config.
|
||||||
Exits on errors.
|
Exits on errors.
|
||||||
:return: False or dict with response
|
:return: False or dict with response
|
||||||
:rtype: bool or dict
|
:rtype: bool or dict
|
||||||
"""
|
"""
|
||||||
dist_list = list(self.create_distribution_list())
|
dist_list = list(self.create_distribution_list(filter_asset))
|
||||||
our_ads = self.enum_ads()
|
our_ads = self.enum_ads()
|
||||||
# Let's get rid of the ad IDs and make it a tuple like dist_list
|
# Let's get rid of the ad IDs and make it a tuple like dist_list
|
||||||
our_ads = [(x[0], x[2], x[3], x[4]) for x in our_ads]
|
our_ads = [(x[0], x[2], x[3], x[4]) for x in our_ads]
|
||||||
|
|
|
@ -95,16 +95,27 @@ class IRCCommands(object):
|
||||||
class dist(object):
|
class dist(object):
|
||||||
name = "dist"
|
name = "dist"
|
||||||
authed = True
|
authed = True
|
||||||
helptext = "Distribute all our chosen currency and country ad pairs."
|
helptext = "Distribute all our chosen currency and country ad pairs. Usage: dist [<XMR/BTC>]"
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def run(cmd, spl, length, authed, msg, agora, revolut, tx, notify):
|
def run(cmd, spl, length, authed, msg, agora, revolut, tx, notify):
|
||||||
# Distribute out our ad to all countries in the config
|
# Distribute out our ad to all countries in the config
|
||||||
for x in agora.dist_countries():
|
if length == 2:
|
||||||
if x["success"]:
|
asset = spl[1]
|
||||||
msg(f"{x['response']['data']['message']}: {x['response']['data']['ad_id']}")
|
if asset not in loads(settings.Agora.AssetList):
|
||||||
else:
|
msg(f"Not a valid asset: {spl[1]}")
|
||||||
msg(dumps(x["response"]))
|
return
|
||||||
|
for x in agora.dist_countries(filter_asset=asset):
|
||||||
|
if x["success"]:
|
||||||
|
msg(f"{x['response']['data']['message']}: {x['response']['data']['ad_id']}")
|
||||||
|
else:
|
||||||
|
msg(dumps(x["response"]))
|
||||||
|
elif length == 1:
|
||||||
|
for x in agora.dist_countries():
|
||||||
|
if x["success"]:
|
||||||
|
msg(f"{x['response']['data']['message']}: {x['response']['data']['ad_id']}")
|
||||||
|
else:
|
||||||
|
msg(dumps(x["response"]))
|
||||||
|
|
||||||
class redist(object):
|
class redist(object):
|
||||||
name = "redist"
|
name = "redist"
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -161,7 +161,6 @@ class TestAgora(TestCase):
|
||||||
to_append = [ad_id, username, temp_price, provider, asset, currency]
|
to_append = [ad_id, username, temp_price, provider, asset, currency]
|
||||||
if to_append not in expected_return:
|
if to_append not in expected_return:
|
||||||
expected_return.append(to_append)
|
expected_return.append(to_append)
|
||||||
# print("expecting", to_append)
|
|
||||||
|
|
||||||
self.assertCountEqual(enum_ads_return, expected_return)
|
self.assertCountEqual(enum_ads_return, expected_return)
|
||||||
self.assertNotEqual(enum_ads_return[0][0], enum_ads_return[1][0])
|
self.assertNotEqual(enum_ads_return[0][0], enum_ads_return[1][0])
|
||||||
|
@ -187,7 +186,7 @@ class TestAgora(TestCase):
|
||||||
price_xmr = cg_prices["monero"]["usd"]
|
price_xmr = cg_prices["monero"]["usd"]
|
||||||
for ad in deepcopy(enum_ads_return):
|
for ad in deepcopy(enum_ads_return):
|
||||||
price = float(ad[2])
|
price = float(ad[2])
|
||||||
margin = round(price / price_xmr, 4)
|
margin = round(price / price_xmr, 2)
|
||||||
ad.append(margin)
|
ad.append(margin)
|
||||||
expected_return.append(ad)
|
expected_return.append(ad)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue