|
@@ -6,7 +6,7 @@
|
|
# pylint: disable=use-dict-literal
|
|
# pylint: disable=use-dict-literal
|
|
|
|
|
|
import json
|
|
import json
|
|
-from urllib.parse import urlencode
|
|
|
|
|
|
+from urllib.parse import urlencode, quote_plus
|
|
|
|
|
|
import lxml
|
|
import lxml
|
|
from httpx import HTTPError
|
|
from httpx import HTTPError
|
|
@@ -16,17 +16,26 @@ from searx.engines import (
|
|
engines,
|
|
engines,
|
|
google,
|
|
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
|
|
from searx.exceptions import SearxEngineResponseException
|
|
|
|
|
|
|
|
|
|
-def get(*args, **kwargs):
|
|
|
|
|
|
+def update_kwargs(**kwargs):
|
|
if 'timeout' not in kwargs:
|
|
if 'timeout' not in kwargs:
|
|
kwargs['timeout'] = settings['outgoing']['request_timeout']
|
|
kwargs['timeout'] = settings['outgoing']['request_timeout']
|
|
kwargs['raise_for_httperror'] = True
|
|
kwargs['raise_for_httperror'] = True
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+def get(*args, **kwargs):
|
|
|
|
+ update_kwargs(**kwargs)
|
|
return http_get(*args, **kwargs)
|
|
return http_get(*args, **kwargs)
|
|
|
|
|
|
|
|
|
|
|
|
+def post(*args, **kwargs):
|
|
|
|
+ update_kwargs(**kwargs)
|
|
|
|
+ return http_post(*args, **kwargs)
|
|
|
|
+
|
|
|
|
+
|
|
def brave(query, _lang):
|
|
def brave(query, _lang):
|
|
# brave search autocompleter
|
|
# brave search autocompleter
|
|
url = 'https://search.brave.com/api/suggest?'
|
|
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):
|
|
def startpage(query, sxng_locale):
|
|
"""Autocomplete from Startpage. Supports Startpage's languages"""
|
|
"""Autocomplete from Startpage. Supports Startpage's languages"""
|
|
lui = engines['startpage'].traits.get_language(sxng_locale, 'english')
|
|
lui = engines['startpage'].traits.get_language(sxng_locale, 'english')
|
|
@@ -223,6 +244,7 @@ backends = {
|
|
'mwmbl': mwmbl,
|
|
'mwmbl': mwmbl,
|
|
'seznam': seznam,
|
|
'seznam': seznam,
|
|
'startpage': startpage,
|
|
'startpage': startpage,
|
|
|
|
+ 'stract': stract,
|
|
'swisscows': swisscows,
|
|
'swisscows': swisscows,
|
|
'qwant': qwant,
|
|
'qwant': qwant,
|
|
'wikipedia': wikipedia,
|
|
'wikipedia': wikipedia,
|