mirror of
https://github.com/searxng/searxng.git
synced 2026-09-03 04:51:24 +00:00
[fix] hardening engine: ddg weather - get GEO location from response (#6623)
The previous implementation ran into an error if the search term contained words
other than just the location (ValueError was raised).
To test engine use search terms like:
!ddw weather berlin germany
Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
This commit is contained in:
@@ -109,7 +109,19 @@ def response(resp: SXNG_Response):
|
|||||||
|
|
||||||
json_data = loads(resp.text[resp.text.find('\n') + 1 : resp.text.rfind('\n') - 2])
|
json_data = loads(resp.text[resp.text.find('\n') + 1 : resp.text.rfind('\n') - 2])
|
||||||
|
|
||||||
geoloc = weather.GeoLocation.by_query(resp.search_params["query"])
|
location = json_data.get("location")
|
||||||
|
if not location:
|
||||||
|
return res
|
||||||
|
|
||||||
|
metadata = json_data.get("weatherAlerts", {}).get("metadata", {})
|
||||||
|
geoloc = weather.GeoLocation(
|
||||||
|
name=location,
|
||||||
|
latitude=metadata.get("latitude"),
|
||||||
|
longitude=metadata.get("longitude"),
|
||||||
|
elevation=0,
|
||||||
|
country_code=metadata.get("language").split("-")[-1],
|
||||||
|
timezone=json_data.get("location"),
|
||||||
|
)
|
||||||
|
|
||||||
weather_answer = EngineResults.types.WeatherAnswer(
|
weather_answer = EngineResults.types.WeatherAnswer(
|
||||||
current=_weather_data(geoloc, json_data["currentWeather"]),
|
current=_weather_data(geoloc, json_data["currentWeather"]),
|
||||||
|
|||||||
Reference in New Issue
Block a user