mirror of
https://github.com/searxng/searxng.git
synced 2024-11-22 19:01:00 +00:00
[pylint] searx/autocomplete.py
Fix remarks from pylint, BTW set SPDX-License-Identifier. Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
This commit is contained in:
parent
b8c98c4c0d
commit
9c5bac4c43
1 changed files with 19 additions and 24 deletions
|
@ -1,33 +1,23 @@
|
||||||
'''
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
searx is free software: you can redistribute it and/or modify
|
# lint: pylint
|
||||||
it under the terms of the GNU Affero General Public License as published by
|
"""This module implements functions needed for the autocompleter.
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
searx is distributed in the hope that it will be useful,
|
"""
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU Affero General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU Affero General Public License
|
|
||||||
along with searx. If not, see < http://www.gnu.org/licenses/ >.
|
|
||||||
|
|
||||||
(C) 2013- by Adam Tauber, <asciimoo@gmail.com>
|
|
||||||
'''
|
|
||||||
|
|
||||||
|
|
||||||
from lxml import etree
|
|
||||||
from json import loads
|
from json import loads
|
||||||
from urllib.parse import urlencode
|
from urllib.parse import urlencode
|
||||||
|
|
||||||
|
from lxml import etree
|
||||||
from httpx import HTTPError
|
from httpx import HTTPError
|
||||||
|
|
||||||
|
|
||||||
from searx import settings
|
from searx import settings
|
||||||
from searx.data import ENGINES_LANGUAGES
|
from searx.data import ENGINES_LANGUAGES
|
||||||
from searx.network import get as http_get
|
from searx.network import get as http_get
|
||||||
from searx.exceptions import SearxEngineResponseException
|
from searx.exceptions import SearxEngineResponseException
|
||||||
|
|
||||||
|
# a fetch_supported_languages() for XPath engines isn't available right now
|
||||||
|
# _brave = ENGINES_LANGUAGES['brave'].keys()
|
||||||
|
|
||||||
|
|
||||||
def get(*args, **kwargs):
|
def get(*args, **kwargs):
|
||||||
if 'timeout' not in kwargs:
|
if 'timeout' not in kwargs:
|
||||||
|
@ -36,10 +26,15 @@ def get(*args, **kwargs):
|
||||||
return http_get(*args, **kwargs)
|
return http_get(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
def brave(query, lang):
|
def brave(query, _lang):
|
||||||
# brave search autocompleter
|
# brave search autocompleter
|
||||||
url = 'https://search.brave.com/api/suggest?{query}'
|
url = 'https://search.brave.com/api/suggest?'
|
||||||
resp = get(url.format(query=urlencode({'q': query})))
|
url += urlencode({'q': query})
|
||||||
|
country = 'all'
|
||||||
|
# if lang in _brave:
|
||||||
|
# country = lang
|
||||||
|
kwargs = {'cookies': {'country': country}}
|
||||||
|
resp = get(url, **kwargs)
|
||||||
|
|
||||||
results = []
|
results = []
|
||||||
|
|
||||||
|
@ -50,7 +45,7 @@ def brave(query, lang):
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
|
||||||
def dbpedia(query, lang):
|
def dbpedia(query, _lang):
|
||||||
# dbpedia autocompleter, no HTTPS
|
# dbpedia autocompleter, no HTTPS
|
||||||
autocomplete_url = 'https://lookup.dbpedia.org/api/search.asmx/KeywordSearch?'
|
autocomplete_url = 'https://lookup.dbpedia.org/api/search.asmx/KeywordSearch?'
|
||||||
|
|
||||||
|
@ -65,7 +60,7 @@ def dbpedia(query, lang):
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
|
||||||
def duckduckgo(query, lang):
|
def duckduckgo(query, _lang):
|
||||||
# duckduckgo autocompleter
|
# duckduckgo autocompleter
|
||||||
url = 'https://ac.duckduckgo.com/ac/?{0}&type=list'
|
url = 'https://ac.duckduckgo.com/ac/?{0}&type=list'
|
||||||
|
|
||||||
|
@ -99,7 +94,7 @@ def startpage(query, lang):
|
||||||
return [e['text'] for e in data.get('suggestions', []) if 'text' in e]
|
return [e['text'] for e in data.get('suggestions', []) if 'text' in e]
|
||||||
|
|
||||||
|
|
||||||
def swisscows(query, lang):
|
def swisscows(query, _lang):
|
||||||
# swisscows autocompleter
|
# swisscows autocompleter
|
||||||
url = 'https://swisscows.ch/api/suggest?{query}&itemsCount=5'
|
url = 'https://swisscows.ch/api/suggest?{query}&itemsCount=5'
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue