logo

searx

My custom branche(s) on searx, a meta-search engine
commit: b19e681cce9cef4993b17d3a89d743208f8d5c05
parent: bfd321a7a9cfc6d643fdebe5e7a5824fe70b9aa9
Author: Adam Tauber <asciimoo@gmail.com>
Date:   Sat, 31 Jan 2015 23:11:45 +0100

[enh] default disabled engines - closes #109

Diffstat:

Msearx/engines/__init__.py6+++---
Msearx/search.py7++-----
Msearx/settings.yml7++++++-
Msearx/utils.py8++++++++
Msearx/webapp.py11++++-------
5 files changed, 23 insertions(+), 16 deletions(-)

diff --git 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 @@ -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 @@ -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 @@ -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 @@ -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