mirror of
https://github.com/searxng/searxng.git
synced 2026-08-14 03:01:24 +00:00
Compare commits
2 Commits
e840e3f960
...
ee6d4f322f
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ee6d4f322f | ||
|
|
3725aef6f3 |
@@ -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,15 +76,62 @@ 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"],
|
||||||
title=result["web"],
|
title=result["web"],
|
||||||
content=result["description"],
|
content=result["description"],
|
||||||
thumbnail=result.get("thumbnail", {}).get("url", ""),
|
thumbnail=resize_url(result.get("thumbnail", {}), height=80),
|
||||||
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
|
||||||
|
|
||||||
|
|
||||||
|
def resize_url(thumbnail: dict[str, str], width: int = 0, height: int = 0) -> str:
|
||||||
|
"""Generates a URL for Reuter's thumbnail with the dimensions *width* and
|
||||||
|
*height*. If no URL can be generated from the *thumbnail data*, an empty
|
||||||
|
string will be returned.
|
||||||
|
|
||||||
|
width: default is *unset* (``0``)
|
||||||
|
Image width in pixels (negative values are ignored). If only width is
|
||||||
|
specified, the height matches the original aspect ratio.
|
||||||
|
|
||||||
|
height: default is *unset* (``0``)
|
||||||
|
Image height in pixels (negative values are ignored). If only height is
|
||||||
|
specified, the width matches the original aspect ratio.
|
||||||
|
|
||||||
|
The file size of a full-size image is usually several MB; when reduced to a
|
||||||
|
height of, for example, 80 points, only a few KB remain!
|
||||||
|
|
||||||
|
Fields of the *thumbnail data* (``result.articles.[<int>].thumbnail``):
|
||||||
|
|
||||||
|
thumbnail.url:
|
||||||
|
Is a full-size image (>MB).
|
||||||
|
|
||||||
|
thumbnail.width & .height:
|
||||||
|
Dimensions of the full-size image.
|
||||||
|
|
||||||
|
thumbnail.resizer_url:
|
||||||
|
Reuters has a *resizer* `REST-API for the images`_, this is the URL of the
|
||||||
|
service. This URL includes the ``&auth`` argument, other arguments are
|
||||||
|
``&width=<int>`` and ``&height=<int>``.
|
||||||
|
|
||||||
|
.. _REST-API for the images:
|
||||||
|
https://dev.arcxp.com/photo-center/image-resizer/resizer-v2-how-to-transform-images/#query-parameters
|
||||||
|
"""
|
||||||
|
|
||||||
|
url = thumbnail.get("resizer_url")
|
||||||
|
if not url:
|
||||||
|
return ""
|
||||||
|
if int(width) > 0:
|
||||||
|
url += f"&width={int(width)}"
|
||||||
|
if int(height) > 0:
|
||||||
|
url += f"&height={int(height)}"
|
||||||
|
return url
|
||||||
|
|||||||
Reference in New Issue
Block a user