Add more checks on getting messages

This commit is contained in:
Mark Veidemanis 2022-01-25 08:43:53 +00:00
parent 0cd8c0b358
commit 483f893ffb
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
1 changed files with 59 additions and 55 deletions

View File

@ -7,7 +7,7 @@ from twisted.internet.threads import deferToThread
from json import loads
from forex_python.converter import CurrencyRates
from agoradesk_py import AgoraDesk
from httpx import ReadTimeout
from httpx import ReadTimeout, ReadError
from pycoingecko import CoinGeckoAPI
from datetime import datetime
@ -186,7 +186,10 @@ class Agora(object):
Get recent messages.
"""
messages_tmp = {}
try:
messages = self.agora.recent_messages()
except ReadError:
return False
if not messages["success"]:
return False
if "data" not in messages["response"]:
@ -487,7 +490,8 @@ class Agora(object):
# Remove extra tabs
ad = ad.replace("\\t", "\t")
form = {"country_code": countrycode,
form = {
"country_code": countrycode,
"currency": currency,
"trade_type": "ONLINE_SELL",
"asset": asset,
@ -503,7 +507,7 @@ class Agora(object):
}
# Dirty hack to test
#if asset == "BTC":
# if asset == "BTC":
# del form["min_amount"]
ad = self.agora.ad_create(**form)
return ad
@ -536,34 +540,34 @@ class Agora(object):
# combinations = [[country, currency] for country in countries for currency in currencies]
# return combinations
# def dist_bruteforce(self):
# """
# Bruteforce all possible ads from the currencies and countries in the config.
# Does not exit on errors.
# :return: False or dict with response
# :rtype: bool or dict
# """
# combinations = self.get_combinations()
# for country, currency in combinations:
# rtrn = self.create_ad(country, currency)
# if not rtrn:
# yield False
# yield rtrn
#
# def bruteforce_fill_blanks(self):
# """
# Get the ads that we want to configure but have not, and fill in the blanks.
# :return: False or dict with response
# :rtype: bool or dict
# """
# existing_ads = self.enum_ads()
# combinations = self.get_combinations()
# for country, currency in combinations:
# if not [country, currency] in existing_ads:
# rtrn = self.create_ad(country, currency)
# if not rtrn:
# yield False
# yield rtrn
# def dist_bruteforce(self):
# """
# Bruteforce all possible ads from the currencies and countries in the config.
# Does not exit on errors.
# :return: False or dict with response
# :rtype: bool or dict
# """
# combinations = self.get_combinations()
# for country, currency in combinations:
# rtrn = self.create_ad(country, currency)
# if not rtrn:
# yield False
# yield rtrn
#
# def bruteforce_fill_blanks(self):
# """
# Get the ads that we want to configure but have not, and fill in the blanks.
# :return: False or dict with response
# :rtype: bool or dict
# """
# existing_ads = self.enum_ads()
# combinations = self.get_combinations()
# for country, currency in combinations:
# if not [country, currency] in existing_ads:
# rtrn = self.create_ad(country, currency)
# if not rtrn:
# yield False
# yield rtrn
def strip_duplicate_ads(self):
"""