.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
reuters.py
Go to the documentation of this file.
1# SPDX-License-Identifier: AGPL-3.0-or-later
2"""Reuters_ (news) is an international news agency.
3
4.. _Reuters: https://www.reuters.com
5
6Configuration
7=============
8
9The engine has the following additional settings:
10
11- :py:obj:`sort_order`
12
13.. code:: yaml
14
15 - name: reuters
16 engine: reuters
17 shortcut: reu
18 sort_order: "relevance"
19
20
21Implementations
22===============
23
24"""
25
26from json import dumps
27from urllib.parse import quote_plus
28from datetime import datetime, timedelta
29
30from searx.result_types import EngineResults
31
32about = {
33 "website": "https://www.reuters.com",
34 "wikidata_id": "Q130879",
35 "official_api_documentation": None,
36 "use_official_api": False,
37 "require_api_key": False,
38 "results": "JSON",
39}
40
41categories = ["news"]
42time_range_support = True
43paging = True
44
45base_url = "https://www.reuters.com"
46
47results_per_page = 20
48sort_order = "relevance"
49"""Sort order, one of ``relevance``, ``display_date:desc`` or ``display_data:asc``."""
50
51time_range_duration_map = {
52 "day": 1,
53 "week": 7,
54 "month": 30,
55 "year": 365,
56}
57
58
59def request(query, params):
60 args = {
61 "keyword": query,
62 "offset": (params["pageno"] - 1) * results_per_page,
63 "orderby": sort_order,
64 "size": results_per_page,
65 "website": "reuters",
66 }
67 if params["time_range"]:
68 time_diff_days = time_range_duration_map[params["time_range"]]
69 start_date = datetime.now() - timedelta(days=time_diff_days)
70 args["start_date"] = start_date.isoformat()
71
72 params["url"] = f"{base_url}/pf/api/v3/content/fetch/articles-by-search-v2?query={quote_plus(dumps(args))}"
73 return params
74
75
76def response(resp) -> EngineResults:
77 res = EngineResults()
78
79 for result in resp.json().get("result", {}).get("articles", []):
80 res.add(
81 res.types.MainResult(
82 url=base_url + result["canonical_url"],
83 title=result["web"],
84 content=result["description"],
85 thumbnail=result.get("thumbnail", {}).get("url", ""),
86 metadata=result.get("kicker", {}).get("name"),
87 publishedDate=datetime.strptime(result["display_time"], "%Y-%m-%dT%H:%M:%SZ"),
88 )
89 )
90 return res
EngineResults response(resp)
Definition reuters.py:76
request(query, params)
Definition reuters.py:59