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

Functions

 request (_query, params)
 
 response (resp)
 

Variables

dict about
 
str engine_type = 'online_currency'
 
list categories = []
 
str base_url = 'https://duckduckgo.com/js/spice/currency/1/{0}/{1}'
 
int weight = 100
 
bool https_support = True
 

Detailed Description

Currency convert (DuckDuckGo)

Function Documentation

◆ request()

searx.engines.currency_convert.request ( _query,
params )

Definition at line 26 of file currency_convert.py.

26def request(_query, params):
27 params['url'] = base_url.format(params['from'], params['to'])
28 return params
29
30

◆ response()

searx.engines.currency_convert.response ( resp)

Definition at line 31 of file currency_convert.py.

31def response(resp):
32 # remove first and last lines to get only json
33 json_resp = resp.text[resp.text.find('\n') + 1 : resp.text.rfind('\n') - 2]
34 try:
35 conversion_rate = float(json.loads(json_resp)["to"][0]["mid"])
36 except IndexError:
37 return []
38 answer = '{0} {1} = {2} {3}, 1 {1} ({5}) = {4} {3} ({6})'.format(
39 resp.search_params['amount'],
40 resp.search_params['from'],
41 resp.search_params['amount'] * conversion_rate,
42 resp.search_params['to'],
43 conversion_rate,
44 resp.search_params['from_name'],
45 resp.search_params['to_name'],
46 )
47
48 url = f"https://duckduckgo.com/?q={resp.search_params['from']}+to+{resp.search_params['to']}"
49
50 return [{"answer": answer, "url": url}]

References searx.format.

Variable Documentation

◆ about

dict searx.engines.currency_convert.about
Initial value:
1= {
2 "website": 'https://duckduckgo.com/',
3 "wikidata_id": 'Q12805',
4 "official_api_documentation": 'https://duckduckgo.com/api',
5 "use_official_api": False,
6 "require_api_key": False,
7 "results": 'JSONP',
8 "description": "Service from DuckDuckGo.",
9}

Definition at line 8 of file currency_convert.py.

◆ base_url

str searx.engines.currency_convert.base_url = 'https://duckduckgo.com/js/spice/currency/1/{0}/{1}'

Definition at line 20 of file currency_convert.py.

◆ categories

list searx.engines.currency_convert.categories = []

Definition at line 19 of file currency_convert.py.

◆ engine_type

str searx.engines.currency_convert.engine_type = 'online_currency'

Definition at line 18 of file currency_convert.py.

◆ https_support

bool searx.engines.currency_convert.https_support = True

Definition at line 23 of file currency_convert.py.

◆ weight

int searx.engines.currency_convert.weight = 100

Definition at line 21 of file currency_convert.py.