.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
currency_convert.py
Go to the documentation of this file.
1
# SPDX-License-Identifier: AGPL-3.0-or-later
2
"""Currency convert (DuckDuckGo)
3
"""
4
5
import
json
6
7
# about
8
about = {
9
"website"
:
'https://duckduckgo.com/'
,
10
"wikidata_id"
:
'Q12805'
,
11
"official_api_documentation"
:
'https://duckduckgo.com/api'
,
12
"use_official_api"
:
False
,
13
"require_api_key"
:
False
,
14
"results"
:
'JSONP'
,
15
"description"
:
"Service from DuckDuckGo."
,
16
}
17
18
engine_type =
'online_currency'
19
categories = []
20
base_url =
'https://duckduckgo.com/js/spice/currency/1/{0}/{1}'
21
weight = 100
22
23
https_support =
True
24
25
26
def
request
(_query, params):
27
params[
'url'
] = base_url.format(params[
'from'
], params[
'to'
])
28
return
params
29
30
31
def
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}]
searx.engines.currency_convert.request
request(_query, params)
Definition
currency_convert.py:26
searx.engines.currency_convert.response
response(resp)
Definition
currency_convert.py:31
searx.format
format
Definition
__init__.py:94
searxng
searx
engines
currency_convert.py
Generated on Sat Nov 16 2024 00:10:57 for .oO SearXNG Developer Documentation Oo. by
1.12.0