[feat] engines: add kaifa.baidu.com
This commit is contained in:
parent
066aabc112
commit
0fbd21eeaf
67
searx/engines/baidu_kaifa.py
Normal file
67
searx/engines/baidu_kaifa.py
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
"""Baidu-Kaifa: A search engine for retrieving coding / development from Baidu."""
|
||||||
|
|
||||||
|
from urllib.parse import urlencode
|
||||||
|
|
||||||
|
import time
|
||||||
|
|
||||||
|
from searx.exceptions import SearxEngineAPIException
|
||||||
|
|
||||||
|
about = {
|
||||||
|
"website": "https://kaifa.baidu.com/",
|
||||||
|
"use_official_api": False,
|
||||||
|
"require_api_key": False,
|
||||||
|
"results": "JSON",
|
||||||
|
}
|
||||||
|
|
||||||
|
paging = True
|
||||||
|
time_range_support = True
|
||||||
|
results_per_page = 10
|
||||||
|
categories = ["it"]
|
||||||
|
|
||||||
|
time_range_dict = {"day": 86400, "week": 604800, "month": 2592000, "year": 31536000}
|
||||||
|
|
||||||
|
base_url = "https://kaifa.baidu.com"
|
||||||
|
|
||||||
|
|
||||||
|
def request(query, params):
|
||||||
|
page_num = params["pageno"]
|
||||||
|
|
||||||
|
query_params = {
|
||||||
|
"wd": query,
|
||||||
|
"paramList": f"page_num={page_num},page_size={results_per_page}",
|
||||||
|
"pageNum": page_num,
|
||||||
|
"pageSize": results_per_page,
|
||||||
|
"position": 0,
|
||||||
|
}
|
||||||
|
|
||||||
|
if params.get("time_range") in time_range_dict:
|
||||||
|
now = int(time.time())
|
||||||
|
past = now - time_range_dict[params["time_range"]]
|
||||||
|
query_params["paramList"] += f",timestamp_range={past}-{now}"
|
||||||
|
|
||||||
|
params["url"] = f"{base_url}/rest/v1/search?{urlencode(query_params)}"
|
||||||
|
return params
|
||||||
|
|
||||||
|
|
||||||
|
def response(resp):
|
||||||
|
try:
|
||||||
|
data = resp.json()
|
||||||
|
except Exception as e:
|
||||||
|
raise SearxEngineAPIException(f"Invalid response: {e}") from e
|
||||||
|
|
||||||
|
results = []
|
||||||
|
|
||||||
|
if not data.get("data", {}).get("documents", {}).get("data"):
|
||||||
|
raise SearxEngineAPIException("Invalid response")
|
||||||
|
|
||||||
|
for entry in data["data"]["documents"]["data"]:
|
||||||
|
results.append(
|
||||||
|
{
|
||||||
|
'title': entry["techDocDigest"]["title"],
|
||||||
|
'url': entry["techDocDigest"]["url"],
|
||||||
|
'content': entry["techDocDigest"]["summary"],
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
return results
|
@ -496,6 +496,11 @@ engines:
|
|||||||
# engine: base
|
# engine: base
|
||||||
# shortcut: bs
|
# shortcut: bs
|
||||||
|
|
||||||
|
- name: baidu kaifa
|
||||||
|
engine: baidu_kaifa
|
||||||
|
shortcut: bdk
|
||||||
|
disabled: true
|
||||||
|
|
||||||
- name: bandcamp
|
- name: bandcamp
|
||||||
engine: bandcamp
|
engine: bandcamp
|
||||||
shortcut: bc
|
shortcut: bc
|
||||||
|
Loading…
x
Reference in New Issue
Block a user