.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
searx.engines.chinaso Namespace Reference

Functions

 init (_)
 
 request (query, params)
 
 response (resp)
 
 parse_news (data)
 
 parse_images (data)
 
 parse_videos (data)
 

Variables

dict about
 
bool paging = True
 
bool time_range_support = True
 
int results_per_page = 10
 
list categories = []
 
str chinaso_category = 'news'
 
dict time_range_dict = {'day': '24h', 'week': '1w', 'month': '1m', 'year': '1y'}
 
str base_url = "https://www.chinaso.com"
 

Detailed Description

ChinaSo: A search engine from ChinaSo.

Function Documentation

◆ init()

searx.engines.chinaso.init ( _)

Definition at line 36 of file chinaso.py.

36def init(_):
37 if chinaso_category not in ('news', 'videos', 'images'):
38 raise SearxEngineAPIException(f"Unsupported category: {chinaso_category}")
39
40

◆ parse_images()

searx.engines.chinaso.parse_images ( data)

Definition at line 102 of file chinaso.py.

102def parse_images(data):
103 results = []
104 if not data.get("data", {}).get("arrRes"):
105 raise SearxEngineAPIException("Invalid response")
106
107 for entry in data["data"]["arrRes"]:
108 results.append(
109 {
110 'url': entry["web_url"],
111 'title': html_to_text(entry["title"]),
112 'content': html_to_text(entry["ImageInfo"]),
113 'template': 'images.html',
114 'img_src': entry["url"].replace("http://", "https://"),
115 'thumbnail_src': entry["largeimage"].replace("http://", "https://"),
116 }
117 )
118 return results
119
120

◆ parse_news()

searx.engines.chinaso.parse_news ( data)

Definition at line 78 of file chinaso.py.

78def parse_news(data):
79 results = []
80 if not data.get("data", {}).get("data"):
81 raise SearxEngineAPIException("Invalid response")
82
83 for entry in data["data"]["data"]:
84 published_date = None
85 if entry.get("timestamp"):
86 try:
87 published_date = datetime.fromtimestamp(int(entry["timestamp"]))
88 except (ValueError, TypeError):
89 pass
90
91 results.append(
92 {
93 'title': html_to_text(entry["title"]),
94 'url': entry["url"],
95 'content': html_to_text(entry["snippet"]),
96 'publishedDate': published_date,
97 }
98 )
99 return results
100
101

◆ parse_videos()

searx.engines.chinaso.parse_videos ( data)

Definition at line 121 of file chinaso.py.

121def parse_videos(data):
122 results = []
123 if not data.get("data", {}).get("arrRes"):
124 raise SearxEngineAPIException("Invalid response")
125
126 for entry in data["data"]["arrRes"]:
127 published_date = None
128 if entry.get("VideoPubDate"):
129 try:
130 published_date = datetime.fromtimestamp(int(entry["VideoPubDate"]))
131 except (ValueError, TypeError):
132 pass
133
134 results.append(
135 {
136 'url': entry["url"],
137 'title': html_to_text(entry["raw_title"]),
138 'template': 'videos.html',
139 'publishedDate': published_date,
140 'thumbnail': entry["image_src"].replace("http://", "https://"),
141 }
142 )
143 return results

◆ request()

searx.engines.chinaso.request ( query,
params )

Definition at line 41 of file chinaso.py.

41def request(query, params):
42 query_params = {"q": query}
43
44 if time_range_dict.get(params['time_range']):
45 query_params["stime"] = time_range_dict[params['time_range']]
46 query_params["etime"] = 'now'
47
48 category_config = {
49 'news': {'endpoint': '/v5/general/v1/web/search', 'params': {'pn': params["pageno"], 'ps': results_per_page}},
50 'images': {
51 'endpoint': '/v5/general/v1/search/image',
52 'params': {'start_index': (params["pageno"] - 1) * results_per_page, 'rn': results_per_page},
53 },
54 'videos': {
55 'endpoint': '/v5/general/v1/search/video',
56 'params': {'start_index': (params["pageno"] - 1) * results_per_page, 'rn': results_per_page},
57 },
58 }
59
60 query_params.update(category_config[chinaso_category]['params'])
61
62 params["url"] = f"{base_url}{category_config[chinaso_category]['endpoint']}?{urlencode(query_params)}"
63
64 return params
65
66

◆ response()

searx.engines.chinaso.response ( resp)

Definition at line 67 of file chinaso.py.

67def response(resp):
68 try:
69 data = resp.json()
70 except Exception as e:
71 raise SearxEngineAPIException(f"Invalid response: {e}") from e
72
73 parsers = {'news': parse_news, 'images': parse_images, 'videos': parse_videos}
74
75 return parsers[chinaso_category](data)
76
77

Variable Documentation

◆ about

dict searx.engines.chinaso.about
Initial value:
1= {
2 "website": "https://www.chinaso.com/",
3 "wikidata_id": "Q10846064",
4 "use_official_api": False,
5 "require_api_key": False,
6 "results": "JSON",
7 "language": "zh",
8}

Definition at line 10 of file chinaso.py.

◆ base_url

str searx.engines.chinaso.base_url = "https://www.chinaso.com"

Definition at line 33 of file chinaso.py.

◆ categories

list searx.engines.chinaso.categories = []

Definition at line 22 of file chinaso.py.

◆ chinaso_category

str searx.engines.chinaso.chinaso_category = 'news'

Definition at line 23 of file chinaso.py.

◆ paging

bool searx.engines.chinaso.paging = True

Definition at line 19 of file chinaso.py.

◆ results_per_page

int searx.engines.chinaso.results_per_page = 10

Definition at line 21 of file chinaso.py.

◆ time_range_dict

dict searx.engines.chinaso.time_range_dict = {'day': '24h', 'week': '1w', 'month': '1m', 'year': '1y'}

Definition at line 31 of file chinaso.py.

◆ time_range_support

bool searx.engines.chinaso.time_range_support = True

Definition at line 20 of file chinaso.py.