summaryrefslogtreecommitdiff
path: root/searx/engines
diff options
context:
space:
mode:
authora01200356 <a01200356@itesm.mx>2015-12-30 00:53:15 -0600
committera01200356 <a01200356@itesm.mx>2015-12-30 00:53:15 -0600
commitbe54e5269a982e272e2fe8a5064ed898373c9063 (patch)
treeb2faba6828ca1513156afa0fb762447f4fb4006d /searx/engines
parent5ed8f4da80ecd119173d7db871256be8484a9ecb (diff)
Add tests for the Wolfram Alpha engines (both API and NO API versions)
Diffstat (limited to 'searx/engines')
-rw-r--r--searx/engines/wolframalpha_api.py11
-rw-r--r--searx/engines/wolframalpha_noapi.py10
2 files changed, 13 insertions, 8 deletions
diff --git a/searx/engines/wolframalpha_api.py b/searx/engines/wolframalpha_api.py
index d61d25747..4c99eac95 100644
--- a/searx/engines/wolframalpha_api.py
+++ b/searx/engines/wolframalpha_api.py
@@ -48,13 +48,16 @@ def response(resp):
if search_results.xpath('/queryresult[attribute::success="false"]'):
return []
- # parse result
- result = search_results.xpath('//pod[attribute::primary="true"]/subpod/plaintext')[0].text
- result = replace_pua_chars(result)
+ # parse answer
+ answer = search_results.xpath('//pod[attribute::primary="true"]/subpod/plaintext')
+ if not answer:
+ return results
+
+ answer = replace_pua_chars(answer[0].text)
# append result
# TODO: shouldn't it bind the source too?
- results.append({'answer': result})
+ results.append({'answer': answer})
# return results
return results
diff --git a/searx/engines/wolframalpha_noapi.py b/searx/engines/wolframalpha_noapi.py
index 23e912a1e..9d3afe658 100644
--- a/searx/engines/wolframalpha_noapi.py
+++ b/searx/engines/wolframalpha_noapi.py
@@ -7,8 +7,8 @@
# @stable no
# @parse answer
-import re
-import json
+from re import search
+from json import loads
from urllib import urlencode
# search-url
@@ -26,6 +26,8 @@ def request(query, params):
# get response from search-request
def response(resp):
results = []
+ webpage = resp.text
+ line = None
# the answer is inside a js function
# answer can be located in different 'pods', although by default it should be in pod_0200
@@ -35,7 +37,7 @@ def response(resp):
# get line that matches the pattern
for pattern in possible_locations:
try:
- line = re.search(pattern, resp.text).group(1)
+ line = search(pattern, webpage).group(1)
break
except AttributeError:
continue
@@ -45,7 +47,7 @@ def response(resp):
# extract answer from json
answer = line[line.find('{'):line.rfind('}')+1]
- answer = json.loads(answer.encode('unicode-escape'))
+ answer = loads(answer.encode('unicode-escape'))
answer = answer['stringified'].decode('unicode-escape')
results.append({'answer': answer})