[enh] default disabled engines - closes #109

This commit is contained in:
Adam Tauber 2015-01-31 23:11:45 +01:00
parent bfd321a7a9
commit b19e681cce
5 changed files with 23 additions and 16 deletions

View File

@ -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('_'):

View File

@ -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 = []

View File

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

View File

@ -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]

View File

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