diff --git a/handler/agora.py b/handler/agora.py index 3420303..2afcc62 100644 --- a/handler/agora.py +++ b/handler/agora.py @@ -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 = {} - messages = self.agora.recent_messages() + try: + messages = self.agora.recent_messages() + except ReadError: + return False if not messages["success"]: return False if "data" not in messages["response"]: @@ -487,23 +490,24 @@ class Agora(object): # Remove extra tabs ad = ad.replace("\\t", "\t") - form = {"country_code": countrycode, - "currency": currency, - "trade_type": "ONLINE_SELL", - "asset": asset, - "price_equation": price_formula, - "track_max_amount": False, - "require_trusted_by_advertiser": False, - "online_provider": "REVOLUT", - "msg": ad, - "min_amount": min_amount, - "max_amount": max_amount, - "payment_method_details": settings.Agora.PaymentMethodDetails, - "account_info": paymentdetailstext, - } + form = { + "country_code": countrycode, + "currency": currency, + "trade_type": "ONLINE_SELL", + "asset": asset, + "price_equation": price_formula, + "track_max_amount": False, + "require_trusted_by_advertiser": False, + "online_provider": "REVOLUT", + "msg": ad, + "min_amount": min_amount, + "max_amount": max_amount, + "payment_method_details": settings.Agora.PaymentMethodDetails, + "account_info": paymentdetailstext, + } # Dirty hack to test - #if asset == "BTC": + # if asset == "BTC": # del form["min_amount"] ad = self.agora.ad_create(**form) return ad @@ -525,45 +529,45 @@ class Agora(object): return False yield rtrn - # def get_combinations(self): - # """ - # Get all combinations of currencies and countries from the configuration. - # :return: list of [country, currency] - # :rtype: list - # """ - # currencies = loads(settings.Agora.BruteCurrencies) - # countries = loads(settings.Agora.BruteCountries) - # combinations = [[country, currency] for country in countries for currency in currencies] - # return combinations + # def get_combinations(self): + # """ + # Get all combinations of currencies and countries from the configuration. + # :return: list of [country, currency] + # :rtype: list + # """ + # currencies = loads(settings.Agora.BruteCurrencies) + # countries = loads(settings.Agora.BruteCountries) + # 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): """