Libraries refactor and add some sinks #4
|
@ -30,8 +30,10 @@ def handle_exceptions(func):
|
|||
if "message" in rtrn:
|
||||
if not rtrn["success"] and rtrn["message"] == "API ERROR":
|
||||
if "error_code" in rtrn["response"]["error"]:
|
||||
log.error("API error: {code}", code=rtrn["response"]["error"]["error_code"])
|
||||
return False
|
||||
code = rtrn["response"]["error"]["error_code"]
|
||||
if not code == 136:
|
||||
log.error("API error: {code}", code=code)
|
||||
return False
|
||||
else:
|
||||
log.error("API error: {code}", code=rtrn["response"]["error"])
|
||||
return False
|
||||
|
@ -643,7 +645,7 @@ class Agora(object):
|
|||
ad = self.agora.ad_create(**form)
|
||||
return ad
|
||||
|
||||
def create_distribution_list(self):
|
||||
def create_distribution_list(self, filter_asset=None):
|
||||
"""
|
||||
Create a list for distribution of ads.
|
||||
:return: generator of asset, countrycode, currency, provider
|
||||
|
@ -655,16 +657,18 @@ class Agora(object):
|
|||
for asset in loads(settings.Agora.AssetList):
|
||||
# Iterate pairs of currency and country like EUR, GB
|
||||
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.
|
||||
Exits on errors.
|
||||
:return: False or dict with response
|
||||
: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()
|
||||
# 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]
|
||||
|
|
|
@ -95,16 +95,27 @@ class IRCCommands(object):
|
|||
class dist(object):
|
||||
name = "dist"
|
||||
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
|
||||
def run(cmd, spl, length, authed, msg, agora, revolut, tx, notify):
|
||||
# Distribute out our ad to all countries in the config
|
||||
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"]))
|
||||
if length == 2:
|
||||
asset = spl[1]
|
||||
if asset not in loads(settings.Agora.AssetList):
|
||||
msg(f"Not a valid asset: {spl[1]}")
|
||||
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):
|
||||
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]
|
||||
if to_append not in expected_return:
|
||||
expected_return.append(to_append)
|
||||
# print("expecting", to_append)
|
||||
|
||||
self.assertCountEqual(enum_ads_return, expected_return)
|
||||
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"]
|
||||
for ad in deepcopy(enum_ads_return):
|
||||
price = float(ad[2])
|
||||
margin = round(price / price_xmr, 4)
|
||||
margin = round(price / price_xmr, 2)
|
||||
ad.append(margin)
|
||||
expected_return.append(ad)
|
||||
|
||||
|
|
Loading…
Reference in New Issue