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

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

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

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

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

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

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

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

Member Data Documentation

◆ country_code

searx.weather.GeoLocation.country_code

Definition at line 156 of file weather.py.

◆ timezone

searx.weather.GeoLocation.timezone

Definition at line 142 of file weather.py.


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