.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
searx.engines.wttr Namespace Reference

Functions

 request (query, params)
 _weather_data (weather.GeoLocation location, dict data)
 response (resp)

Variables

dict about
list categories = ["weather"]
str url = "https://wttr.in/{query}?format=j1&lang={lang}"
dict WWO_TO_CONDITION

Detailed Description

wttr.in (weather forecast service)

Function Documentation

◆ _weather_data()

searx.engines.wttr._weather_data ( weather.GeoLocation location,
dict data )
protected

Definition at line 83 of file wttr.py.

83def _weather_data(location: weather.GeoLocation, data: dict):
84 # the naming between different data objects is inconsitent, thus temp_C and
85 # tempC are possible
86 tempC: float = data.get("temp_C") or data.get("tempC") # type: ignore
87
88 return WeatherAnswer.Item(
89 location=location,
90 temperature=weather.Temperature(unit="°C", value=tempC),
91 condition=WWO_TO_CONDITION[data["weatherCode"]],
92 feels_like=weather.Temperature(unit="°C", value=data["FeelsLikeC"]),
93 wind_from=weather.Compass(int(data["winddirDegree"])),
94 wind_speed=weather.WindSpeed(data["windspeedKmph"], unit="km/h"),
95 pressure=weather.Pressure(data["pressure"], unit="hPa"),
96 humidity=weather.RelativeHumidity(data["humidity"]),
97 cloud_cover=data["cloudcover"],
98 )
99
100

Referenced by response().

Here is the caller graph for this function:

◆ request()

searx.engines.wttr.request ( query,
params )

Definition at line 76 of file wttr.py.

76def request(query, params):
77 params["url"] = url.format(query=quote(query), lang=params["language"])
78 params["raise_for_httperror"] = False
79
80 return params
81
82

◆ response()

searx.engines.wttr.response ( resp)

Definition at line 101 of file wttr.py.

101def response(resp):
102 res = EngineResults()
103
104 if resp.status_code == 404:
105 return res
106
107 json_data = resp.json()
108 geoloc = weather.GeoLocation.by_query(resp.search_params["query"])
109
110 weather_answer = WeatherAnswer(
111 current=_weather_data(geoloc, json_data["current_condition"][0]),
112 service="wttr.in",
113 )
114
115 for day in json_data["weather"]:
116 date = datetime.fromisoformat(day["date"])
117 time_slot_len = 24 // len(day["hourly"])
118 for index, forecast in enumerate(day["hourly"]):
119 forecast_data = _weather_data(geoloc, forecast)
120 forecast_data.datetime = weather.DateTime(date.replace(hour=index * time_slot_len + 1))
121 weather_answer.forecasts.append(forecast_data)
122
123 res.add(weather_answer)
124 return res

References _weather_data().

Here is the call graph for this function:

Variable Documentation

◆ about

dict searx.engines.wttr.about
Initial value:
1= {
2 "website": "https://wttr.in",
3 "wikidata_id": "Q107586666",
4 "official_api_documentation": "https://github.com/chubin/wttr.in#json-output",
5 "use_official_api": True,
6 "require_api_key": False,
7 "results": "JSON",
8}

Definition at line 10 of file wttr.py.

◆ categories

list searx.engines.wttr.categories = ["weather"]

Definition at line 19 of file wttr.py.

◆ url

str searx.engines.wttr.url = "https://wttr.in/{query}?format=j1&lang={lang}"

Definition at line 21 of file wttr.py.

◆ WWO_TO_CONDITION

dict searx.engines.wttr.WWO_TO_CONDITION

Definition at line 24 of file wttr.py.