From b19e681cce9cef4993b17d3a89d743208f8d5c05 Mon Sep 17 00:00:00 2001 From: Adam Tauber Date: Sat, 31 Jan 2015 23:11:45 +0100 Subject: [PATCH] [enh] default disabled engines - closes #109 --- searx/engines/__init__.py | 6 +++--- searx/search.py | 7 ++----- searx/settings.yml | 7 ++++++- searx/utils.py | 8 ++++++++ searx/webapp.py | 11 ++++------- 5 files changed, 23 insertions(+), 16 deletions(-) diff --git a/searx/engines/__init__.py b/searx/engines/__init__.py index 643b107a5..21a307501 100644 --- a/searx/engines/__init__.py +++ b/searx/engines/__init__.py @@ -69,17 +69,17 @@ def load_engine(engine_data): engine.categories = ['general'] if not hasattr(engine, 'language_support'): - # engine.language_support = False engine.language_support = True if not hasattr(engine, 'timeout'): - # engine.language_support = False engine.timeout = settings['server']['request_timeout'] if not hasattr(engine, 'shortcut'): - # engine.shortcut = ''' engine.shortcut = '' + if not hasattr(engine, 'disabled'): + engine.disabled = False + # checking required variables for engine_attr in dir(engine): if engine_attr.startswith('_'): diff --git a/searx/search.py b/searx/search.py index b6cf84e94..c16346f45 100644 --- a/searx/search.py +++ b/searx/search.py @@ -27,7 +27,7 @@ from searx.engines import ( categories, engines ) from searx.languages import language_codes -from searx.utils import gen_useragent +from searx.utils import gen_useragent, get_blocked_engines from searx.query import Query from searx import logger @@ -320,10 +320,7 @@ class Search(object): self.lang = 'all' # set blocked engines - if request.cookies.get('blocked_engines'): - self.blocked_engines = request.cookies['blocked_engines'].split(',') # noqa - else: - self.blocked_engines = [] + self.blocked_engines = get_blocked_engines(engines, request.cookies) self.results = [] self.suggestions = [] diff --git a/searx/settings.yml b/searx/settings.yml index b0a2853c7..ebae8af62 100644 --- a/searx/settings.yml +++ b/searx/settings.yml @@ -96,6 +96,7 @@ engines: - name : general-file engine : generalfile shortcut : gf + disabled : True - name : github engine : github @@ -121,6 +122,7 @@ engines: content_xpath : //a[@class="subtitle"] categories : files shortcut : gpa + disabled : True - name : google play movies engine : xpath @@ -130,6 +132,7 @@ engines: content_xpath : //a[@class="subtitle"] categories : videos shortcut : gpm + disabled : True - name : google play music engine : xpath @@ -139,6 +142,7 @@ engines: content_xpath : //a[@class="subtitle"] categories : music shortcut : gps + disabled : True - name : mixcloud engine : mixcloud @@ -175,6 +179,7 @@ engines: - name : searchcode code engine : searchcode_code shortcut : scc + disabled : True - name : subtitleseeker engine : subtitleseeker @@ -239,7 +244,7 @@ engines: # shortcut : ya # base_url : 'http://localhost:8090' # number_of_results : 5 -# timeout: 3.0 +# timeout : 3.0 locales: en : English diff --git a/searx/utils.py b/searx/utils.py index cd2392b9d..c47d3be17 100644 --- a/searx/utils.py +++ b/searx/utils.py @@ -225,3 +225,11 @@ def prettify_url(url): return u'{0}[...]{1}'.format(url[:35], url[-35:]) else: return url + + +def get_blocked_engines(engines, cookies): + if 'blocked_engines' not in cookies: + return [engine for engine in engines if engines[engine].disabled] + + return [engine for engine in cookies.get('blocked_engines', '').split(',') + if engine in engines] diff --git a/searx/webapp.py b/searx/webapp.py index 4300c1dca..d612af410 100644 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -43,7 +43,7 @@ from searx.engines import ( from searx.utils import ( UnicodeWriter, highlight_content, html_to_text, get_themes, get_static_files, get_result_templates, gen_useragent, dict_subset, - prettify_url + prettify_url, get_blocked_engines ) from searx.version import VERSION_STRING from searx.languages import language_codes @@ -225,7 +225,7 @@ def image_proxify(url): def render(template_name, override_theme=None, **kwargs): - blocked_engines = request.cookies.get('blocked_engines', '').split(',') + blocked_engines = get_blocked_engines(engines, request.cookies) autocomplete = request.cookies.get('autocomplete') @@ -410,10 +410,7 @@ def autocompleter(): request_data = request.args # set blocked engines - if request.cookies.get('blocked_engines'): - blocked_engines = request.cookies['blocked_engines'].split(',') # noqa - else: - blocked_engines = [] + blocked_engines = get_blocked_engines(engines, request.cookies) # parse query query = Query(request_data.get('q', '').encode('utf-8'), blocked_engines) @@ -468,7 +465,7 @@ def preferences(): resp = make_response(redirect(url_for('index'))) if request.method == 'GET': - blocked_engines = request.cookies.get('blocked_engines', '').split(',') + blocked_engines = get_blocked_engines(engines, request.cookies) else: # on save selected_categories = [] locale = None