Libraries refactor and add some sinks #4
|
@ -281,10 +281,10 @@ class Agora(object):
|
||||||
return ads_total
|
return ads_total
|
||||||
|
|
||||||
@handle_exceptions
|
@handle_exceptions
|
||||||
def enum_ads(self, asset=None, page=0):
|
def enum_ads(self, requested_asset=None, page=0):
|
||||||
query_values = {"page": page}
|
query_values = {"page": page}
|
||||||
if asset:
|
if requested_asset:
|
||||||
query_values["asset"] = asset
|
query_values["asset"] = requested_asset
|
||||||
ads = self.agora._api_call(api_method="ads", query_values=query_values)
|
ads = self.agora._api_call(api_method="ads", query_values=query_values)
|
||||||
if ads is False:
|
if ads is False:
|
||||||
return False
|
return False
|
||||||
|
@ -292,17 +292,22 @@ class Agora(object):
|
||||||
if not ads["success"]:
|
if not ads["success"]:
|
||||||
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"]["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 "pagination" in ads["response"]:
|
||||||
if "next" in ads["response"]["pagination"]:
|
if "next" in ads["response"]["pagination"]:
|
||||||
page += 1
|
page += 1
|
||||||
ads_iter = self.enum_ads(asset, page)
|
ads_iter = self.enum_ads(requested_asset, page)
|
||||||
if ads_iter is None:
|
if ads_iter is None:
|
||||||
return False
|
return False
|
||||||
if ads_iter is False:
|
if ads_iter is False:
|
||||||
return False
|
return False
|
||||||
for ad in ads_iter:
|
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
|
return ads_total
|
||||||
|
|
||||||
def last_online_recent(self, date):
|
def last_online_recent(self, date):
|
||||||
|
@ -320,12 +325,20 @@ class Agora(object):
|
||||||
return sec_ago_date < 172800
|
return sec_ago_date < 172800
|
||||||
|
|
||||||
@handle_exceptions
|
@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
|
# buy-monero-online, buy-bitcoin-online
|
||||||
# Work around Agora weirdness calling it bitcoins
|
# Work around Agora weirdness calling it bitcoins
|
||||||
if coin == "bitcoin":
|
if coin == "bitcoin":
|
||||||
coin = "bitcoins"
|
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:
|
if ads is None:
|
||||||
return False
|
return False
|
||||||
if ads is False:
|
if ads is False:
|
||||||
|
@ -333,24 +346,39 @@ class Agora(object):
|
||||||
if "data" not in ads["response"]:
|
if "data" not in ads["response"]:
|
||||||
return False
|
return False
|
||||||
for ad in ads["response"]["data"]["ad_list"]:
|
for ad in ads["response"]["data"]["ad_list"]:
|
||||||
if ad["data"]["online_provider"] == "REVOLUT":
|
print(ad["data"]["online_provider"])
|
||||||
date_last_seen = ad["data"]["profile"]["last_online"]
|
if not providers:
|
||||||
# Check if this person was seen recently
|
print("not providers")
|
||||||
if not self.last_online_recent(date_last_seen):
|
if not ad["data"]["online_provider"] == "REVOLUT":
|
||||||
|
print("provider is not revolut")
|
||||||
continue
|
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 "pagination" in ads["response"]:
|
||||||
if "next" in ads["response"]["pagination"]:
|
if "next" in ads["response"]["pagination"]:
|
||||||
page += 1
|
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:
|
if ads_iter is None:
|
||||||
return False
|
return False
|
||||||
if ads_iter is False:
|
if ads_iter is False:
|
||||||
return False
|
return False
|
||||||
for ad in ads_iter:
|
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.
|
Wrapper to sort public ads.
|
||||||
"""
|
"""
|
||||||
|
@ -358,11 +386,11 @@ class Agora(object):
|
||||||
coin = "monero"
|
coin = "monero"
|
||||||
elif asset == "BTC":
|
elif asset == "BTC":
|
||||||
coin = "bitcoin"
|
coin = "bitcoin"
|
||||||
ads_obj = self.enum_public_ads(coin, currency.upper())
|
ads = self.enum_public_ads(coin, currency.upper(), providers)
|
||||||
if ads_obj is False:
|
if ads is False:
|
||||||
return False
|
return False
|
||||||
ads = list(ads_obj)
|
# ads = list(ads_obj)
|
||||||
if ads_obj is False:
|
if ads is False:
|
||||||
return False
|
return False
|
||||||
if not rates:
|
if not rates:
|
||||||
# Set the price based on the asset
|
# Set the price based on the asset
|
||||||
|
@ -373,7 +401,7 @@ class Agora(object):
|
||||||
price = float(ad[2])
|
price = float(ad[2])
|
||||||
rate = round(price / base_currency_price, 2)
|
rate = round(price / base_currency_price, 2)
|
||||||
ad.append(rate)
|
ad.append(rate)
|
||||||
return ads
|
return sorted(ads, key=lambda x: x[2])
|
||||||
|
|
||||||
def _update_prices(self, xmr=None, btc=None):
|
def _update_prices(self, xmr=None, btc=None):
|
||||||
"""
|
"""
|
||||||
|
@ -644,7 +672,7 @@ class Agora(object):
|
||||||
return (min_local, max_local)
|
return (min_local, max_local)
|
||||||
|
|
||||||
@handle_exceptions
|
@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.
|
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.
|
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,
|
"price_equation": price_formula,
|
||||||
"track_max_amount": False,
|
"track_max_amount": False,
|
||||||
"require_trusted_by_advertiser": False,
|
"require_trusted_by_advertiser": False,
|
||||||
"online_provider": online_provider,
|
"online_provider": provider,
|
||||||
"msg": ad,
|
"msg": ad,
|
||||||
"min_amount": min_amount,
|
"min_amount": min_amount,
|
||||||
"max_amount": max_amount,
|
"max_amount": max_amount,
|
||||||
|
|
|
@ -346,7 +346,17 @@ class IRCCommands(object):
|
||||||
currency = spl[2]
|
currency = spl[2]
|
||||||
rtrn = agora.wrap_public_ads(asset, currency)
|
rtrn = agora.wrap_public_ads(asset, currency)
|
||||||
for ad in rtrn:
|
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):
|
class cheat(object):
|
||||||
name = "cheat"
|
name = "cheat"
|
||||||
|
@ -392,7 +402,7 @@ class IRCCommands(object):
|
||||||
def run(cmd, spl, length, authed, msg, agora, revolut, tx, notify):
|
def run(cmd, spl, length, authed, msg, agora, revolut, tx, notify):
|
||||||
ads = agora.enum_ads()
|
ads = agora.enum_ads()
|
||||||
for ad in 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):
|
class xmr(object):
|
||||||
name = "xmr"
|
name = "xmr"
|
||||||
|
|
Loading…
Reference in New Issue