AI_Forum / tools /engine_check.py
Haster1137's picture
Upload 7519 files
57d7008 verified
Raw History Blame Contribute Delete
2.35 kB
"""Start local SearXNG, test each engine alone, print OK/FAIL per engine.
Usage: python tools\\engine_check.py engine1 engine2 ... (default: a broad list)
"""
import json, os, subprocess, sys, time, urllib.parse, urllib.request
from concurrent.futures import ThreadPoolExecutor
HERE = os.path.dirname(os.path.abspath(__file__))
SX = os.path.join(HERE, "searxng")
SRC = os.path.join(SX, "src")
BASE = "http://127.0.0.1:8888"
DEFAULT = ("google bing duckduckgo brave startpage mojeek marginalia wikipedia wikidata github "
"stackoverflow hackernews reddit qwant yahoo yandex arxiv crossref "
"wikibooks wikisource wikiquote wiktionary searchcode_code huggingface "
"'internet archive scholar' 'semantic scholar' openlibrary currency pypi npm "
"'docker hub' 'mdn' 'bing news' 'google news' 'ecosia' 'presearch' 'yep'").replace("'", "")
def one(name):
url = BASE + "/search?" + urllib.parse.urlencode(
{"q": "python", "format": "json", "engines": name})
try:
with urllib.request.urlopen(url, timeout=40) as r:
d = json.loads(r.read())
n = len(d.get("results", []))
un = d.get("unresponsive_engines")
return name, n, un
except Exception as e:
return name, -1, str(e)[:80]
def main():
names = sys.argv[1:] or [x for x in DEFAULT.split() if x]
env = dict(os.environ, SEARXNG_SETTINGS_PATH=os.path.join(SX, "settings.yml"),
PYTHONPATH=SRC + os.pathsep + os.path.join(SX, "wincompat"),
PYTHONUTF8="1", SEARXNG_PORT="8888", SEARXNG_BIND_ADDRESS="127.0.0.1")
log = open(os.path.join(HERE, "engine_check.log"), "w")
p = subprocess.Popen([os.path.join(SX, "venv", "Scripts", "python.exe"), "-m", "searx.webapp"],
cwd=SRC, env=env, stdout=log, stderr=subprocess.STDOUT)
try:
for _ in range(90):
try:
urllib.request.urlopen(BASE + "/healthz", timeout=3)
break
except Exception:
time.sleep(1)
with ThreadPoolExecutor(6) as ex:
for name, n, un in ex.map(one, names):
print(("OK " if n > 0 else "FAIL"), name, n, un or "")
finally:
p.terminate()
try:
p.wait(10)
except Exception:
p.kill()
main()