mirror of
https://github.com/searxng/searxng
synced 2024-11-09 01:10:26 +00:00
Merge branch 'wolframalpha'
This commit is contained in:
commit
5b0e785bbb
@ -16,31 +16,30 @@ from searx.utils import html_to_text
|
|||||||
# search-url
|
# search-url
|
||||||
base_url = 'http://api.wolframalpha.com/v2/query'
|
base_url = 'http://api.wolframalpha.com/v2/query'
|
||||||
search_url = base_url + '?appid={api_key}&{query}&format=plaintext'
|
search_url = base_url + '?appid={api_key}&{query}&format=plaintext'
|
||||||
site_url = 'http://wolframalpha.com/input/?{query}'
|
api_key = ''
|
||||||
|
|
||||||
|
|
||||||
# do search-request
|
# do search-request
|
||||||
def request(query, params):
|
def request(query, params):
|
||||||
params['url'] = search_url.format(query=urlencode({'input': query}),
|
params['url'] = search_url.format(query=urlencode({'input': query}),
|
||||||
api_key=api_key)
|
api_key=api_key)
|
||||||
|
|
||||||
# need this for url in response
|
|
||||||
global my_query
|
|
||||||
my_query = query
|
|
||||||
|
|
||||||
return params
|
return params
|
||||||
|
|
||||||
|
|
||||||
# replace private user area characters to make text legible
|
# replace private user area characters to make text legible
|
||||||
def replace_pua_chars(text):
|
def replace_pua_chars(text):
|
||||||
pua_chars = { u'\uf74c': 'd',
|
pua_chars = {u'\uf74c': 'd',
|
||||||
u'\uf74d': u'\u212f',
|
u'\uf74d': u'\u212f',
|
||||||
u'\uf74e': 'i',
|
u'\uf74e': 'i',
|
||||||
u'\uf7d9': '=' }
|
u'\uf7d9': '='}
|
||||||
|
|
||||||
for k, v in pua_chars.iteritems():
|
for k, v in pua_chars.iteritems():
|
||||||
text = text.replace(k, v)
|
text = text.replace(k, v)
|
||||||
|
|
||||||
return text
|
return text
|
||||||
|
|
||||||
|
|
||||||
# get response from search-request
|
# get response from search-request
|
||||||
def response(resp):
|
def response(resp):
|
||||||
results = []
|
results = []
|
||||||
@ -55,13 +54,9 @@ def response(resp):
|
|||||||
result = search_results.xpath('//pod[attribute::primary="true"]/subpod/plaintext')[0].text
|
result = search_results.xpath('//pod[attribute::primary="true"]/subpod/plaintext')[0].text
|
||||||
result = replace_pua_chars(result)
|
result = replace_pua_chars(result)
|
||||||
|
|
||||||
# bind url from site
|
|
||||||
result_url = site_url.format(query=urlencode({'i': my_query}))
|
|
||||||
|
|
||||||
# append result
|
# append result
|
||||||
# TODO: shouldn't it bind the source too?
|
# TODO: shouldn't it bind the source too?
|
||||||
results.append({'url': result_url,
|
results.append({'answer': result})
|
||||||
'answer': result})
|
|
||||||
|
|
||||||
# return results
|
# return results
|
||||||
return results
|
return results
|
||||||
|
Loading…
Reference in New Issue
Block a user