summaryrefslogtreecommitdiff
path: root/searx/engines/wolframalpha_api.py
diff options
context:
space:
mode:
Diffstat (limited to 'searx/engines/wolframalpha_api.py')
-rw-r--r--searx/engines/wolframalpha_api.py23
1 files changed, 14 insertions, 9 deletions
diff --git a/searx/engines/wolframalpha_api.py b/searx/engines/wolframalpha_api.py
index d61d25747..540d81351 100644
--- a/searx/engines/wolframalpha_api.py
+++ b/searx/engines/wolframalpha_api.py
@@ -14,7 +14,11 @@ from lxml import etree
# search-url
base_url = 'http://api.wolframalpha.com/v2/query'
search_url = base_url + '?appid={api_key}&{query}&format=plaintext'
-api_key = ''
+api_key = '' # defined in settings.yml
+
+# xpath variables
+failure_xpath = '/queryresult[attribute::success="false"]'
+answer_xpath = '//pod[attribute::primary="true"]/subpod/plaintext'
# do search-request
@@ -45,16 +49,17 @@ def response(resp):
search_results = etree.XML(resp.content)
# return empty array if there are no results
- if search_results.xpath('/queryresult[attribute::success="false"]'):
+ if search_results.xpath(failure_xpath):
return []
- # parse result
- result = search_results.xpath('//pod[attribute::primary="true"]/subpod/plaintext')[0].text
- result = replace_pua_chars(result)
+ # parse answers
+ answers = search_results.xpath(answer_xpath)
+ if answers:
+ for answer in answers:
+ answer = replace_pua_chars(answer.text)
+
+ results.append({'answer': answer})
- # append result
- # TODO: shouldn't it bind the source too?
- results.append({'answer': result})
+ # TODO: append a result with title and link, like in the no api version
- # return results
return results