diff options
author | Markus Heiser <markus.heiser@darmarit.de> | 2019-11-29 18:56:29 +0100 |
---|---|---|
committer | Markus Heiser <markus.heiser@darmarit.de> | 2019-11-29 19:20:14 +0100 |
commit | 4998e9ec856479d0c619e54f7100c295c7c5851c (patch) | |
tree | 52fda37e52b1ec6467b33766aed8ce0f5590b22d /searx/engines/duckduckgo_definitions.py | |
parent | 8721be2f7d37b314b2ce01c29b3fbd6dc03aa3aa (diff) | |
download | searxng-4998e9ec856479d0c619e54f7100c295c7c5851c.tar.gz searxng-4998e9ec856479d0c619e54f7100c295c7c5851c.zip |
[fix] duckduckgo_definitions - where 'AnswerType' is 'calc'
Do not try to get text when 'AnswerType' is 'calc'.
Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
Diffstat (limited to 'searx/engines/duckduckgo_definitions.py')
-rw-r--r-- | searx/engines/duckduckgo_definitions.py | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/searx/engines/duckduckgo_definitions.py b/searx/engines/duckduckgo_definitions.py index 957a13ea6..2899b50fb 100644 --- a/searx/engines/duckduckgo_definitions.py +++ b/searx/engines/duckduckgo_definitions.py @@ -1,11 +1,25 @@ +""" +DuckDuckGo (definitions) + +- `Instant Answer API`_ +- `DuckDuckGo query`_ + +.. _Instant Answer API: https://duckduckgo.com/api +.. _DuckDuckGo query: https://api.duckduckgo.com/?q=DuckDuckGo&format=json&pretty=1 + +""" + import json from lxml import html from re import compile +import logging from searx.engines.xpath import extract_text from searx.engines.duckduckgo import _fetch_supported_languages, supported_languages_url, language_aliases from searx.url_utils import urlencode from searx.utils import html_to_text, match_language +logger = logging.getLogger('searx.engines.'+ __name__) + url = 'https://api.duckduckgo.com/'\ + '?{query}&format=json&pretty=0&no_redirect=1&d=1' @@ -25,7 +39,9 @@ def result_to_text(url, text, htmlResult): def request(query, params): params['url'] = url.format(query=urlencode({'q': query})) language = match_language(params['language'], supported_languages, language_aliases) - params['headers']['Accept-Language'] = language.split('-')[0] + language = language.split('-')[0] + params['headers']['Accept-Language'] = language + logger.debug("query %s: // headers: %s", params['url'], params['headers']) return params @@ -43,8 +59,9 @@ def response(resp): # add answer if there is one answer = search_res.get('Answer', '') - if answer != '': - results.append({'answer': html_to_text(answer)}) + if answer: + if search_res.get('AnswerType', '') not in ['calc']: + results.append({'answer': html_to_text(answer)}) # add infobox if 'Definition' in search_res: |