From c09ff4faf23fc13579ed350344de7f193a6b1869 Mon Sep 17 00:00:00 2001 From: Alexandre Flament Date: Wed, 7 Apr 2021 10:31:45 +0200 Subject: [PATCH 1/3] [fix] fix PR 2656 SCRIPT_NAME remove trailing slash to avoid infinite redirect --- searx/webapp.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/searx/webapp.py b/searx/webapp.py index 4c09f0ac..072f140c 100755 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -1133,11 +1133,14 @@ class ReverseProxyPathFix: base_url = urlparse(settings['server']['base_url']) self.script_name = base_url.path + if self.script_name.endswith('/'): + # remove trailing slash to avoid infinite redirect on the index + # see https://github.com/searx/searx/issues/2729 + self.script_name = self.script_name[:-1] self.scheme = base_url.scheme self.server = base_url.netloc def __call__(self, environ, start_response): - script_name = self.script_name or environ.get('HTTP_X_SCRIPT_NAME', '') if script_name: environ['SCRIPT_NAME'] = script_name From 7035bed4ee2c8aa40c80b41e11cc538583e2b2de Mon Sep 17 00:00:00 2001 From: Plague Doctor Date: Thu, 8 Apr 2021 09:58:00 +1000 Subject: [PATCH 2/3] Add new engine: Wordnik.com --- searx/engines/wordnik.py | 77 ++++++++++++++++++++++++++++++++++++++++ searx/settings.yml | 8 +++++ 2 files changed, 85 insertions(+) create mode 100644 searx/engines/wordnik.py diff --git a/searx/engines/wordnik.py b/searx/engines/wordnik.py new file mode 100644 index 00000000..3abe9efa --- /dev/null +++ b/searx/engines/wordnik.py @@ -0,0 +1,77 @@ +# SPDX-License-Identifier: AGPL-3.0-or-later +"""Wordnik (general) + +""" + +from lxml.html import fromstring +from searx import logger +from searx.utils import extract_text +from searx.raise_for_httperror import raise_for_httperror + +logger = logger.getChild('Wordnik engine') + +# about +about = { + "website": 'https://www.wordnik.com', + "wikidata_id": 'Q8034401', + "official_api_documentation": None, + "use_official_api": False, + "require_api_key": False, + "results": 'HTML', +} + +categories = ['general'] +paging = False + +URL = 'https://www.wordnik.com' +SEARCH_URL = URL + '/words/{query}' + + +def request(query, params): + params['url'] = SEARCH_URL.format(query=query) + logger.debug(f"query_url --> {params['url']}") + return params + + +def response(resp): + results = [] + + raise_for_httperror(resp) + dom = fromstring(resp.text) + word = extract_text(dom.xpath('//*[@id="headword"]/text()')) + + definitions = [] + for src in dom.xpath('//*[@id="define"]//h3[@class="source"]'): + src_text = extract_text(src).strip() + if src_text.startswith('from '): + src_text = src_text[5:] + + src_defs = [] + for def_item in src.xpath('following-sibling::ul[1]/li'): + def_abbr = extract_text(def_item.xpath('.//abbr')).strip() + def_text = extract_text(def_item).strip() + if def_abbr: + def_text = def_text[len(def_abbr):].strip() + src_defs.append((def_abbr, def_text)) + + definitions.append((src_text, src_defs)) + + if not definitions: + return results + + infobox = '' + for src_text, src_defs in definitions: + infobox += f"{src_text}" + infobox += "" + + results.append({ + 'infobox': word, + 'content': infobox, + }) + + return results diff --git a/searx/settings.yml b/searx/settings.yml index 3428b2ec..c289cde5 100644 --- a/searx/settings.yml +++ b/searx/settings.yml @@ -1271,6 +1271,14 @@ engines: categories: videos disabled : True + - name: wordnik + engine: wordnik + shortcut: def + base_url: https://www.wordnik.com/ + categories: general + timeout: 5.0 + disabled: True + # Doku engine lets you access to any Doku wiki instance: # A public one or a privete/corporate one. # - name : ubuntuwiki From 4557d58919333998bb199653920f1234d67b20b1 Mon Sep 17 00:00:00 2001 From: Markus Heiser Date: Thu, 8 Apr 2021 14:47:24 +0200 Subject: [PATCH 3/3] [fix] docutils v0.17 incompatibility to previeous v0.16 With docutils v0.17 a lot of html markup has been changed (see below) what cause a lot of problems in CSS from Sphinx and other Sphinx extensions & customizing. For the first this fix pins to previous v0.16. In sphinx 4.0 these problems will be addressed [2] and we can relax (drop) in the requirements-dev. HTML5 writer [1]: Use the new semantic tags
,
,
,