.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
searx.search.processors.online_currency.OnlineCurrencyProcessor Class Reference
Inheritance diagram for searx.search.processors.online_currency.OnlineCurrencyProcessor:
Collaboration diagram for searx.search.processors.online_currency.OnlineCurrencyProcessor:

Public Member Functions

 initialize (self, t.Callable[["EngineProcessor", bool], bool] callback)
OnlineCurrenciesParams|None get_params (self, "SearchQuery" search_query, str engine_category)
Public Member Functions inherited from searx.search.processors.online.OnlineProcessor
bool init_engine (self)
 init_network_in_thread (self, float start_time, float timeout_limit)
 search (self, str query, OnlineParams params, "ResultContainer" result_container, float start_time, float timeout_limit)
Public Member Functions inherited from searx.search.processors.abstract.EngineProcessor
 __init__ (self, "Engine|types.ModuleType" engine)
 handle_exception (self, "ResultContainer" result_container, BaseException|str exception_or_message, bool suspend=False)
 extend_container (self, "ResultContainer" result_container, float start_time, "list[Result | LegacyResult]|None" search_results)
bool extend_container_if_suspended (self, "ResultContainer" result_container)
 get_tests (self)
 get_default_tests (self)

Additional Inherited Members

Public Attributes inherited from searx.search.processors.abstract.EngineProcessor
 engine = engine
logging.Logger logger = engines[engine.name].logger
SuspendedStatus suspended_status = SUSPENDED_STATUS.setdefault(key, SuspendedStatus())
Static Public Attributes inherited from searx.search.processors.online.OnlineProcessor
str engine_type = "online"
Protected Member Functions inherited from searx.search.processors.online.OnlineProcessor
 _send_http_request (self, OnlineParams params)
"EngineResults|None" _search_basic (self, str query, OnlineParams params)
Protected Member Functions inherited from searx.search.processors.abstract.EngineProcessor
 _extend_container_basic (self, "ResultContainer" result_container, float start_time, "list[Result | LegacyResult]" search_results)

Detailed Description

Processor class used by ``online_currency`` engines.

Definition at line 50 of file online_currency.py.

Member Function Documentation

◆ get_params()

OnlineCurrenciesParams | None searx.search.processors.online_currency.OnlineCurrencyProcessor.get_params ( self,
"SearchQuery" search_query,
str engine_category )
Returns a dictionary with the :ref:`request params <engine request
online_currency>` (:py:obj:`OnlineCurrenciesParams`).  ``None`` is
returned if the search query does not match :py:obj:`search_syntax`.

Reimplemented from searx.search.processors.online.OnlineProcessor.

Definition at line 59 of file online_currency.py.

59 def get_params(self, search_query: "SearchQuery", engine_category: str) -> OnlineCurrenciesParams | None:
60 """Returns a dictionary with the :ref:`request params <engine request
61 online_currency>` (:py:obj:`OnlineCurrenciesParams`). ``None`` is
62 returned if the search query does not match :py:obj:`search_syntax`."""
63
64 online_params: OnlineParams | None = super().get_params(search_query, engine_category)
65
66 if online_params is None:
67 return None
68 m = search_syntax.match(search_query.query)
69 if not m:
70 return None
71
72 amount_str, from_currency, to_currency = m.groups()
73 try:
74 amount = float(amount_str)
75 except ValueError:
76 return None
77
78 # most often $ stands for USD
79 if from_currency == "$":
80 from_currency = "$ us"
81
82 if to_currency == "$":
83 to_currency = "$ us"
84
85 from_iso4217 = from_currency
86 if not CURRENCIES.is_iso4217(from_iso4217):
87 from_iso4217 = CURRENCIES.name_to_iso4217(_normalize_name(from_currency))
88
89 to_iso4217 = to_currency
90 if not CURRENCIES.is_iso4217(to_iso4217):
91 to_iso4217 = CURRENCIES.name_to_iso4217(_normalize_name(to_currency))
92
93 if from_iso4217 is None or to_iso4217 is None:
94 return None
95
96 ui_locale = flask_babel.get_locale() or babel.Locale.parse("en")
97 from_name: str = CURRENCIES.iso4217_to_name(
98 from_iso4217, ui_locale.language
99 ) # pyright: ignore[reportAssignmentType]
100 to_name: str = CURRENCIES.iso4217_to_name(
101 to_iso4217, ui_locale.language
102 ) # pyright: ignore[reportAssignmentType]
103
104 params: OnlineCurrenciesParams = {
105 **online_params,
106 "amount": amount,
107 "from_iso4217": from_iso4217,
108 "to_iso4217": to_iso4217,
109 "from_name": from_name,
110 "to_name": to_name,
111 }
112
113 return params
114
115

References searx.search.processors.online_currency._normalize_name(), and get_params().

Referenced by get_params().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ initialize()

searx.search.processors.online_currency.OnlineCurrencyProcessor.initialize ( self,
t.Callable[["EngineProcessor", bool], bool] callback )
Initialization of *this* :py:obj:`EngineProcessor`.

If processor's engine has an ``init`` method, it is called first.
Engine's ``init`` method is executed in a thread, meaning that the
*registration* (the ``callback``) may occur later and is not already
established by the return from this registration method.

Registration only takes place if the ``init`` method is not available or
is successfully run through.

Reimplemented from searx.search.processors.abstract.EngineProcessor.

Definition at line 55 of file online_currency.py.

55 def initialize(self, callback: t.Callable[["EngineProcessor", bool], bool]):
56 CURRENCIES.init()
57 super().initialize(callback)
58

References initialize().

Referenced by initialize().

Here is the call graph for this function:
Here is the caller graph for this function:

The documentation for this class was generated from the following file: