Use AgoraDesk library instead of requests

This commit is contained in:
Mark Veidemanis 2021-12-26 21:36:25 +00:00
parent 18aecc216a
commit 37b97495da
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
1 changed files with 30 additions and 57 deletions

View File

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