2021-01-05 10:24:39 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
|
2020-12-24 08:28:16 +00:00
|
|
|
import sys
|
2020-12-30 14:24:29 +00:00
|
|
|
import os
|
2021-01-05 10:24:39 +00:00
|
|
|
import argparse
|
2020-12-24 08:28:16 +00:00
|
|
|
|
|
|
|
import searx.search
|
|
|
|
import searx.search.checker
|
2021-01-05 10:24:39 +00:00
|
|
|
from searx.search import processors
|
|
|
|
from searx.engines import engine_shortcuts
|
2020-12-24 08:28:16 +00:00
|
|
|
|
|
|
|
|
2020-12-30 14:24:29 +00:00
|
|
|
if sys.stdout.isatty() and os.environ.get('TERM') not in ['dumb', 'unknown']:
|
2020-12-24 08:28:16 +00:00
|
|
|
RESET_SEQ = "\033[0m"
|
|
|
|
COLOR_SEQ = "\033[1;%dm"
|
|
|
|
BOLD_SEQ = "\033[1m"
|
|
|
|
BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE = map(lambda i: COLOR_SEQ % (30 + i), range(8))
|
|
|
|
else:
|
|
|
|
RESET_SEQ = ""
|
|
|
|
COLOR_SEQ = ""
|
|
|
|
BOLD_SEQ = ""
|
|
|
|
BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE = "", "", "", "", "", "", "", ""
|
|
|
|
|
|
|
|
|
2021-01-05 10:24:39 +00:00
|
|
|
def iter_processor(engine_name_list):
|
|
|
|
if len(engine_name_list) > 0:
|
|
|
|
for name in engine_name_list:
|
|
|
|
name = engine_shortcuts.get(name, name)
|
|
|
|
processor = processors.get(name)
|
|
|
|
if processor is not None:
|
2020-12-24 08:28:16 +00:00
|
|
|
yield name, processor
|
2021-01-05 10:24:39 +00:00
|
|
|
else:
|
|
|
|
print(BOLD_SEQ, 'Engine ', '%-30s' % name, RESET_SEQ, RED, ' Not found ', RESET_SEQ)
|
2020-12-24 08:28:16 +00:00
|
|
|
else:
|
|
|
|
for name, processor in searx.search.processors.items():
|
|
|
|
yield name, processor
|
|
|
|
|
|
|
|
|
2021-01-05 10:24:39 +00:00
|
|
|
def run(engine_name_list):
|
2020-12-24 08:28:16 +00:00
|
|
|
searx.search.initialize()
|
|
|
|
broken_urls = []
|
2021-01-05 10:24:39 +00:00
|
|
|
for name, processor in iter_processor(engine_name_list):
|
2020-12-24 08:28:16 +00:00
|
|
|
if sys.stdout.isatty():
|
|
|
|
print(BOLD_SEQ, 'Engine ', '%-30s' % name, RESET_SEQ, WHITE, ' Checking', RESET_SEQ)
|
|
|
|
checker = searx.search.checker.Checker(processor)
|
|
|
|
checker.run()
|
|
|
|
if checker.test_results.succesfull:
|
|
|
|
print(BOLD_SEQ, 'Engine ', '%-30s' % name, RESET_SEQ, GREEN, ' OK', RESET_SEQ)
|
|
|
|
else:
|
|
|
|
errors = [test_name + ': ' + error for test_name, error in checker.test_results]
|
|
|
|
print(BOLD_SEQ, 'Engine ', '%-30s' % name, RESET_SEQ, RED, ' Error ', str(errors), RESET_SEQ)
|
|
|
|
|
|
|
|
broken_urls += checker.test_results.broken_urls
|
|
|
|
|
|
|
|
for url in broken_urls:
|
|
|
|
print('Error fetching', url)
|
|
|
|
|
|
|
|
|
2021-01-05 10:24:39 +00:00
|
|
|
def main():
|
|
|
|
parser = argparse.ArgumentParser(description='Check searx engines.')
|
|
|
|
parser.add_argument('engine_name_list', metavar='engine name', type=str, nargs='*',
|
|
|
|
help='engines name or shortcut list. Empty for all engines.')
|
|
|
|
args = parser.parse_args()
|
|
|
|
run(args.engine_name_list)
|
|
|
|
|
|
|
|
|
2020-12-24 08:28:16 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|