.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
searx.weather.Temperature Class Reference

Public Member Functions

 __init__ (self, float value, Units unit)
 __str__ (self)
float value (self, Units unit)
str l10n (self, Units|None unit=None, babel.Locale|GeoLocation|None locale=None, str template="{value} {unit}", str num_pattern="#,##0")

Public Attributes

float si

Static Public Attributes

str si_name = "Q11579"
 Units = typing.Literal["°C", "°F", "K"]
 units = list(typing.get_args(Units))

Detailed Description

Class for converting temperature units and for string representation of
measured values.

Definition at line 256 of file weather.py.

Constructor & Destructor Documentation

◆ __init__()

searx.weather.Temperature.__init__ ( self,
float value,
Units unit )

Definition at line 267 of file weather.py.

267 def __init__(self, value: float, unit: Units):
268 if unit not in self.units:
269 raise ValueError(f"invalid unit: {unit}")
270 self.si: float = convert_to_si( # pylint: disable=invalid-name
271 si_name=self.si_name,
272 symbol=unit,
273 value=value,
274 )
275

References units.

Member Function Documentation

◆ __str__()

searx.weather.Temperature.__str__ ( self)

Definition at line 276 of file weather.py.

276 def __str__(self):
277 return self.l10n()
278

References searx.weather.DateTime.l10n(), and l10n().

Here is the call graph for this function:

◆ l10n()

str searx.weather.Temperature.l10n ( self,
Units | None unit = None,
babel.Locale | GeoLocation | None locale = None,
str template = "{value} {unit}",
str num_pattern = "#,##0" )
Localized representation of a measured value.

If the ``unit`` is not set, an attempt is made to determine a ``unit``
matching the territory of the ``locale``.  If the locale is not set, an
attempt is made to determine it from the HTTP request.

The value is converted into the respective unit before formatting.

The argument ``num_pattern`` is used to determine the string formatting
of the numerical value:

- https://babel.pocoo.org/en/latest/numbers.html#pattern-syntax
- https://unicode.org/reports/tr35/tr35-numbers.html#Number_Format_Patterns

The argument ``template`` specifies how the **string formatted** value
and unit are to be arranged.

- `Format Specification Mini-Language
  <https://docs.python.org/3/library/string.html#format-specification-mini-language>`.

Definition at line 282 of file weather.py.

288 ) -> str:
289 """Localized representation of a measured value.
290
291 If the ``unit`` is not set, an attempt is made to determine a ``unit``
292 matching the territory of the ``locale``. If the locale is not set, an
293 attempt is made to determine it from the HTTP request.
294
295 The value is converted into the respective unit before formatting.
296
297 The argument ``num_pattern`` is used to determine the string formatting
298 of the numerical value:
299
300 - https://babel.pocoo.org/en/latest/numbers.html#pattern-syntax
301 - https://unicode.org/reports/tr35/tr35-numbers.html#Number_Format_Patterns
302
303 The argument ``template`` specifies how the **string formatted** value
304 and unit are to be arranged.
305
306 - `Format Specification Mini-Language
307 <https://docs.python.org/3/library/string.html#format-specification-mini-language>`.
308 """
309
310 if isinstance(locale, GeoLocation):
311 locale = locale.locale()
312 elif locale is None:
313 locale = babel.Locale.parse(_get_sxng_locale_tag(), sep='-')
314
315 if unit is None: # unit by territory
316 unit = "°C"
317 if locale.territory in ["US"]:
318 unit = "°F"
319 val_str = babel.numbers.format_decimal(self.value(unit), locale=locale, format=num_pattern)
320 return template.format(value=val_str, unit=unit)
321
322
323@typing.final

References searx.weather._get_sxng_locale_tag(), searx.preferences.BooleanSetting.value, searx.preferences.EnumStringSetting.value, searx.preferences.MapSetting.value, searx.preferences.MultipleChoiceSetting.value, searx.preferences.SearchLanguageSetting.value, searx.preferences.Setting.value, and value().

Referenced by searx.weather.Compass.__str__(), searx.weather.Pressure.__str__(), searx.weather.RelativeHumidity.__str__(), __str__(), and searx.weather.WindSpeed.__str__().

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

◆ value()

float searx.weather.Temperature.value ( self,
Units unit )

Definition at line 279 of file weather.py.

279 def value(self, unit: Units) -> float:
280 return convert_from_si(si_name=self.si_name, symbol=unit, value=self.si)
281

References si, and si_name.

Referenced by searx.weather.Compass.l10n(), searx.weather.Pressure.l10n(), searx.weather.RelativeHumidity.l10n(), l10n(), and searx.weather.WindSpeed.l10n().

Here is the caller graph for this function:

Member Data Documentation

◆ si

float searx.weather.Temperature.si
Initial value:
= convert_to_si( # pylint: disable=invalid-name
si_name=self.si_name,
symbol=unit,
value=value,
)

Definition at line 270 of file weather.py.

Referenced by searx.weather.Pressure.value(), value(), and searx.weather.WindSpeed.value().

◆ si_name

str searx.weather.Temperature.si_name = "Q11579"
static

Definition at line 260 of file weather.py.

Referenced by searx.weather.Pressure.value(), value(), and searx.weather.WindSpeed.value().

◆ Units

searx.weather.Temperature.Units = typing.Literal["°C", "°F", "K"]
static

Definition at line 262 of file weather.py.

◆ units

searx.weather.Temperature.units = list(typing.get_args(Units))
static

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