mirror of
https://github.com/searxng/searxng.git
synced 2025-12-23 04:00:02 +00:00
[fix] reuters: crash on empty results pages & date parsing
1. On empty result list, return empty EngineResults (#5330) 2. Use ``dateutil.parser`` to avoid ``ValueError``: ERROR searx.engines.reuters : exception : Invalid isoformat string: '2022-06-08T16:07:54Z' File "searx/engines/reuters.py", line 91, in response publishedDate=datetime.fromisoformat(result["display_time"]), ValueError: Invalid isoformat string: '2022-06-08T16:07:54Z' Closes: https://github.com/searxng/searxng/issues/5330 Co-authored-by: Markus Heiser <markus.heiser@darmarit.de>
This commit is contained in:
@@ -17,7 +17,6 @@ The engine has the following additional settings:
|
|||||||
shortcut: reu
|
shortcut: reu
|
||||||
sort_order: "relevance"
|
sort_order: "relevance"
|
||||||
|
|
||||||
|
|
||||||
Implementations
|
Implementations
|
||||||
===============
|
===============
|
||||||
|
|
||||||
@@ -26,6 +25,7 @@ Implementations
|
|||||||
from json import dumps
|
from json import dumps
|
||||||
from urllib.parse import quote_plus
|
from urllib.parse import quote_plus
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
|
from dateutil import parser
|
||||||
|
|
||||||
from searx.result_types import EngineResults
|
from searx.result_types import EngineResults
|
||||||
|
|
||||||
@@ -76,7 +76,11 @@ def request(query, params):
|
|||||||
def response(resp) -> EngineResults:
|
def response(resp) -> EngineResults:
|
||||||
res = EngineResults()
|
res = EngineResults()
|
||||||
|
|
||||||
for result in resp.json().get("result", {}).get("articles", []):
|
resp_json = resp.json()
|
||||||
|
if not resp_json.get("result"):
|
||||||
|
return res
|
||||||
|
|
||||||
|
for result in resp_json["result"].get("articles", []):
|
||||||
res.add(
|
res.add(
|
||||||
res.types.MainResult(
|
res.types.MainResult(
|
||||||
url=base_url + result["canonical_url"],
|
url=base_url + result["canonical_url"],
|
||||||
@@ -84,7 +88,7 @@ def response(resp) -> EngineResults:
|
|||||||
content=result["description"],
|
content=result["description"],
|
||||||
thumbnail=result.get("thumbnail", {}).get("url", ""),
|
thumbnail=result.get("thumbnail", {}).get("url", ""),
|
||||||
metadata=result.get("kicker", {}).get("name"),
|
metadata=result.get("kicker", {}).get("name"),
|
||||||
publishedDate=datetime.fromisoformat(result["display_time"]),
|
publishedDate=parser.isoparse(result["display_time"]),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
return res
|
return res
|
||||||
|
|||||||
Reference in New Issue
Block a user