.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
searx.plugins.time_zone.SXNGPlugin Class Reference
Inheritance diagram for searx.plugins.time_zone.SXNGPlugin:
Collaboration diagram for searx.plugins.time_zone.SXNGPlugin:

Public Member Functions

 __init__ (self, "PluginCfg" plg_cfg)
EngineResults post_search (self, "SXNG_Request" request, "SearchWithPlugins" search)
Public Member Functions inherited from searx.plugins._core.Plugin
None __init__ (self, "PluginCfg" plg_cfg)
int __hash__ (self)
 __eq__ (self, typing.Any other)
bool init (self, "flask.Flask" app)
bool pre_search (self, SXNG_Request request, "SearchWithPlugins" search)
bool on_result (self, SXNG_Request request, "SearchWithPlugins" search, Result result)

Public Attributes

 info

Additional Inherited Members

Static Public Attributes inherited from searx.plugins._core.Plugin
str id = ""
typing active .ClassVar[bool]
list keywords = []
logging log .Logger
str fqn = ""

Detailed Description

Plugin to display the current time at different timezones (usually the
query city).

Definition at line 22 of file time_zone.py.

Constructor & Destructor Documentation

◆ __init__()

searx.plugins.time_zone.SXNGPlugin.__init__ ( self,
"PluginCfg" plg_cfg )

Definition at line 29 of file time_zone.py.

29 def __init__(self, plg_cfg: "PluginCfg"):
30 super().__init__(plg_cfg)
31
32 self.info = PluginInfo(
33 id=self.id,
34 name=gettext("Timezones plugin"),
35 description=gettext("Display the current time on different time zones."),
36 preference_section="query",
37 examples=["time Berlin", "clock Los Angeles"],
38 )
39

References __init__().

Referenced by __init__().

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

Member Function Documentation

◆ post_search()

EngineResults searx.plugins.time_zone.SXNGPlugin.post_search ( self,
"SXNG_Request" request,
"SearchWithPlugins" search )
The plugin uses the :py:obj:`searx.weather.GeoLocation` class, which
is already implemented in the context of weather forecasts, to determine
the time zone. The :py:obj:`searx.weather.DateTime` class is used for
the localized display of date and time.

Reimplemented from searx.plugins._core.Plugin.

Definition at line 40 of file time_zone.py.

40 def post_search(self, request: "SXNG_Request", search: "SearchWithPlugins") -> EngineResults:
41 """The plugin uses the :py:obj:`searx.weather.GeoLocation` class, which
42 is already implemented in the context of weather forecasts, to determine
43 the time zone. The :py:obj:`searx.weather.DateTime` class is used for
44 the localized display of date and time."""
45
46 results = EngineResults()
47 if search.search_query.pageno > 1:
48 return results
49
50 # remove keywords from the query
51 query = search.search_query.query
52 query_parts = filter(lambda part: part.lower() not in self.keywords, query.split(" "))
53 search_term = " ".join(query_parts).strip()
54
55 if not search_term:
56 date_time = DateTime(time=datetime.datetime.now())
57 results.add(results.types.Answer(answer=date_time.l10n()))
58 return results
59
60 geo = GeoLocation.by_query(search_term=search_term)
61 if geo:
62 date_time = DateTime(time=datetime.datetime.now(tz=geo.zoneinfo))
63 tz_name = geo.timezone.replace('_', ' ')
64 results.add(
65 results.types.Answer(
66 answer=(f"{tz_name}:" f" {date_time.l10n()} ({date_time.datetime.strftime('%Z')})")
67 )
68 )
69
70 return results

References searx.answerers._core.Answerer.keywords, searx.answerers._core.AnswererInfo.keywords, searx.answerers._core.ModuleAnswerer.keywords, searx.answerers.random.SXNGAnswerer.keywords, searx.answerers.statistics.SXNGAnswerer.keywords, searx.plugins._core.Plugin.keywords, and searx.plugins._core.PluginInfo.keywords.

Member Data Documentation

◆ info

searx.plugins.time_zone.SXNGPlugin.info
Initial value:
= PluginInfo(
id=self.id,
name=gettext("Timezones plugin"),
description=gettext("Display the current time on different time zones."),
preference_section="query",
examples=["time Berlin", "clock Los Angeles"],
)

Definition at line 32 of file time_zone.py.


The documentation for this class was generated from the following file:
  • /home/andrew/Documents/code/public/searxng/searx/plugins/time_zone.py