diff options
| author | Émilien (perso) <4016501+unixfox@users.noreply.github.com> | 2023-09-19 10:31:02 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-09-19 10:31:02 +0200 |
| commit | ad725ce7d7df5afc2fc2f63405195b6bcfc8a8a7 (patch) | |
| tree | 24a5153f321853fd5c93f2bc9c834fc551519662 /searx/engines/wikipedia.py | |
| parent | dcee82334548ad8849391b5c29cdcd868b65daad (diff) | |
wikipedia wikidata infobox + disable wikisource (#2806)
Co-authored-by: Markus Heiser <markus.heiser@darmarit.de>
Diffstat (limited to 'searx/engines/wikipedia.py')
| -rw-r--r-- | searx/engines/wikipedia.py | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/searx/engines/wikipedia.py b/searx/engines/wikipedia.py index b4b70208d..d825cbdea 100644 --- a/searx/engines/wikipedia.py +++ b/searx/engines/wikipedia.py @@ -77,6 +77,11 @@ about = { "results": 'JSON', } +display_type = ["infobox"] +"""A list of display types composed from ``infobox`` and ``list``. The latter +one will add a hit to the result list. The first one will show a hit in the +info box. Both values can be set, or one of the two can be set.""" + send_accept_language_header = True """The HTTP ``Accept-Language`` header is needed for wikis where LanguageConverter_ is enabled.""" @@ -185,18 +190,23 @@ def response(resp): api_result = resp.json() title = utils.html_to_text(api_result.get('titles', {}).get('display') or api_result.get('title')) wikipedia_link = api_result['content_urls']['desktop']['page'] - results.append({'url': wikipedia_link, 'title': title, 'content': api_result.get('description', '')}) - - if api_result.get('type') == 'standard': - results.append( - { - 'infobox': title, - 'id': wikipedia_link, - 'content': api_result.get('extract', ''), - 'img_src': api_result.get('thumbnail', {}).get('source'), - 'urls': [{'title': 'Wikipedia', 'url': wikipedia_link}], - } - ) + + if "list" in display_type or api_result.get('type') != 'standard': + # show item in the result list if 'list' is in the display options or it + # is a item that can't be displayed in a infobox. + results.append({'url': wikipedia_link, 'title': title, 'content': api_result.get('description', '')}) + + if "infobox" in display_type: + if api_result.get('type') == 'standard': + results.append( + { + 'infobox': title, + 'id': wikipedia_link, + 'content': api_result.get('extract', ''), + 'img_src': api_result.get('thumbnail', {}).get('source'), + 'urls': [{'title': 'Wikipedia', 'url': wikipedia_link}], + } + ) return results |