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

Functions

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

Variables

dict about
 
list categories = ["weather"]
 
str geo_url = "https://geocoding-api.open-meteo.com"
 
str api_url = "https://api.open-meteo.com"
 
tuple data_of_interest
 
dict WMO_TO_CONDITION
 

Detailed Description

Open Meteo (weather)

Function Documentation

◆ _weather_data()

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

Definition at line 109 of file open_meteo.py.

109def _weather_data(location: weather.GeoLocation, data: dict):
110
111 return WeatherAnswer.Item(
112 location=location,
113 temperature=weather.Temperature(unit="°C", value=data["temperature_2m"]),
114 condition=WMO_TO_CONDITION[data["weather_code"]],
115 feels_like=weather.Temperature(unit="°C", value=data["apparent_temperature"]),
116 wind_from=weather.Compass(data["wind_direction_10m"]),
117 wind_speed=weather.WindSpeed(data["wind_speed_10m"], unit="km/h"),
118 pressure=weather.Pressure(data["pressure_msl"], unit="hPa"),
119 humidity=weather.RelativeHumidity(data["relative_humidity_2m"]),
120 cloud_cover=data["cloud_cover"],
121 )
122
123

Referenced by response().

+ Here is the caller graph for this function:

◆ request()

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

Definition at line 40 of file open_meteo.py.

40def request(query, params):
41
42 try:
43 location = weather.GeoLocation.by_query(query)
44 except ValueError:
45 return
46
47 args = {
48 "latitude": location.latitude,
49 "longitude": location.longitude,
50 "timeformat": "unixtime",
51 "timezone": "auto", # use timezone of the location
52 "format": "json",
53 "current": ",".join(data_of_interest),
54 "forecast_days": 3,
55 "hourly": ",".join(data_of_interest),
56 }
57
58 params["url"] = f"{api_url}/v1/forecast?{urlencode(args)}"
59
60
61# https://open-meteo.com/en/docs#weather_variable_documentation
62# https://nrkno.github.io/yr-weather-symbols/
63

◆ response()

searx.engines.open_meteo.response ( resp)

Definition at line 124 of file open_meteo.py.

124def response(resp):
125 location = weather.GeoLocation.by_query(resp.search_params["query"])
126
127 res = EngineResults()
128 json_data = resp.json()
129
130 weather_answer = WeatherAnswer(
131 current=_weather_data(location, json_data["current"]),
132 service="Open-meteo",
133 # url="https://open-meteo.com/en/docs",
134 )
135
136 for index, time in enumerate(json_data["hourly"]["time"]):
137
138 if time < json_data["current"]["time"]:
139 # Cut off the hours that are already in the past
140 continue
141
142 hourly_data = {}
143 for key in data_of_interest:
144 hourly_data[key] = json_data["hourly"][key][index]
145
146 forecast_data = _weather_data(location, hourly_data)
147 forecast_data.datetime = weather.DateTime(datetime.fromtimestamp(time))
148 weather_answer.forecasts.append(forecast_data)
149
150 res.add(weather_answer)
151 return res

References _weather_data().

+ Here is the call graph for this function:

Variable Documentation

◆ about

dict searx.engines.open_meteo.about
Initial value:
1= {
2 "website": "https://open-meteo.com",
3 "wikidata_id": None,
4 "official_api_documentation": "https://open-meteo.com/en/docs",
5 "use_official_api": True,
6 "require_api_key": False,
7 "results": "JSON",
8}

Definition at line 11 of file open_meteo.py.

◆ api_url

str searx.engines.open_meteo.api_url = "https://api.open-meteo.com"

Definition at line 23 of file open_meteo.py.

◆ categories

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

Definition at line 20 of file open_meteo.py.

◆ data_of_interest

tuple searx.engines.open_meteo.data_of_interest
Initial value:
1= (
2 "temperature_2m",
3 "apparent_temperature",
4 "relative_humidity_2m",
5 "apparent_temperature",
6 "cloud_cover",
7 "pressure_msl",
8 "wind_speed_10m",
9 "wind_direction_10m",
10 "weather_code",
11 # "visibility",
12 # "is_day",
13)

Definition at line 25 of file open_meteo.py.

◆ geo_url

str searx.engines.open_meteo.geo_url = "https://geocoding-api.open-meteo.com"

Definition at line 22 of file open_meteo.py.

◆ WMO_TO_CONDITION

dict searx.engines.open_meteo.WMO_TO_CONDITION

Definition at line 64 of file open_meteo.py.