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

Functions

 _weather_data (weather.GeoLocation location, dict[str, t.Any] data)
 request (str query, dict[str, t.Any] params)
 response (SXNG_Response resp)

Variables

dict about
bool send_accept_language_header = True
list categories = ["weather"]
str base_url = "https://duckduckgo.com/js/spice/forecast/{query}/{lang}"
dict WEATHERKIT_TO_CONDITION

Detailed Description

DuckDuckGo Weather
~~~~~~~~~~~~~~~~~~

Function Documentation

◆ _weather_data()

searx.engines.duckduckgo_weather._weather_data ( weather.GeoLocation location,
dict[str, t.Any] data )
protected

Definition at line 75 of file duckduckgo_weather.py.

75def _weather_data(location: weather.GeoLocation, data: dict[str, t.Any]):
76
77 return EngineResults.types.WeatherAnswer.Item(
78 location=location,
79 temperature=weather.Temperature(unit="°C", value=data['temperature']),
80 condition=WEATHERKIT_TO_CONDITION[data["conditionCode"]],
81 feels_like=weather.Temperature(unit="°C", value=data['temperatureApparent']),
82 wind_from=weather.Compass(data["windDirection"]),
83 wind_speed=weather.WindSpeed(data["windSpeed"], unit="mi/h"),
84 pressure=weather.Pressure(data["pressure"], unit="hPa"),
85 humidity=weather.RelativeHumidity(data["humidity"] * 100),
86 cloud_cover=data["cloudCover"] * 100,
87 )
88
89

Referenced by response().

Here is the caller graph for this function:

◆ request()

searx.engines.duckduckgo_weather.request ( str query,
dict[str, t.Any] params )

Definition at line 90 of file duckduckgo_weather.py.

90def request(query: str, params: dict[str, t.Any]):
91
92 eng_region = traits.get_region(params['searxng_locale'], traits.all_locale)
93 eng_lang = get_ddg_lang(traits, params['searxng_locale'])
94
95 # !ddw paris :es-AR --> {'ad': 'es_AR', 'ah': 'ar-es', 'l': 'ar-es'}
96 params['cookies']['ad'] = eng_lang
97 params['cookies']['ah'] = eng_region
98 params['cookies']['l'] = eng_region
99 logger.debug("cookies: %s", params['cookies'])
100
101 params["url"] = base_url.format(query=quote(query), lang=eng_lang.split('_')[0])
102 return params
103
104

◆ response()

searx.engines.duckduckgo_weather.response ( SXNG_Response resp)

Definition at line 105 of file duckduckgo_weather.py.

105def response(resp: SXNG_Response):
106 res = EngineResults()
107
108 if resp.text.strip() == "ddg_spice_forecast();":
109 return res
110
111 json_data = loads(resp.text[resp.text.find('\n') + 1 : resp.text.rfind('\n') - 2])
112
113 geoloc = weather.GeoLocation.by_query(resp.search_params["query"])
114
115 weather_answer = EngineResults.types.WeatherAnswer(
116 current=_weather_data(geoloc, json_data["currentWeather"]),
117 service="duckduckgo weather",
118 )
119
120 for forecast in json_data['forecastHourly']['hours']:
121 forecast_time = date_parser.parse(forecast['forecastStart'])
122 forecast_data = _weather_data(geoloc, forecast)
123 forecast_data.datetime = weather.DateTime(forecast_time)
124 weather_answer.forecasts.append(forecast_data)
125
126 res.add(weather_answer)
127 return res

References _weather_data().

Here is the call graph for this function:

Variable Documentation

◆ about

dict searx.engines.duckduckgo_weather.about
Initial value:
1= {
2 "website": 'https://duckduckgo.com/',
3 "wikidata_id": 'Q12805',
4 "official_api_documentation": None,
5 "use_official_api": True,
6 "require_api_key": False,
7 "results": "JSON",
8}

Definition at line 21 of file duckduckgo_weather.py.

◆ base_url

str searx.engines.duckduckgo_weather.base_url = "https://duckduckgo.com/js/spice/forecast/{query}/{lang}"

Definition at line 34 of file duckduckgo_weather.py.

◆ categories

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

Definition at line 33 of file duckduckgo_weather.py.

◆ send_accept_language_header

bool searx.engines.duckduckgo_weather.send_accept_language_header = True

Definition at line 30 of file duckduckgo_weather.py.

◆ WEATHERKIT_TO_CONDITION

dict searx.engines.duckduckgo_weather.WEATHERKIT_TO_CONDITION

Definition at line 37 of file duckduckgo_weather.py.