.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 230 of file weather.py.

Constructor & Destructor Documentation

◆ __init__()

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

Definition at line 241 of file weather.py.

241 def __init__(self, value: float, unit: Units):
242 if unit not in self.units:
243 raise ValueError(f"invalid unit: {unit}")
244 self.si: float = convert_to_si( # pylint: disable=invalid-name
245 si_name=self.si_name,
246 symbol=unit,
247 value=value,
248 )
249

References units.

Member Function Documentation

◆ __str__()

searx.weather.Temperature.__str__ ( self)

Definition at line 250 of file weather.py.

250 def __str__(self):
251 return self.l10n()
252

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 256 of file weather.py.

262 ) -> str:
263 """Localized representation of a measured value.
264
265 If the ``unit`` is not set, an attempt is made to determine a ``unit``
266 matching the territory of the ``locale``. If the locale is not set, an
267 attempt is made to determine it from the HTTP request.
268
269 The value is converted into the respective unit before formatting.
270
271 The argument ``num_pattern`` is used to determine the string formatting
272 of the numerical value:
273
274 - https://babel.pocoo.org/en/latest/numbers.html#pattern-syntax
275 - https://unicode.org/reports/tr35/tr35-numbers.html#Number_Format_Patterns
276
277 The argument ``template`` specifies how the **string formatted** value
278 and unit are to be arranged.
279
280 - `Format Specification Mini-Language
281 <https://docs.python.org/3/library/string.html#format-specification-mini-language>`.
282 """
283
284 if isinstance(locale, GeoLocation):
285 locale = locale.locale()
286 elif locale is None:
287 locale = babel.Locale.parse(_get_sxng_locale_tag(), sep='-')
288
289 if unit is None: # unit by territory
290 unit = "°C"
291 if locale.territory in ["US"]:
292 unit = "°F"
293 val_str = babel.numbers.format_decimal(self.value(unit), locale=locale, format=num_pattern)
294 return template.format(value=val_str, unit=unit)
295
296
297@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 253 of file weather.py.

253 def value(self, unit: Units) -> float:
254 return convert_from_si(si_name=self.si_name, symbol=unit, value=self.si)
255

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 244 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 234 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 236 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