mirror of
https://github.com/searxng/searxng.git
synced 2025-12-22 19:50:00 +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
|
||||
sort_order: "relevance"
|
||||
|
||||
|
||||
Implementations
|
||||
===============
|
||||
|
||||
@@ -26,6 +25,7 @@ Implementations
|
||||
from json import dumps
|
||||
from urllib.parse import quote_plus
|
||||
from datetime import datetime, timedelta
|
||||
from dateutil import parser
|
||||
|
||||
from searx.result_types import EngineResults
|
||||
|
||||
@@ -76,7 +76,11 @@ def request(query, params):
|
||||
def response(resp) -> 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.types.MainResult(
|
||||
url=base_url + result["canonical_url"],
|
||||
@@ -84,7 +88,7 @@ def response(resp) -> EngineResults:
|
||||
content=result["description"],
|
||||
thumbnail=result.get("thumbnail", {}).get("url", ""),
|
||||
metadata=result.get("kicker", {}).get("name"),
|
||||
publishedDate=datetime.fromisoformat(result["display_time"]),
|
||||
publishedDate=parser.isoparse(result["display_time"]),
|
||||
)
|
||||
)
|
||||
return res
|
||||
|
||||
Reference in New Issue
Block a user