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

Constructor & Destructor Documentation

◆ __init__()

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

Definition at line 235 of file weather.py.

235 def __init__(self, value: float, unit: Units):
236 if unit not in self.units:
237 raise ValueError(f"invalid unit: {unit}")
238 self.si: float = convert_to_si( # pylint: disable=invalid-name
239 si_name=self.si_name,
240 symbol=unit,
241 value=value,
242 )
243

References units.

Member Function Documentation

◆ __str__()

searx.weather.Temperature.__str__ ( self)

Definition at line 244 of file weather.py.

244 def __str__(self):
245 return self.l10n()
246

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

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

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

247 def value(self, unit: Units) -> float:
248 return convert_from_si(si_name=self.si_name, symbol=unit, value=self.si)
249

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 238 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 228 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 230 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: