logger = logging.getLogger(__name__)
-
if not hasattr(json, 'JSONDecodeError'):
json.JSONDecodeError = ValueError
def __init__(self, actionqueue):
super().__init__(actionqueue)
- self.search_list = self.fetch_all_searx_engines()
+ try:
+ self.search_list = self.fetch_all_searx_engines()
+ except RuntimeError as e:
+ # will eventually fix itself
+ logger.exception(e)
+ pass
@staticmethod
def fetch_all_searx_engines():
- # response = requests.get("http://stats.searx.oe5tpo.com")
- response = requests.get("https://stats.searx.xyz")
+ response = requests.get("https://searx.space/data/instances.json")
response.raise_for_status()
- tree = etree.XML(
- response.content,
- parser=html.HTMLParser()
- )
- searxes = [str(x) for x in tree.xpath('//span[text()[contains(.,"200 - OK")]]/../..//a/text()') if
- str(x).startswith("http")]
+ searxes = [url for (url, details) in response.json().get("instances").items() if
+ details.get("error") is None and details.get("network_type") != "tor"]
logger.info("Registered {} searxes".format(len(searxes)))
if not searxes:
raise RuntimeError("not a single searx discovered... " + str(response.content))