mirror of
https://github.com/searxng/searxng
synced 2024-01-01 19:24:07 +01:00
Add tests for the Wolfram Alpha engines (both API and NO API versions)
This commit is contained in:
parent
5ed8f4da80
commit
be54e5269a
5 changed files with 539 additions and 8 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue