mirror of https://github.com/searx/searx
Merge pull request #1758 from return42/ddd-fix
[fix] duckduckgo_definitions
This commit is contained in:
commit
574cb25a16
|
@ -1,3 +1,14 @@
|
||||||
|
"""
|
||||||
|
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
|
import json
|
||||||
from lxml import html
|
from lxml import html
|
||||||
from re import compile
|
from re import compile
|
||||||
|
@ -25,7 +36,8 @@ def result_to_text(url, text, htmlResult):
|
||||||
def request(query, params):
|
def request(query, params):
|
||||||
params['url'] = url.format(query=urlencode({'q': query}))
|
params['url'] = url.format(query=urlencode({'q': query}))
|
||||||
language = match_language(params['language'], supported_languages, language_aliases)
|
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
|
||||||
return params
|
return params
|
||||||
|
|
||||||
|
|
||||||
|
@ -43,8 +55,9 @@ def response(resp):
|
||||||
|
|
||||||
# add answer if there is one
|
# add answer if there is one
|
||||||
answer = search_res.get('Answer', '')
|
answer = search_res.get('Answer', '')
|
||||||
if answer != '':
|
if answer:
|
||||||
results.append({'answer': html_to_text(answer)})
|
if search_res.get('AnswerType', '') not in ['calc']:
|
||||||
|
results.append({'answer': html_to_text(answer)})
|
||||||
|
|
||||||
# add infobox
|
# add infobox
|
||||||
if 'Definition' in search_res:
|
if 'Definition' in search_res:
|
||||||
|
|
Loading…
Reference in New Issue