summaryrefslogtreecommitdiff
path: root/searx/engines/currency_convert.py
diff options
context:
space:
mode:
authorMarkus Heiser <markus.heiser@darmarit.de>2025-09-11 19:10:27 +0200
committerMarkus Heiser <markus.heiser@darmarIT.de>2025-09-18 19:40:03 +0200
commit8f8343dc0d78bb57215afc3e99fd9000fce6e0cf (patch)
tree7c0aa8587ed4bc47e403b4148a308191e2d21c55 /searx/engines/currency_convert.py
parent23257bddce864cfc44d64324dee36b32b1cf5248 (diff)
[mod] addition of various type hints / engine processors
Continuation of #5147 .. typification of the engine processors. BTW: - removed obsolete engine property https_support - fixed & improved currency_convert - engine instances can now implement a engine.setup method [#5147] https://github.com/searxng/searxng/pull/5147 Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
Diffstat (limited to 'searx/engines/currency_convert.py')
-rw-r--r--searx/engines/currency_convert.py55
1 files changed, 30 insertions, 25 deletions
diff --git a/searx/engines/currency_convert.py b/searx/engines/currency_convert.py
index c4c757e3f..0b9b339a9 100644
--- a/searx/engines/currency_convert.py
+++ b/searx/engines/currency_convert.py
@@ -1,53 +1,58 @@
# SPDX-License-Identifier: AGPL-3.0-or-later
-"""Currency convert (DuckDuckGo)
-"""
+"""Currency convert (DuckDuckGo)"""
+import typing as t
import json
from searx.result_types import EngineResults
+if t.TYPE_CHECKING:
+ from searx.search.processors import OnlineCurrenciesParams
+ from searx.extended_types import SXNG_Response
+
# about
about = {
- "website": 'https://duckduckgo.com/',
- "wikidata_id": 'Q12805',
- "official_api_documentation": 'https://duckduckgo.com/api',
+ "website": "https://duckduckgo.com/",
+ "wikidata_id": "Q12805",
+ "official_api_documentation": "https://duckduckgo.com/api",
"use_official_api": False,
"require_api_key": False,
- "results": 'JSONP',
+ "results": "JSONP",
"description": "Service from DuckDuckGo.",
}
-engine_type = 'online_currency'
-categories = []
-base_url = 'https://duckduckgo.com/js/spice/currency/1/{0}/{1}'
-weight = 100
+engine_type = "online_currency"
+categories = ["currency", "general"]
+
+base_url = "https://duckduckgo.com/js/spice/currency/1/%(from_iso4217)s/%(to_iso4217)s"
+ddg_link_url = "https://duckduckgo.com/?q=%(from_iso4217)s+to+%(to_iso4217)s"
-https_support = True
+weight = 100
-def request(_query, params):
- params['url'] = base_url.format(params['from'], params['to'])
- return params
+def request(query: str, params: "OnlineCurrenciesParams") -> None: # pylint: disable=unused-argument
+ params["url"] = base_url % params
-def response(resp) -> EngineResults:
+def response(resp: "SXNG_Response") -> EngineResults:
res = EngineResults()
# remove first and last lines to get only json
- json_resp = resp.text[resp.text.find('\n') + 1 : resp.text.rfind('\n') - 2]
+ json_resp = resp.text[resp.text.find("\n") + 1 : resp.text.rfind("\n") - 2]
try:
conversion_rate = float(json.loads(json_resp)["to"][0]["mid"])
except IndexError:
return res
- answer = '{0} {1} = {2} {3}, 1 {1} ({5}) = {4} {3} ({6})'.format(
- resp.search_params['amount'],
- resp.search_params['from'],
- resp.search_params['amount'] * conversion_rate,
- resp.search_params['to'],
+
+ params: OnlineCurrenciesParams = resp.search_params # pyright: ignore[reportAssignmentType]
+ answer = "{0} {1} = {2} {3} (1 {5} : {4} {6})".format(
+ params["amount"],
+ params["from_iso4217"],
+ params["amount"] * conversion_rate,
+ params["to_iso4217"],
conversion_rate,
- resp.search_params['from_name'],
- resp.search_params['to_name'],
+ params["from_name"],
+ params["to_name"],
)
-
- url = f"https://duckduckgo.com/?q={resp.search_params['from']}+to+{resp.search_params['to']}"
+ url = ddg_link_url % params
res.add(res.types.Answer(answer=answer, url=url))
return res