.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 = []
 ChinasoCategoryType = t.Literal['news', 'videos', 'images']
str chinaso_category = 'news'
 ChinasoNewsSourceType = t.Literal['CENTRAL', 'LOCAL', 'BUSINESS', 'EPAPER', 'all']
ChinasoNewsSourceType chinaso_news_source = 'all'
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 for the chinese language area.

.. attention::

   ChinaSo engine does not return real URL, the links from these search
   engines violate the privacy of the users!!

   We try to find a solution for this problem, please follow `issue #4694`_.

   As long as the problem has not been resolved, these engines are
   not active in a standard setup (``inactive: true``).

.. _ChinaSo: https://www.chinaso.com/
.. _issue #4694: https://github.com/searxng/searxng/issues/4694

Configuration
=============

The engine has the following additional settings:

- :py:obj:`chinaso_category` (:py:obj:`ChinasoCategoryType`)
- :py:obj:`chinaso_news_source` (:py:obj:`ChinasoNewsSourceType`)

In the example below, all three ChinaSO engines are using the :ref:`network
<engine network>` from the ``chinaso news`` engine.

.. code:: yaml

   - name: chinaso news
     engine: chinaso
     shortcut: chinaso
     categories: [news]
     chinaso_category: news
     chinaso_news_source: all

   - name: chinaso images
     engine: chinaso
     network: chinaso news
     shortcut: chinasoi
     categories: [images]
     chinaso_category: images

   - name: chinaso videos
     engine: chinaso
     network: chinaso news
     shortcut: chinasov
     categories: [videos]
     chinaso_category: videos


Implementations
===============

Function Documentation

◆ init()

searx.engines.chinaso.init ( _)

Definition at line 111 of file chinaso.py.

111def init(_):
112 if chinaso_category not in ('news', 'videos', 'images'):
113 raise ValueError(f"Unsupported category: {chinaso_category}")
114 if chinaso_category == 'news' and chinaso_news_source not in t.get_args(ChinasoNewsSourceType):
115 raise ValueError(f"Unsupported news source: {chinaso_news_source}")
116
117

◆ parse_images()

searx.engines.chinaso.parse_images ( data)

Definition at line 188 of file chinaso.py.

188def parse_images(data):
189 results = []
190 if not data.get("data", {}).get("arrRes"):
191 raise SearxEngineAPIException("Invalid response")
192
193 for entry in data["data"]["arrRes"]:
194 results.append(
195 {
196 'url': entry["web_url"],
197 'title': html_to_text(entry["title"]),
198 'content': html_to_text(entry.get("ImageInfo", "")),
199 'template': 'images.html',
200 'img_src': entry["url"].replace("http://", "https://"),
201 'thumbnail_src': entry["largeimage"].replace("http://", "https://"),
202 }
203 )
204 return results
205
206

◆ parse_news()

searx.engines.chinaso.parse_news ( data)

Definition at line 164 of file chinaso.py.

164def parse_news(data):
165 results = []
166 if not data.get("data", {}).get("data"):
167 raise SearxEngineAPIException("Invalid response")
168
169 for entry in data["data"]["data"]:
170 published_date = None
171 if entry.get("timestamp"):
172 try:
173 published_date = datetime.fromtimestamp(int(entry["timestamp"]))
174 except (ValueError, TypeError):
175 pass
176
177 results.append(
178 {
179 'title': html_to_text(entry["title"]),
180 'url': entry["url"],
181 'content': html_to_text(entry["snippet"]),
182 'publishedDate': published_date,
183 }
184 )
185 return results
186
187

◆ parse_videos()

searx.engines.chinaso.parse_videos ( data)

Definition at line 207 of file chinaso.py.

207def parse_videos(data):
208 results = []
209 if not data.get("data", {}).get("arrRes"):
210 raise SearxEngineAPIException("Invalid response")
211
212 for entry in data["data"]["arrRes"]:
213 published_date = None
214 if entry.get("VideoPubDate"):
215 try:
216 published_date = datetime.fromtimestamp(int(entry["VideoPubDate"]))
217 except (ValueError, TypeError):
218 pass
219
220 results.append(
221 {
222 'url': entry["url"],
223 'title': html_to_text(entry["raw_title"]),
224 'template': 'videos.html',
225 'publishedDate': published_date,
226 'thumbnail': entry["image_src"].replace("http://", "https://"),
227 }
228 )
229 return results

◆ request()

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

Definition at line 118 of file chinaso.py.

118def request(query, params):
119 query_params = {"q": query}
120
121 if time_range_dict.get(params['time_range']):
122 query_params["stime"] = time_range_dict[params['time_range']]
123 query_params["etime"] = 'now'
124
125 category_config = {
126 'news': {'endpoint': '/v5/general/v1/web/search', 'params': {'pn': params["pageno"], 'ps': results_per_page}},
127 'images': {
128 'endpoint': '/v5/general/v1/search/image',
129 'params': {'start_index': (params["pageno"] - 1) * results_per_page, 'rn': results_per_page},
130 },
131 'videos': {
132 'endpoint': '/v5/general/v1/search/video',
133 'params': {'start_index': (params["pageno"] - 1) * results_per_page, 'rn': results_per_page},
134 },
135 }
136 if chinaso_news_source != 'all':
137 if chinaso_news_source == 'EPAPER':
138 category_config['news']['params']["type"] = 'EPAPER'
139 else:
140 category_config['news']['params']["cate"] = chinaso_news_source
141
142 query_params.update(category_config[chinaso_category]['params'])
143
144 params["url"] = f"{base_url}{category_config[chinaso_category]['endpoint']}?{urlencode(query_params)}"
145 cookie = {
146 "uid": base64.b64encode(secrets.token_bytes(16)).decode("utf-8"),
147 }
148 params["cookies"] = cookie
149
150 return params
151
152

◆ response()

searx.engines.chinaso.response ( resp)

Definition at line 153 of file chinaso.py.

153def response(resp):
154 try:
155 data = resp.json()
156 except Exception as e:
157 raise SearxEngineAPIException(f"Invalid response: {e}") from e
158
159 parsers = {'news': parse_news, 'images': parse_images, 'videos': parse_videos}
160
161 return parsers[chinaso_category](data)
162
163

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 67 of file chinaso.py.

◆ base_url

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

Definition at line 108 of file chinaso.py.

◆ categories

list searx.engines.chinaso.categories = []

Definition at line 79 of file chinaso.py.

◆ chinaso_category

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

Definition at line 91 of file chinaso.py.

◆ chinaso_news_source

ChinasoNewsSourceType searx.engines.chinaso.chinaso_news_source = 'all'

Definition at line 103 of file chinaso.py.

◆ ChinasoCategoryType

searx.engines.chinaso.ChinasoCategoryType = t.Literal['news', 'videos', 'images']

Definition at line 81 of file chinaso.py.

◆ ChinasoNewsSourceType

searx.engines.chinaso.ChinasoNewsSourceType = t.Literal['CENTRAL', 'LOCAL', 'BUSINESS', 'EPAPER', 'all']

Definition at line 94 of file chinaso.py.

◆ paging

bool searx.engines.chinaso.paging = True

Definition at line 76 of file chinaso.py.

◆ results_per_page

int searx.engines.chinaso.results_per_page = 10

Definition at line 78 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 106 of file chinaso.py.

◆ time_range_support

bool searx.engines.chinaso.time_range_support = True

Definition at line 77 of file chinaso.py.