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

Public Member Functions

zoneinfo.ZoneInfo zoneinfo (self)
 __str__ (self)
babel.Locale locale (self)
"GeoLocation" by_query (cls, str search_term)

Public Attributes

 timezone
 country_code

Protected Member Functions

dict[str, str] _query_open_meteo (cls, str search_term)

Detailed Description

Minimal implementation of Geocoding.

Definition at line 124 of file weather.py.

Member Function Documentation

◆ __str__()

◆ _query_open_meteo()

dict[str, str] searx.weather.GeoLocation._query_open_meteo ( cls,
str search_term )
protected

Definition at line 188 of file weather.py.

188 def _query_open_meteo(cls, search_term: str) -> dict[str, str]:
189 url = f"https://geocoding-api.open-meteo.com/v1/search?name={quote_plus(search_term)}"
190 resp = network.get(url, timeout=3)
191 if resp.status_code != 200:
192 raise ValueError(f"unknown geo location: '{search_term}'")
193 results = resp.json().get("results")
194 if not results:
195 raise ValueError(f"unknown geo location: '{search_term}'")
196 location = results[0]
197 return {field.name: location[field.name] for field in dataclasses.fields(cls)}
198
199

Referenced by by_query().

Here is the caller graph for this function:

◆ by_query()

"GeoLocation" searx.weather.GeoLocation.by_query ( cls,
str search_term )
Factory method to get a GeoLocation object by a search term.  If no
location can be determined for the search term, a :py:obj:`ValueError`
is thrown.

Definition at line 171 of file weather.py.

171 def by_query(cls, search_term: str) -> "GeoLocation":
172 """Factory method to get a GeoLocation object by a search term. If no
173 location can be determined for the search term, a :py:obj:`ValueError`
174 is thrown.
175 """
176
177 ctx = "weather_geolocation_by_query"
178 cache = get_WEATHER_DATA_CACHE()
179 geo_props = cache.get(search_term, ctx=ctx)
180
181 if not geo_props:
182 geo_props = cls._query_open_meteo(search_term=search_term)
183 cache.set(key=search_term, value=geo_props, expire=None, ctx=ctx)
184
185 return cls(**geo_props) # type: ignore
186

References _query_open_meteo(), and searx.weather.get_WEATHER_DATA_CACHE().

Here is the call graph for this function:

◆ locale()

babel.Locale searx.weather.GeoLocation.locale ( self)

Definition at line 148 of file weather.py.

148 def locale(self) -> babel.Locale:
149
150 # by region of the search language
151 sxng_tag = _get_sxng_locale_tag()
152 if "-" in sxng_tag:
153 locale = babel.Locale.parse(_get_sxng_locale_tag(), sep='-')
154 return locale
155
156 # by most popular language in the region (country code)
157 for lang in babel.languages.get_official_languages(self.country_code):
158 try:
159 locale = babel.Locale.parse(f"{lang}_{self.country_code}")
160 return locale
161 except babel.UnknownLocaleError:
162 continue
163
164 # No locale could be determined. This does not actually occur, but if
165 # it does, the English language is used by default. But not region US.
166 # US has some units that are only used in US but not in the rest of the
167 # world (e.g. °F instead of °C)
168 return babel.Locale("en", territory="DE")
169

References searx.weather._get_sxng_locale_tag().

Here is the call graph for this function:

◆ zoneinfo()

zoneinfo.ZoneInfo searx.weather.GeoLocation.zoneinfo ( self)

Definition at line 142 of file weather.py.

142 def zoneinfo(self) -> zoneinfo.ZoneInfo:
143 return zoneinfo.ZoneInfo(self.timezone)
144

Member Data Documentation

◆ country_code

searx.weather.GeoLocation.country_code

Definition at line 157 of file weather.py.

◆ timezone

searx.weather.GeoLocation.timezone

Definition at line 143 of file weather.py.


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