[mod] add /engine_descriptions.json endpoint

returns engine descriptions (JSON):
* key: engine name
* value: description in the user locale, use English description as a fallback
This commit is contained in:
Alexandre Flament 2021-09-18 10:59:56 +02:00
parent f8d5fe0f11
commit bfd24d1226
3 changed files with 3802 additions and 0 deletions

View file

@ -14,6 +14,7 @@ __all__ = [
'WIKIDATA_UNITS', 'WIKIDATA_UNITS',
'EXTERNAL_BANGS', 'EXTERNAL_BANGS',
'OSM_KEYS_TAGS', 'OSM_KEYS_TAGS',
'ENGINE_DESCRIPTIONS',
'ahmia_blacklist_loader', 'ahmia_blacklist_loader',
] ]
@ -45,3 +46,4 @@ EXTERNAL_URLS = _load('external_urls.json')
WIKIDATA_UNITS = _load('wikidata_units.json') WIKIDATA_UNITS = _load('wikidata_units.json')
EXTERNAL_BANGS = _load('external_bangs.json') EXTERNAL_BANGS = _load('external_bangs.json')
OSM_KEYS_TAGS = _load('osm_keys_tags.json') OSM_KEYS_TAGS = _load('osm_keys_tags.json')
ENGINE_DESCRIPTIONS = _load('engine_descriptions.json')

File diff suppressed because it is too large Load diff

View file

@ -54,6 +54,7 @@ from searx import (
settings, settings,
searx_debug, searx_debug,
) )
from searx.data import ENGINE_DESCRIPTIONS
from searx.settings_defaults import OUTPUT_FORMATS from searx.settings_defaults import OUTPUT_FORMATS
from searx.settings_loader import get_default_settings_path from searx.settings_loader import get_default_settings_path
from searx.exceptions import SearxParameterException from searx.exceptions import SearxParameterException
@ -1140,6 +1141,23 @@ def image_proxy():
return '', 400 return '', 400
@app.route('/engine_descriptions.json', methods=['GET'])
def engine_descriptions():
locale = get_locale().split('_')[0]
result = ENGINE_DESCRIPTIONS['en'].copy()
if locale != 'en':
for engine, description in ENGINE_DESCRIPTIONS.get(locale, {}).items():
result[engine] = description
for engine, description in result.items():
if len(description) ==2 and description[1] == 'ref':
ref_engine, ref_lang = description[0].split(':')
description = ENGINE_DESCRIPTIONS[ref_lang][ref_engine]
if isinstance(description, str):
description = [ description, 'wikipedia' ]
result[engine] = description
return jsonify(result)
@app.route('/stats', methods=['GET']) @app.route('/stats', methods=['GET'])
def stats(): def stats():
"""Render engine statistics page.""" """Render engine statistics page."""