diff options
author | Bnyro <bnyro@tutanota.com> | 2024-01-05 18:15:42 +0100 |
---|---|---|
committer | Alexandre Flament <alex@al-f.net> | 2024-01-07 11:18:16 +0100 |
commit | 3dea7e609bac72d4a129979ba15315b966ff020f (patch) | |
tree | 65feb678e3388c74628fe4b63420c5614f0ed262 /searx/autocomplete.py | |
parent | 621e1313aff3c1fd7b6cc789d34311b11f877f43 (diff) | |
download | searxng-3dea7e609bac72d4a129979ba15315b966ff020f.tar.gz searxng-3dea7e609bac72d4a129979ba15315b966ff020f.zip |
[feat] autocompleter: implementation of stract (beta)
Diffstat (limited to 'searx/autocomplete.py')
-rw-r--r-- | searx/autocomplete.py | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/searx/autocomplete.py b/searx/autocomplete.py index 58655e26f..49e1eaa6a 100644 --- a/searx/autocomplete.py +++ b/searx/autocomplete.py @@ -6,7 +6,7 @@ # pylint: disable=use-dict-literal import json -from urllib.parse import urlencode +from urllib.parse import urlencode, quote_plus import lxml from httpx import HTTPError @@ -16,17 +16,26 @@ from searx.engines import ( engines, google, ) -from searx.network import get as http_get +from searx.network import get as http_get, post as http_post from searx.exceptions import SearxEngineResponseException -def get(*args, **kwargs): +def update_kwargs(**kwargs): if 'timeout' not in kwargs: kwargs['timeout'] = settings['outgoing']['request_timeout'] kwargs['raise_for_httperror'] = True + + +def get(*args, **kwargs): + update_kwargs(**kwargs) return http_get(*args, **kwargs) +def post(*args, **kwargs): + update_kwargs(**kwargs) + return http_post(*args, **kwargs) + + def brave(query, _lang): # brave search autocompleter url = 'https://search.brave.com/api/suggest?' @@ -145,6 +154,18 @@ def seznam(query, _lang): ] +def stract(query, _lang): + # stract autocompleter (beta) + url = f"https://stract.com/beta/api/autosuggest?q={quote_plus(query)}" + + resp = post(url) + + if not resp.ok: + return [] + + return [suggestion['raw'] for suggestion in resp.json()] + + def startpage(query, sxng_locale): """Autocomplete from Startpage. Supports Startpage's languages""" lui = engines['startpage'].traits.get_language(sxng_locale, 'english') @@ -223,6 +244,7 @@ backends = { 'mwmbl': mwmbl, 'seznam': seznam, 'startpage': startpage, + 'stract': stract, 'swisscows': swisscows, 'qwant': qwant, 'wikipedia': wikipedia, |