forked from Ponysearch/Ponysearch
Merge pull request #1185 from return42/fix-1142
[fix] format.python: regexp argument '--include' in BLACK_TARGETS
This commit is contained in:
commit
6db568bf69
6 changed files with 41 additions and 37 deletions
2
manage
2
manage
|
@ -30,7 +30,7 @@ GECKODRIVER_VERSION="v0.30.0"
|
||||||
export NODE_MINIMUM_VERSION="16.13.0"
|
export NODE_MINIMUM_VERSION="16.13.0"
|
||||||
# SPHINXOPTS=
|
# SPHINXOPTS=
|
||||||
BLACK_OPTIONS=("--target-version" "py37" "--line-length" "120" "--skip-string-normalization")
|
BLACK_OPTIONS=("--target-version" "py37" "--line-length" "120" "--skip-string-normalization")
|
||||||
BLACK_TARGETS=("--exclude" "searx/static,searx/languages.py" "--include" "searxng.msg" "searx" "searxng_extra" "tests")
|
BLACK_TARGETS=("--exclude" "searx/static,searx/languages.py" "--include" 'searxng.msg|\.pyi?$' "searx" "searxng_extra" "tests")
|
||||||
|
|
||||||
pylint.FILES() {
|
pylint.FILES() {
|
||||||
|
|
||||||
|
|
|
@ -89,17 +89,24 @@ def seznam(query, _lang):
|
||||||
# seznam search autocompleter
|
# seznam search autocompleter
|
||||||
url = 'https://suggest.seznam.cz/fulltext/cs?{query}'
|
url = 'https://suggest.seznam.cz/fulltext/cs?{query}'
|
||||||
|
|
||||||
resp = get(url.format(query=urlencode(
|
resp = get(
|
||||||
|
url.format(
|
||||||
|
query=urlencode(
|
||||||
{'phrase': query, 'cursorPosition': len(query), 'format': 'json-2', 'highlight': '1', 'count': '6'}
|
{'phrase': query, 'cursorPosition': len(query), 'format': 'json-2', 'highlight': '1', 'count': '6'}
|
||||||
)))
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
if not resp.ok:
|
if not resp.ok:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
data = resp.json()
|
data = resp.json()
|
||||||
return [''.join(
|
return [
|
||||||
[part.get('text', '') for part in item.get('text', [])]
|
''.join([part.get('text', '') for part in item.get('text', [])])
|
||||||
) for item in data.get('result', []) if item.get('itemType', None) == 'ItemType.TEXT']
|
for item in data.get('result', [])
|
||||||
|
if item.get('itemType', None) == 'ItemType.TEXT'
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
def startpage(query, lang):
|
def startpage(query, lang):
|
||||||
# startpage autocompleter
|
# startpage autocompleter
|
||||||
|
|
|
@ -58,7 +58,7 @@ search_url = (
|
||||||
'fields={fields}&password_protected={password_protected}&private={private}&sort={sort}&limit={limit}'
|
'fields={fields}&password_protected={password_protected}&private={private}&sort={sort}&limit={limit}'
|
||||||
).format(
|
).format(
|
||||||
fields=','.join(result_fields),
|
fields=','.join(result_fields),
|
||||||
password_protected= 'false',
|
password_protected='false',
|
||||||
private='false',
|
private='false',
|
||||||
sort='relevance',
|
sort='relevance',
|
||||||
limit=number_of_results,
|
limit=number_of_results,
|
||||||
|
@ -170,7 +170,4 @@ def response(resp):
|
||||||
# get supported languages from their site
|
# get supported languages from their site
|
||||||
def _fetch_supported_languages(resp):
|
def _fetch_supported_languages(resp):
|
||||||
response_json = resp.json()
|
response_json = resp.json()
|
||||||
return [
|
return [item['locale'] for item in response_json['list']]
|
||||||
item['locale']
|
|
||||||
for item in response_json['list']
|
|
||||||
]
|
|
||||||
|
|
|
@ -54,18 +54,15 @@ def response(resp):
|
||||||
title += ' (' + title_raw['reading'] + ')'
|
title += ' (' + title_raw['reading'] + ')'
|
||||||
alt_forms.append(title)
|
alt_forms.append(title)
|
||||||
|
|
||||||
#
|
|
||||||
result_url = urljoin(BASE_URL, page['slug'])
|
result_url = urljoin(BASE_URL, page['slug'])
|
||||||
definitions = get_definitions(page)
|
definitions = get_definitions(page)
|
||||||
|
|
||||||
# For results, we'll return the URL, all alternative forms (as title),
|
# For results, we'll return the URL, all alternative forms (as title),
|
||||||
# and all definitions (as description) truncated to 300 characters.
|
# and all definitions (as description) truncated to 300 characters.
|
||||||
content = " ".join(f"{engdef}." for _, engdef, _ in definitions)
|
content = " ".join(f"{engdef}." for _, engdef, _ in definitions)
|
||||||
results.append({
|
results.append(
|
||||||
'url': result_url,
|
{'url': result_url, 'title': ", ".join(alt_forms), 'content': content[:300] + (content[300:] and '...')}
|
||||||
'title': ", ".join(alt_forms),
|
)
|
||||||
'content': content[:300] + (content[300:] and '...')
|
|
||||||
})
|
|
||||||
|
|
||||||
# Like Wordnik, we'll return the first result in an infobox too.
|
# Like Wordnik, we'll return the first result in an infobox too.
|
||||||
if first_result:
|
if first_result:
|
||||||
|
@ -93,11 +90,13 @@ def get_definitions(page):
|
||||||
extra.append(', '.join(defn_raw['info']).capitalize() + '. ')
|
extra.append(', '.join(defn_raw['info']).capitalize() + '. ')
|
||||||
if defn_raw.get('restrictions'):
|
if defn_raw.get('restrictions'):
|
||||||
extra.append('Only applies to: ' + ', '.join(defn_raw['restrictions']) + '. ')
|
extra.append('Only applies to: ' + ', '.join(defn_raw['restrictions']) + '. ')
|
||||||
definitions.append((
|
definitions.append(
|
||||||
|
(
|
||||||
', '.join(defn_raw['parts_of_speech']),
|
', '.join(defn_raw['parts_of_speech']),
|
||||||
'; '.join(defn_raw['english_definitions']),
|
'; '.join(defn_raw['english_definitions']),
|
||||||
''.join(extra)[:-1],
|
''.join(extra)[:-1],
|
||||||
))
|
)
|
||||||
|
)
|
||||||
return definitions
|
return definitions
|
||||||
|
|
||||||
|
|
||||||
|
@ -109,12 +108,14 @@ def get_infobox(alt_forms, result_url, definitions):
|
||||||
infobox_content.append(f'<p><i>Other forms:</i> {", ".join(alt_forms[1:])}</p>')
|
infobox_content.append(f'<p><i>Other forms:</i> {", ".join(alt_forms[1:])}</p>')
|
||||||
|
|
||||||
# definitions
|
# definitions
|
||||||
infobox_content.append('''
|
infobox_content.append(
|
||||||
|
'''
|
||||||
<small><a href="https://www.edrdg.org/wiki/index.php/JMdict-EDICT_Dictionary_Project">JMdict</a>
|
<small><a href="https://www.edrdg.org/wiki/index.php/JMdict-EDICT_Dictionary_Project">JMdict</a>
|
||||||
and <a href="https://www.edrdg.org/enamdict/enamdict_doc.html">JMnedict</a>
|
and <a href="https://www.edrdg.org/enamdict/enamdict_doc.html">JMnedict</a>
|
||||||
by <a href="https://www.edrdg.org/edrdg/licence.html">EDRDG</a>, CC BY-SA 3.0.</small>
|
by <a href="https://www.edrdg.org/edrdg/licence.html">EDRDG</a>, CC BY-SA 3.0.</small>
|
||||||
<ul>
|
<ul>
|
||||||
''')
|
'''
|
||||||
|
)
|
||||||
for pos, engdef, extra in definitions:
|
for pos, engdef, extra in definitions:
|
||||||
if pos == 'Wikipedia definition':
|
if pos == 'Wikipedia definition':
|
||||||
infobox_content.append('</ul><small>Wikipedia, CC BY-SA 3.0.</small><ul>')
|
infobox_content.append('</ul><small>Wikipedia, CC BY-SA 3.0.</small><ul>')
|
||||||
|
@ -132,5 +133,5 @@ def get_infobox(alt_forms, result_url, definitions):
|
||||||
'title': 'Jisho.org',
|
'title': 'Jisho.org',
|
||||||
'url': result_url,
|
'url': result_url,
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,11 +77,9 @@ class InfoPage:
|
||||||
.. _markdown-it-py: https://github.com/executablebooks/markdown-it-py
|
.. _markdown-it-py: https://github.com/executablebooks/markdown-it-py
|
||||||
|
|
||||||
"""
|
"""
|
||||||
return MarkdownIt(
|
return (
|
||||||
"commonmark", {"typographer": True}
|
MarkdownIt("commonmark", {"typographer": True}).enable(["replacements", "smartquotes"]).render(self.content)
|
||||||
).enable(
|
)
|
||||||
["replacements", "smartquotes"]
|
|
||||||
).render(self.content)
|
|
||||||
|
|
||||||
def get_ctx(self): # pylint: disable=no-self-use
|
def get_ctx(self): # pylint: disable=no-self-use
|
||||||
"""Jinja context to render :py:obj:`InfoPage.content`"""
|
"""Jinja context to render :py:obj:`InfoPage.content`"""
|
||||||
|
|
|
@ -449,7 +449,7 @@ def get_client_settings():
|
||||||
req_pref = request.preferences
|
req_pref = request.preferences
|
||||||
return {
|
return {
|
||||||
'autocomplete_provider': req_pref.get_value('autocomplete'),
|
'autocomplete_provider': req_pref.get_value('autocomplete'),
|
||||||
'autocomplete_min' : get_setting('search.autocomplete_min'),
|
'autocomplete_min': get_setting('search.autocomplete_min'),
|
||||||
'http_method': req_pref.get_value('method'),
|
'http_method': req_pref.get_value('method'),
|
||||||
'infinite_scroll': req_pref.get_value('infinite_scroll'),
|
'infinite_scroll': req_pref.get_value('infinite_scroll'),
|
||||||
'translations': get_translations(),
|
'translations': get_translations(),
|
||||||
|
@ -467,7 +467,8 @@ def render(template_name: str, override_theme: str = None, **kwargs):
|
||||||
json.dumps(get_client_settings()),
|
json.dumps(get_client_settings()),
|
||||||
encoding='utf-8',
|
encoding='utf-8',
|
||||||
)
|
)
|
||||||
), encoding='utf-8',
|
),
|
||||||
|
encoding='utf-8',
|
||||||
)
|
)
|
||||||
|
|
||||||
# obsolete, only needed by oscar
|
# obsolete, only needed by oscar
|
||||||
|
|
Loading…
Reference in a new issue