Finish implementation and tests for the cheat system #3
|
@ -281,10 +281,10 @@ class Agora(object):
|
|||
return ads_total
|
||||
|
||||
@handle_exceptions
|
||||
def enum_ads(self, asset=None, page=0):
|
||||
def enum_ads(self, requested_asset=None, page=0):
|
||||
query_values = {"page": page}
|
||||
if asset:
|
||||
query_values["asset"] = asset
|
||||
if requested_asset:
|
||||
query_values["asset"] = requested_asset
|
||||
ads = self.agora._api_call(api_method="ads", query_values=query_values)
|
||||
if ads is False:
|
||||
return False
|
||||
|
@ -292,17 +292,22 @@ class Agora(object):
|
|||
if not ads["success"]:
|
||||
return False
|
||||
for ad in ads["response"]["data"]["ad_list"]:
|
||||
ads_total.append([ad["data"]["asset"], ad["data"]["ad_id"], ad["data"]["countrycode"], ad["data"]["currency"]])
|
||||
asset = ad["data"]["asset"]
|
||||
ad_id = ad["data"]["ad_id"]
|
||||
country = ad["data"]["countrycode"]
|
||||
currency = ad["data"]["currency"]
|
||||
provider = ad["data"]["online_provider"]
|
||||
ads_total.append([asset, ad_id, country, currency, provider])
|
||||
if "pagination" in ads["response"]:
|
||||
if "next" in ads["response"]["pagination"]:
|
||||
page += 1
|
||||
ads_iter = self.enum_ads(asset, page)
|
||||
ads_iter = self.enum_ads(requested_asset, page)
|
||||
if ads_iter is None:
|
||||
return False
|
||||
if ads_iter is False:
|
||||
return False
|
||||
for ad in ads_iter:
|
||||
ads_total.append([ad[0], ad[1], ad[2], ad[3]])
|
||||
ads_total.append([ad[0], ad[1], ad[2], ad[3], ad[4]])
|
||||
return ads_total
|
||||
|
||||
def last_online_recent(self, date):
|
||||
|
@ -320,12 +325,20 @@ class Agora(object):
|
|||
return sec_ago_date < 172800
|
||||
|
||||
@handle_exceptions
|
||||
def enum_public_ads(self, coin, currency, page=0):
|
||||
def enum_public_ads(self, coin, currency, providers=None, page=0):
|
||||
# buy-monero-online, buy-bitcoin-online
|
||||
# Work around Agora weirdness calling it bitcoins
|
||||
if coin == "bitcoin":
|
||||
coin = "bitcoins"
|
||||
ads = self.agora._api_call(api_method=f"buy-{coin}-online/{currency}/REVOLUT", query_values={"page": page})
|
||||
if not providers:
|
||||
print("NO PROVIDERS")
|
||||
ads = self.agora._api_call(api_method=f"buy-{coin}-online/{currency}/REVOLUT", query_values={"page": page})
|
||||
elif len(providers) == 1:
|
||||
print("one provider")
|
||||
ads = self.agora._api_call(api_method=f"buy-{coin}-online/{currency}/providers[0]", query_values={"page": page})
|
||||
elif len(providers) > 1:
|
||||
print("more than one provider")
|
||||
ads = self.agora._api_call(api_method=f"buy-{coin}-online/{currency}", query_values={"page": page})
|
||||
if ads is None:
|
||||
return False
|
||||
if ads is False:
|
||||
|
@ -333,24 +346,39 @@ class Agora(object):
|
|||
if "data" not in ads["response"]:
|
||||
return False
|
||||
for ad in ads["response"]["data"]["ad_list"]:
|
||||
if ad["data"]["online_provider"] == "REVOLUT":
|
||||
date_last_seen = ad["data"]["profile"]["last_online"]
|
||||
# Check if this person was seen recently
|
||||
if not self.last_online_recent(date_last_seen):
|
||||
print(ad["data"]["online_provider"])
|
||||
if not providers:
|
||||
print("not providers")
|
||||
if not ad["data"]["online_provider"] == "REVOLUT":
|
||||
print("provider is not revolut")
|
||||
continue
|
||||
yield [ad["data"]["ad_id"], ad["data"]["profile"]["username"], ad["data"]["temp_price"]]
|
||||
else:
|
||||
print("yes providers")
|
||||
if ad["data"]["online_provider"] not in providers:
|
||||
print("provider not in asked")
|
||||
continue
|
||||
date_last_seen = ad["data"]["profile"]["last_online"]
|
||||
# Check if this person was seen recently
|
||||
if not self.last_online_recent(date_last_seen):
|
||||
continue
|
||||
ad_id = ad["data"]["ad_id"]
|
||||
username = ad["data"]["profile"]["username"]
|
||||
temp_price = ad["data"]["temp_price"]
|
||||
provider = ad["data"]["online_provider"]
|
||||
print(ad_id, username, temp_price, provider)
|
||||
yield [ad_id, username, temp_price, provider]
|
||||
if "pagination" in ads["response"]:
|
||||
if "next" in ads["response"]["pagination"]:
|
||||
page += 1
|
||||
ads_iter = self.enum_public_ads(coin, currency, page)
|
||||
ads_iter = self.enum_public_ads(coin, currency, providers, page)
|
||||
if ads_iter is None:
|
||||
return False
|
||||
if ads_iter is False:
|
||||
return False
|
||||
for ad in ads_iter:
|
||||
yield [ad[0], ad[1], ad[2]]
|
||||
yield [ad[0], ad[1], ad[2], ad[3]]
|
||||
|
||||
def wrap_public_ads(self, asset, currency, rates=None):
|
||||
def wrap_public_ads(self, asset, currency, providers=None, rates=None):
|
||||
"""
|
||||
Wrapper to sort public ads.
|
||||
"""
|
||||
|
@ -358,11 +386,11 @@ class Agora(object):
|
|||
coin = "monero"
|
||||
elif asset == "BTC":
|
||||
coin = "bitcoin"
|
||||
ads_obj = self.enum_public_ads(coin, currency.upper())
|
||||
if ads_obj is False:
|
||||
ads = self.enum_public_ads(coin, currency.upper(), providers)
|
||||
if ads is False:
|
||||
return False
|
||||
ads = list(ads_obj)
|
||||
if ads_obj is False:
|
||||
# ads = list(ads_obj)
|
||||
if ads is False:
|
||||
return False
|
||||
if not rates:
|
||||
# Set the price based on the asset
|
||||
|
@ -373,7 +401,7 @@ class Agora(object):
|
|||
price = float(ad[2])
|
||||
rate = round(price / base_currency_price, 2)
|
||||
ad.append(rate)
|
||||
return ads
|
||||
return sorted(ads, key=lambda x: x[2])
|
||||
|
||||
def _update_prices(self, xmr=None, btc=None):
|
||||
"""
|
||||
|
@ -644,7 +672,7 @@ class Agora(object):
|
|||
return (min_local, max_local)
|
||||
|
||||
@handle_exceptions
|
||||
def create_ad(self, asset, countrycode, currency, online_provider):
|
||||
def create_ad(self, asset, countrycode, currency, provider):
|
||||
"""
|
||||
Post an ad with the given asset in a country with a given currency.
|
||||
Convert the min and max amounts from settings to the given currency with CurrencyRates.
|
||||
|
@ -699,7 +727,7 @@ class Agora(object):
|
|||
"price_equation": price_formula,
|
||||
"track_max_amount": False,
|
||||
"require_trusted_by_advertiser": False,
|
||||
"online_provider": online_provider,
|
||||
"online_provider": provider,
|
||||
"msg": ad,
|
||||
"min_amount": min_amount,
|
||||
"max_amount": max_amount,
|
||||
|
|
|
@ -346,7 +346,17 @@ class IRCCommands(object):
|
|||
currency = spl[2]
|
||||
rtrn = agora.wrap_public_ads(asset, currency)
|
||||
for ad in rtrn:
|
||||
msg(f"({ad[0]}) {ad[1]} {ad[2]} {ad[3]}")
|
||||
msg(f"({ad[0]}) {ad[1]} {ad[2]} {ad[4]}")
|
||||
elif length == 4:
|
||||
asset = spl[1]
|
||||
if asset not in loads(settings.Agora.AssetList):
|
||||
msg(f"Not a valid asset: {spl[1]}")
|
||||
return
|
||||
providers = spl[3].split(",")
|
||||
currency = spl[2]
|
||||
rtrn = agora.wrap_public_ads(asset, currency, providers)
|
||||
for ad in rtrn:
|
||||
msg(f"({ad[0]}) {ad[1]} {ad[2]} {ad[3]} {ad[4]}")
|
||||
|
||||
class cheat(object):
|
||||
name = "cheat"
|
||||
|
@ -392,7 +402,7 @@ class IRCCommands(object):
|
|||
def run(cmd, spl, length, authed, msg, agora, revolut, tx, notify):
|
||||
ads = agora.enum_ads()
|
||||
for ad in ads:
|
||||
msg(f"({ad[0]}) {ad[1]} {ad[2]} {ad[3]}")
|
||||
msg(f"({ad[0]}) {ad[1]} {ad[2]} {ad[3]} {ad[4]}")
|
||||
|
||||
class xmr(object):
|
||||
name = "xmr"
|
||||
|
|
Loading…
Reference in New Issue