Implement OTP and fix getting public ads

This commit is contained in:
Mark Veidemanis 2022-02-02 13:36:18 +00:00
parent b58bb1a9cd
commit 39254ef684
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
1 changed files with 17 additions and 19 deletions

View File

@ -11,6 +11,7 @@ from httpx import ReadTimeout, ReadError
from pycoingecko import CoinGeckoAPI from pycoingecko import CoinGeckoAPI
from datetime import datetime from datetime import datetime
from time import sleep from time import sleep
from pyotp import TOTP
# Project imports # Project imports
from settings import settings from settings import settings
@ -328,18 +329,15 @@ class Agora(object):
@handle_exceptions @handle_exceptions
def enum_public_ads(self, coin, currency, providers=None, page=0): def enum_public_ads(self, coin, currency, providers=None, page=0):
if not providers:
providers = ["REVOLUT"]
# 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"
if not providers: if len(providers) == 1:
print("NO PROVIDERS") ads = self.agora._api_call(api_method=f"buy-{coin}-online/{currency}/{providers[0]}", query_values={"page": page})
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: 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}) 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
@ -348,16 +346,7 @@ 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"]:
print(ad["data"]["online_provider"])
if not providers:
print("not providers")
if not ad["data"]["online_provider"] == "REVOLUT":
print("provider is not revolut")
continue
else:
print("yes providers")
if ad["data"]["online_provider"] not in providers: if ad["data"]["online_provider"] not in providers:
print("provider not in asked")
continue continue
date_last_seen = ad["data"]["profile"]["last_online"] date_last_seen = ad["data"]["profile"]["last_online"]
# Check if this person was seen recently # Check if this person was seen recently
@ -367,7 +356,6 @@ class Agora(object):
username = ad["data"]["profile"]["username"] username = ad["data"]["profile"]["username"]
temp_price = ad["data"]["temp_price"] temp_price = ad["data"]["temp_price"]
provider = ad["data"]["online_provider"] provider = ad["data"]["online_provider"]
print(ad_id, username, temp_price, provider)
yield [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"]:
@ -881,11 +869,21 @@ class Agora(object):
half_rounded = round(half, 8) half_rounded = round(half, 8)
# Read OTP secret
with open("otp.key", "r") as f:
otp_key = f.read()
f.close()
otp_key = otp_key.replace("\n", "")
# Get OTP code
otp_code = TOTP(otp_key)
# Set up the format for calling wallet_send_xmr # Set up the format for calling wallet_send_xmr
send_cast = { send_cast = {
"address": None, "address": None,
"amount": half_rounded, "amount": half_rounded,
"password": settings.Agora.Pass, "password": settings.Agora.Pass,
"otp": otp_code.now(),
} }
send_cast["address"] = settings.XMR.Wallet1 send_cast["address"] = settings.XMR.Wallet1