Use AgoraDesk library instead of requests
This commit is contained in:
parent
18aecc216a
commit
37b97495da
|
@ -2,9 +2,8 @@
|
|||
from twisted.logger import Logger
|
||||
|
||||
# Other library imports
|
||||
from json import dumps, loads
|
||||
from json import loads
|
||||
from simplejson.errors import JSONDecodeError
|
||||
import requests
|
||||
from forex_python.converter import CurrencyRates
|
||||
from agoradesk_py.agoradesk import AgoraDesk
|
||||
|
||||
|
@ -32,72 +31,46 @@ class Agora(object):
|
|||
return str(data.content)
|
||||
|
||||
def dashboard(self):
|
||||
rtrn = self.agora.dashboard()
|
||||
return rtrn
|
||||
dash = self.agora.dashboard_seller()
|
||||
return dash
|
||||
|
||||
def get_messages(self, contact_id):
|
||||
headers = {"Authorization": settings.Agora.Token, "Content-Type": "application/json", "User-Agent": "Agora-Py"}
|
||||
r = requests.get(f"{settings.Agora.Base}/contact_messages/{contact_id}", headers=headers)
|
||||
parsed = self.try_json(r)
|
||||
return parsed
|
||||
messages = self.agora.contact_messages(contact_id)
|
||||
return messages
|
||||
|
||||
def get_ads(self):
|
||||
headers = {"Authorization": settings.Agora.Token, "Content-Type": "application/json", "User-Agent": "Agora-Py"}
|
||||
r = requests.get(f"{settings.Agora.Base}/ads", headers=headers)
|
||||
parsed = self.try_json(r)
|
||||
return parsed
|
||||
ads = self.agora.ads()
|
||||
return ads
|
||||
|
||||
def get_rates_all(self):
|
||||
rates = self.cr.get_rates("USD")
|
||||
return rates
|
||||
|
||||
def create_ad(self, countrycode, currency):
|
||||
headers = {"Authorization": settings.Agora.Token, "Content-Type": "application/json"}
|
||||
print(dumps(headers))
|
||||
# data = {
|
||||
# "price_equation": f"coingeckoxmrusd*{settings.Agora.Margin}",
|
||||
# "countrycode": countrycode,
|
||||
# "currency": currency,
|
||||
# "msg": settings.Agora.Ad,
|
||||
# "track_max_amount": "false",
|
||||
# "online_provider": "REVOLUT",
|
||||
# "trade_type": "ONLINE_SELL",
|
||||
# "min_amount": price * float(settings.Agora.Margin),
|
||||
# # "max_amount": maxAmount,
|
||||
# "asset": "XMR",
|
||||
# "payment_method_detail": settings.Agora.PaymentMethodDetail,
|
||||
# "require_feedback_score": 0,
|
||||
# "account_info": settings.Agora.PaymentDetails,
|
||||
# }
|
||||
|
||||
priceformula = f"coingeckoxmrusdusd{currency.lower()}*{settings.Agora.Margin}"
|
||||
rates = self.get_rates_all()
|
||||
minamount = rates[currency] * float(settings.Agora.MinUSD)
|
||||
maxamount = rates[currency] * float(settings.Agora.MaxUSD)
|
||||
data = {
|
||||
"price_equation": priceformula,
|
||||
"countrycode": countrycode,
|
||||
"currency": currency,
|
||||
# "account_info": "My WeChat ID is XXXXX.",
|
||||
"msg": settings.Agora.Ad,
|
||||
# "account_info": settings.Agora.PaymentDetails,
|
||||
"track_max_amount": 0,
|
||||
"online_provider": "REVOLUT",
|
||||
"trade_type": "ONLINE_SELL",
|
||||
"min_amount": minamount,
|
||||
"max_amount": maxamount,
|
||||
"asset": "XMR",
|
||||
"payment_method_details": settings.Agora.PaymentMethodDetails,
|
||||
# "firsttimelimit_xmr": "0.5",
|
||||
# "require_feedback_score": 0,
|
||||
"require_trusted_by_advertiser": 0,
|
||||
"verified_email_required": 0,
|
||||
}
|
||||
print(dumps(data))
|
||||
r = requests.post(f"{settings.Agora.Base}/ad-create", json=dumps(data), headers=headers)
|
||||
# self.log.info(str(r.content))
|
||||
parsed = self.try_json(r)
|
||||
return parsed
|
||||
min_amount = rates[currency] * float(settings.Agora.MinUSD)
|
||||
max_amount = rates[currency] * float(settings.Agora.MaxUSD)
|
||||
price_formula = f"coingeckoxmrusd{currency.lower()}*{settings.Agora.Margin}"
|
||||
# price_formula = f"coingeckoxmrusd*{settings.Agora.Margin}"
|
||||
print("formula", price_formula)
|
||||
ad = self.agora.ad_create(
|
||||
country_code=countrycode,
|
||||
currency=currency,
|
||||
trade_type="ONLINE_SELL",
|
||||
asset="XMR",
|
||||
price_equation=price_formula,
|
||||
track_max_amount=False,
|
||||
require_trusted_by_advertiser=False,
|
||||
# verified_email_required = False,
|
||||
online_provider="REVOLUT",
|
||||
msg=settings.Agora.Ad,
|
||||
min_amount=min_amount,
|
||||
max_amount=max_amount,
|
||||
payment_method_details=settings.Agora.PaymentMethodDetails,
|
||||
# require_feedback_score = 0,
|
||||
account_info=settings.Agora.PaymentDetails,
|
||||
)
|
||||
return ad
|
||||
|
||||
def dist_countries(self):
|
||||
for currency, countrycode in loads(settings.Agora.DistList):
|
||||
|
|
Loading…
Reference in New Issue