.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 = typing.Literal['news', 'videos', 'images']
 
str chinaso_category = 'news'
 
 ChinasoNewsSourceType = typing.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 109 of file chinaso.py.

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

◆ parse_images()

searx.engines.chinaso.parse_images ( data)

Definition at line 182 of file chinaso.py.

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

◆ parse_news()

searx.engines.chinaso.parse_news ( data)

Definition at line 158 of file chinaso.py.

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

◆ parse_videos()

searx.engines.chinaso.parse_videos ( data)

Definition at line 201 of file chinaso.py.

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

◆ request()

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

Definition at line 116 of file chinaso.py.

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

◆ response()

searx.engines.chinaso.response ( resp)

Definition at line 147 of file chinaso.py.

147def response(resp):
148 try:
149 data = resp.json()
150 except Exception as e:
151 raise SearxEngineAPIException(f"Invalid response: {e}") from e
152
153 parsers = {'news': parse_news, 'images': parse_images, 'videos': parse_videos}
154
155 return parsers[chinaso_category](data)
156
157

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

◆ base_url

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

Definition at line 106 of file chinaso.py.

◆ categories

list searx.engines.chinaso.categories = []

Definition at line 77 of file chinaso.py.

◆ chinaso_category

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

Definition at line 89 of file chinaso.py.

◆ chinaso_news_source

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

Definition at line 101 of file chinaso.py.

◆ ChinasoCategoryType

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

Definition at line 79 of file chinaso.py.

◆ ChinasoNewsSourceType

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

Definition at line 92 of file chinaso.py.

◆ paging

bool searx.engines.chinaso.paging = True

Definition at line 74 of file chinaso.py.

◆ results_per_page

int searx.engines.chinaso.results_per_page = 10

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

◆ time_range_support

bool searx.engines.chinaso.time_range_support = True

Definition at line 75 of file chinaso.py.