mirror of
https://github.com/parchlinuxB/Gitee.git
synced 2025-02-22 18:05:44 -05:00
[json_engine] Fix R0912 (too-many-branches)
This commit is contained in:
parent
3942b311ac
commit
35c80268bf
1 changed files with 42 additions and 43 deletions
|
@ -352,6 +352,37 @@ def identity(arg):
|
||||||
return arg
|
return arg
|
||||||
|
|
||||||
|
|
||||||
|
def extract_response_info(result):
|
||||||
|
title_filter = html_to_text if title_html_to_text else identity
|
||||||
|
content_filter = html_to_text if content_html_to_text else identity
|
||||||
|
|
||||||
|
tmp_result = {}
|
||||||
|
|
||||||
|
try:
|
||||||
|
url = query(result, url_query)[0]
|
||||||
|
tmp_result['url'] = url_prefix + to_string(url)
|
||||||
|
|
||||||
|
title = query(result, title_query)[0]
|
||||||
|
tmp_result['title'] = title_filter(to_string(title))
|
||||||
|
except: # pylint: disable=bare-except
|
||||||
|
return None
|
||||||
|
|
||||||
|
try:
|
||||||
|
content = query(result, content_query)[0]
|
||||||
|
tmp_result['content'] = content_filter(to_string(content))
|
||||||
|
except: # pylint: disable=bare-except
|
||||||
|
tmp_result['content'] = ""
|
||||||
|
|
||||||
|
try:
|
||||||
|
if thumbnail_query:
|
||||||
|
thumbnail_query_result = query(result, thumbnail_query)[0]
|
||||||
|
tmp_result['thumbnail'] = thumbnail_prefix + to_string(thumbnail_query_result)
|
||||||
|
except: # pylint: disable=bare-except
|
||||||
|
pass
|
||||||
|
|
||||||
|
return tmp_result
|
||||||
|
|
||||||
|
|
||||||
def response(resp):
|
def response(resp):
|
||||||
'''Scrap *results* from the response (see :ref:`engine results`).'''
|
'''Scrap *results* from the response (see :ref:`engine results`).'''
|
||||||
results = []
|
results = []
|
||||||
|
@ -367,55 +398,23 @@ def response(resp):
|
||||||
json = loads(resp.text)
|
json = loads(resp.text)
|
||||||
is_onion = 'onions' in categories
|
is_onion = 'onions' in categories
|
||||||
|
|
||||||
title_filter = html_to_text if title_html_to_text else identity
|
|
||||||
content_filter = html_to_text if content_html_to_text else identity
|
|
||||||
|
|
||||||
if results_query:
|
if results_query:
|
||||||
rs = query(json, results_query) # pylint: disable=invalid-name
|
rs = query(json, results_query) # pylint: disable=invalid-name
|
||||||
if not rs:
|
if not rs:
|
||||||
return results
|
return results
|
||||||
for result in rs[0]:
|
rs = rs[0] # pylint: disable=invalid-name
|
||||||
try:
|
|
||||||
url = query(result, url_query)[0]
|
|
||||||
title = query(result, title_query)[0]
|
|
||||||
except: # pylint: disable=bare-except
|
|
||||||
continue
|
|
||||||
try:
|
|
||||||
content = query(result, content_query)[0]
|
|
||||||
except: # pylint: disable=bare-except
|
|
||||||
content = ""
|
|
||||||
|
|
||||||
tmp_result = {
|
|
||||||
'url': url_prefix + to_string(url),
|
|
||||||
'title': title_filter(to_string(title)),
|
|
||||||
'content': content_filter(to_string(content)),
|
|
||||||
}
|
|
||||||
|
|
||||||
if thumbnail_query:
|
|
||||||
try:
|
|
||||||
thumbnail_query_result = query(result, thumbnail_query)[0]
|
|
||||||
tmp_result['thumbnail'] = thumbnail_prefix + to_string(thumbnail_query_result)
|
|
||||||
except: # pylint: disable=bare-except
|
|
||||||
continue
|
|
||||||
|
|
||||||
if is_onion:
|
|
||||||
tmp_result['is_onion'] = True
|
|
||||||
|
|
||||||
results.append(tmp_result)
|
|
||||||
else:
|
else:
|
||||||
for result in json:
|
rs = json # pylint: disable=invalid-name
|
||||||
url = query(result, url_query)[0]
|
|
||||||
title = query(result, title_query)[0]
|
|
||||||
content = query(result, content_query)[0]
|
|
||||||
|
|
||||||
results.append(
|
for result in rs:
|
||||||
{
|
tmp_result = extract_response_info(result)
|
||||||
'url': url_prefix + to_string(url),
|
if not tmp_result:
|
||||||
'title': title_filter(to_string(title)),
|
continue
|
||||||
'content': content_filter(to_string(content)),
|
|
||||||
'is_onion': is_onion,
|
if is_onion:
|
||||||
}
|
tmp_result['is_onion'] = True
|
||||||
)
|
|
||||||
|
results.append(tmp_result)
|
||||||
|
|
||||||
if not suggestion_query:
|
if not suggestion_query:
|
||||||
return results
|
return results
|
||||||
|
|
Loading…
Add table
Reference in a new issue