.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
searx.engines.wolframalpha_noapi Namespace Reference

Functions

 obtain_token ()
 
 init (engine_settings=None)
 
 request (query, params)
 
 response (resp)
 

Variables

dict about
 
str url = 'https://www.wolframalpha.com/'
 
tuple search_url
 
str referer_url = url + 'input/?{query}'
 
dict token = {'value': '', 'last_updated': None}
 
dict image_pods = {'VisualRepresentation', 'Illustration', 'Symbol'}
 

Detailed Description

 Wolfram|Alpha (Science)

Function Documentation

◆ init()

searx.engines.wolframalpha_noapi.init ( engine_settings = None)

Definition at line 62 of file wolframalpha_noapi.py.

62def init(engine_settings=None): # pylint: disable=unused-argument
63 obtain_token()
64
65
66# do search-request

References searx.engines.wolframalpha_noapi.obtain_token().

+ Here is the call graph for this function:

◆ obtain_token()

searx.engines.wolframalpha_noapi.obtain_token ( )

Definition at line 51 of file wolframalpha_noapi.py.

51def obtain_token():
52 update_time = time() - (time() % 3600)
53 try:
54 token_response = http_get('https://www.wolframalpha.com/input/api/v1/code?ts=9999999999999999999', timeout=2.0)
55 token['value'] = loads(token_response.text)['code']
56 token['last_updated'] = update_time
57 except: # pylint: disable=bare-except
58 pass
59 return token
60
61

Referenced by searx.engines.wolframalpha_noapi.init(), and searx.engines.wolframalpha_noapi.request().

+ Here is the caller graph for this function:

◆ request()

searx.engines.wolframalpha_noapi.request ( query,
params )

Definition at line 67 of file wolframalpha_noapi.py.

67def request(query, params):
68 # obtain token if last update was more than an hour
69 if time() - (token['last_updated'] or 0) > 3600:
70 obtain_token()
71 params['url'] = search_url.format(query=urlencode({'input': query}), token=token['value'])
72 params['headers']['Referer'] = referer_url.format(query=urlencode({'i': query}))
73
74 return params
75
76
77# get response from search-request

References searx.engines.wolframalpha_noapi.obtain_token().

+ Here is the call graph for this function:

◆ response()

searx.engines.wolframalpha_noapi.response ( resp)

Definition at line 78 of file wolframalpha_noapi.py.

78def response(resp):
79 results = []
80
81 resp_json = loads(resp.text)
82
83 if not resp_json['queryresult']['success']:
84 return []
85
86 # handle resp_json['queryresult']['assumptions']?
87 result_chunks = []
88 infobox_title = ""
89 result_content = ""
90 for pod in resp_json['queryresult']['pods']:
91 pod_id = pod.get('id', '')
92 pod_title = pod.get('title', '')
93 pod_is_result = pod.get('primary', None)
94
95 if 'subpods' not in pod:
96 continue
97
98 if pod_id == 'Input' or not infobox_title:
99 infobox_title = pod['subpods'][0]['plaintext']
100
101 for subpod in pod['subpods']:
102 if subpod['plaintext'] != '' and pod_id not in image_pods:
103 # append unless it's not an actual answer
104 if subpod['plaintext'] != '(requires interactivity)':
105 result_chunks.append({'label': pod_title, 'value': subpod['plaintext']})
106
107 if pod_is_result or not result_content:
108 if pod_id != "Input":
109 result_content = pod_title + ': ' + subpod['plaintext']
110
111 elif 'img' in subpod:
112 result_chunks.append({'label': pod_title, 'image': subpod['img']})
113
114 if not result_chunks:
115 return []
116
117 results.append(
118 {
119 'infobox': infobox_title,
120 'attributes': result_chunks,
121 'urls': [{'title': 'Wolfram|Alpha', 'url': resp.request.headers['Referer']}],
122 }
123 )
124
125 results.append(
126 {
127 'url': resp.request.headers['Referer'],
128 'title': 'Wolfram|Alpha (' + infobox_title + ')',
129 'content': result_content,
130 }
131 )
132
133 return results

Variable Documentation

◆ about

dict searx.engines.wolframalpha_noapi.about
Initial value:
1= {
2 "website": 'https://www.wolframalpha.com/',
3 "wikidata_id": 'Q207006',
4 "official_api_documentation": 'https://products.wolframalpha.com/api/',
5 "use_official_api": False,
6 "require_api_key": False,
7 "results": 'JSON',
8}

Definition at line 13 of file wolframalpha_noapi.py.

◆ image_pods

dict searx.engines.wolframalpha_noapi.image_pods = {'VisualRepresentation', 'Illustration', 'Symbol'}

Definition at line 47 of file wolframalpha_noapi.py.

◆ referer_url

str searx.engines.wolframalpha_noapi.referer_url = url + 'input/?{query}'

Definition at line 41 of file wolframalpha_noapi.py.

◆ search_url

tuple searx.engines.wolframalpha_noapi.search_url
Initial value:
1= (
2 url + 'input/json.jsp'
3 '?async=false'
4 '&banners=raw'
5 '&debuggingdata=false'
6 '&format=image,plaintext,imagemap,minput,moutput'
7 '&formattimeout=2'
8 '&{query}'
9 '&output=JSON'
10 '&parsetimeout=2'
11 '&proxycode={token}'
12 '&scantimeout=0.5'
13 '&sponsorcategories=true'
14 '&statemethod=deploybutton'
15)

Definition at line 25 of file wolframalpha_noapi.py.

◆ token

dict searx.engines.wolframalpha_noapi.token = {'value': '', 'last_updated': None}

Definition at line 43 of file wolframalpha_noapi.py.

◆ url

str searx.engines.wolframalpha_noapi.url = 'https://www.wolframalpha.com/'

Definition at line 23 of file wolframalpha_noapi.py.