def config(): return jsonify({'categories': categories.keys(), 'engines': [{'name': engine_name, 'categories': engine.categories, 'shortcut': engine.shortcut, 'enabled': not engine.disabled, 'paging': engine.paging, 'language_support': engine.language_support, 'supported_languages': engine.supported_languages.keys() if isinstance(engine.supported_languages, dict) else engine.supported_languages, 'safesearch': engine.safesearch, 'time_range_support': engine.time_range_support, 'timeout': engine.timeout} for engine_name, engine in engines.items()], 'plugins': [{'name': plugin.name, 'enabled': plugin.default_on} for plugin in plugins], 'instance_name': settings['general']['instance_name'], 'locales': settings['locales'], 'default_locale': settings['ui']['default_locale'], 'autocomplete': settings['search']['autocomplete'], 'safe_search': settings['search']['safe_search'], 'default_theme': settings['ui']['default_theme'], 'version': VERSION_STRING, 'doi_resolvers': [r for r in settings['doi_resolvers']], 'default_doi_resolver': settings['default_doi_resolver'], })
def pre_request(): request.errors = [] preferences = Preferences(themes, list(categories.keys()), engines, plugins) request.preferences = preferences try: preferences.parse_dict(request.cookies) except: request.errors.append(gettext('Invalid settings, please edit your preferences')) # merge GET, POST vars # request.form request.form = dict(request.form.items()) for k, v in request.args.items(): if k not in request.form: request.form[k] = v if request.form.get('preferences'): preferences.parse_encoded_data(request.form['preferences']) else: try: preferences.parse_dict(request.form) except Exception as e: logger.exception('invalid settings') request.errors.append(gettext('Invalid settings')) # request.user_plugins request.user_plugins = [] allowed_plugins = preferences.plugins.get_enabled() disabled_plugins = preferences.plugins.get_disabled() for plugin in plugins: if ((plugin.default_on and plugin.id not in disabled_plugins) or plugin.id in allowed_plugins): request.user_plugins.append(plugin)
def render(template_name, **kwargs): global categories kwargs['categories'] = sorted(categories.keys()) if not 'selected_categories' in kwargs: kwargs['selected_categories'] = [] cookie_categories = request.cookies.get('categories', '').split(',') for ccateg in cookie_categories: if ccateg in categories: kwargs['selected_categories'].append(ccateg) if not len(kwargs['selected_categories']): kwargs['selected_categories'] = ['general'] return render_template(template_name, **kwargs)
def render(template_name, override_theme=None, **kwargs): blocked_engines = request.cookies.get('blocked_engines', '').split(',') autocomplete = request.cookies.get('autocomplete') if autocomplete not in autocomplete_backends: autocomplete = None nonblocked_categories = (engines[e].categories for e in engines if e not in blocked_engines) nonblocked_categories = set(chain.from_iterable(nonblocked_categories)) if 'categories' not in kwargs: kwargs['categories'] = ['general'] kwargs['categories'].extend(x for x in sorted(categories.keys()) if x != 'general' and x in nonblocked_categories) if 'selected_categories' not in kwargs: kwargs['selected_categories'] = [] for arg in request.args: if arg.startswith('category_'): c = arg.split('_', 1)[1] if c in categories: kwargs['selected_categories'].append(c) if not kwargs['selected_categories']: cookie_categories = request.cookies.get('categories', '').split(',') for ccateg in cookie_categories: if ccateg in categories: kwargs['selected_categories'].append(ccateg) if not kwargs['selected_categories']: kwargs['selected_categories'] = ['general'] if 'autocomplete' not in kwargs: kwargs['autocomplete'] = autocomplete kwargs['searx_version'] = VERSION_STRING kwargs['method'] = request.cookies.get('method', 'POST') # override url_for function in templates kwargs['url_for'] = url_for_theme kwargs['theme'] = get_current_theme_name(override=override_theme) kwargs['template_name'] = template_name return render_template( '{}/{}'.format(kwargs['theme'], template_name), **kwargs)
def config(): return jsonify({'categories': categories.keys(), 'engines': [{'name': engine_name, 'categories': engine.categories, 'enabled': not engine.disabled} for engine_name, engine in engines.items()], 'plugins': [{'name': plugin.name, 'enabled': plugin.default_on} for plugin in plugins], 'instance_name': settings['general']['instance_name'], 'locales': settings['locales'], 'default_locale': settings['ui']['default_locale'], 'autocomplete': settings['search']['autocomplete'], 'safe_search': settings['search']['safe_search'], 'default_theme': settings['ui']['default_theme']})
def config(): """Return configuration in JSON format.""" _engines = [] for name, engine in engines.items(): if not request.preferences.validate_token(engine): continue supported_languages = engine.supported_languages if isinstance(engine.supported_languages, dict): supported_languages = list(engine.supported_languages.keys()) _engines.append({ 'name': name, 'categories': engine.categories, 'shortcut': engine.shortcut, 'enabled': not engine.disabled, 'paging': engine.paging, 'language_support': engine.language_support, 'supported_languages': supported_languages, 'safesearch': engine.safesearch, 'time_range_support': engine.time_range_support, 'timeout': engine.timeout }) _plugins = [] for _ in plugins: _plugins.append({'name': _.name, 'enabled': _.default_on}) return jsonify({ 'categories': list(categories.keys()), 'engines': _engines, 'plugins': _plugins, 'instance_name': settings['general']['instance_name'], 'locales': settings['locales'], 'default_locale': settings['ui']['default_locale'], 'autocomplete': settings['search']['autocomplete'], 'safe_search': settings['search']['safe_search'], 'default_theme': settings['ui']['default_theme'], 'version': VERSION_STRING, 'brand': { 'GIT_URL': brand.GIT_URL, 'DOCS_URL': brand.DOCS_URL }, 'doi_resolvers': [r for r in settings['doi_resolvers']], 'default_doi_resolver': settings['default_doi_resolver'], })
def pre_request(): request.start_time = time() request.timings = [] request.errors = [] preferences = Preferences(themes, list(categories.keys()), engines, plugins) user_agent = request.headers.get('User-Agent', '').lower() if 'webkit' in user_agent and 'android' in user_agent: preferences.key_value_settings['method'].value = 'GET' request.preferences = preferences try: preferences.parse_dict(request.cookies) except: request.errors.append(gettext('Invalid settings, please edit your preferences')) # merge GET, POST vars # request.form request.form = dict(request.form.items()) for k, v in request.args.items(): if k not in request.form: request.form[k] = v if request.form.get('preferences'): preferences.parse_encoded_data(request.form['preferences']) else: try: preferences.parse_dict(request.form) except Exception: logger.exception('invalid settings') request.errors.append(gettext('Invalid settings')) # init search language and locale if not preferences.get_value("language"): preferences.parse_dict({"language": _get_browser_or_settings_language(request, LANGUAGE_CODES)}) if not preferences.get_value("locale"): preferences.parse_dict({"locale": get_locale()}) # request.user_plugins request.user_plugins = [] allowed_plugins = preferences.plugins.get_enabled() disabled_plugins = preferences.plugins.get_disabled() for plugin in plugins: if ((plugin.default_on and plugin.id not in disabled_plugins) or plugin.id in allowed_plugins): request.user_plugins.append(plugin)
def pre_request(): # merge GET, POST vars preferences = Preferences(themes, categories.keys(), engines, plugins) preferences.parse_cookies(request.cookies) request.preferences = preferences request.form = dict(request.form.items()) for k, v in request.args.items(): if k not in request.form: request.form[k] = v request.user_plugins = [] allowed_plugins = preferences.plugins.get_enabled() disabled_plugins = preferences.plugins.get_disabled() for plugin in plugins: if ((plugin.default_on and plugin.id not in disabled_plugins) or plugin.id in allowed_plugins): request.user_plugins.append(plugin)
def get_default_settings(): engs = [] langs = [] plugs = [] for engine in engines.values(): eng = { 'name': engine.name, 'paging': engine.paging, 'categories': engine.categories, 'language_support': engine.language_support, 'safesearch': engine.safesearch, 'timeout': engine.timeout, 'shortcut': engine.shortcut, 'disabled': engine.disabled } engs.append(eng) for plugin in plugins: plug = { 'name': plugin.name, 'allow': plugin.default_on, 'description': plugin.description } plugs.append(plug) for lang_id, lang_name, country_name in language_codes: lang = { 'id': lang_id, 'name': lang_name, 'country_name': country_name } langs.append(lang) setting = {'engines': engs, 'default_locale': get_locale(), 'locales': settings['locales'], 'all_categories': sorted(categories.keys()), 'search': settings['search'], 'image_proxy': settings['server'].get('image_proxy'), 'plugins': plugs, 'languages': langs, 'version': VERSION_STRING} return setting
def pre_request(): request.start_time = time() request.timings = [] request.errors = [] preferences = Preferences(themes, list(categories.keys()), engines, plugins) request.preferences = preferences try: preferences.parse_dict(request.cookies) except: request.errors.append(gettext('Invalid settings, please edit your preferences')) # merge GET, POST vars # request.form request.form = dict(request.form.items()) for k, v in request.args.items(): if k not in request.form: request.form[k] = v # todo 缓存机制 # 关键词累积加一 kr.keyNum(request.form['q']) # 查询form是否存在,存在将结果直接返回 if request.form.get('research') == '0' and kr.existsForm(json.dumps(request.form)): request.form['Result'] = kr.getResult(json.dumps(request.form)) if request.form.get('preferences'): preferences.parse_encoded_data(request.form['preferences']) else: try: preferences.parse_dict(request.form) except Exception as e: logger.exception('invalid settings') request.errors.append(gettext('Invalid settings')) # request.user_plugins request.user_plugins = [] allowed_plugins = preferences.plugins.get_enabled() disabled_plugins = preferences.plugins.get_disabled() for plugin in plugins: if ((plugin.default_on and plugin.id not in disabled_plugins) or plugin.id in allowed_plugins): request.user_plugins.append(plugin)
def render(template_name, **kwargs): blocked_engines = request.cookies.get('blocked_engines', '').split(',') nonblocked_categories = (engines[e].categories for e in engines if e not in blocked_engines) nonblocked_categories = set(chain.from_iterable(nonblocked_categories)) if not 'categories' in kwargs: kwargs['categories'] = ['general'] kwargs['categories'].extend(x for x in sorted(categories.keys()) if x != 'general' and x in nonblocked_categories) if not 'selected_categories' in kwargs: kwargs['selected_categories'] = [] cookie_categories = request.cookies.get('categories', '').split(',') for ccateg in cookie_categories: if ccateg in categories: kwargs['selected_categories'].append(ccateg) if not kwargs['selected_categories']: kwargs['selected_categories'] = ['general'] return render_template(template_name, **kwargs)
def pre_request(): # merge GET, POST vars preferences = Preferences(themes, categories.keys(), engines, plugins) try: preferences.parse_cookies(request.cookies) except: # TODO throw error message to the user logger.warning('Invalid config') request.preferences = preferences request.form = dict(request.form.items()) for k, v in request.args.items(): if k not in request.form: request.form[k] = v request.user_plugins = [] allowed_plugins = preferences.plugins.get_enabled() disabled_plugins = preferences.plugins.get_disabled() for plugin in plugins: if ((plugin.default_on and plugin.id not in disabled_plugins) or plugin.id in allowed_plugins): request.user_plugins.append(plugin)
def pre_request(): request.start_time = time() request.timings = [] request.errors = [] preferences = Preferences(themes, list(categories.keys()), engines, plugins) request.preferences = preferences try: preferences.parse_dict(request.cookies) except: request.errors.append( gettext('Invalid settings, please edit your preferences')) # merge GET, POST vars # request.form request.form = dict(request.form.items()) for k, v in request.args.items(): if k not in request.form: request.form[k] = v if request.form.get('preferences'): preferences.parse_encoded_data(request.form['preferences']) else: try: preferences.parse_dict(request.form) except Exception as e: logger.exception('invalid settings') request.errors.append(gettext('Invalid settings')) # request.user_plugins request.user_plugins = [] allowed_plugins = preferences.plugins.get_enabled() disabled_plugins = preferences.plugins.get_disabled() for plugin in plugins: if ((plugin.default_on and plugin.id not in disabled_plugins) or plugin.id in allowed_plugins): request.user_plugins.append(plugin)
def config(): return jsonify( { "categories": categories.keys(), "engines": [ { "name": engine_name, "categories": engine.categories, "shortcut": engine.shortcut, "enabled": not engine.disabled, } for engine_name, engine in engines.items() ], "plugins": [{"name": plugin.name, "enabled": plugin.default_on} for plugin in plugins], "instance_name": settings["general"]["instance_name"], "locales": settings["locales"], "default_locale": settings["ui"]["default_locale"], "autocomplete": settings["search"]["autocomplete"], "safe_search": settings["search"]["safe_search"], "default_theme": settings["ui"]["default_theme"], "version": VERSION_STRING, } )
def pre_request(): request.errors = [] preferences = Preferences(themes, categories.keys(), engines, plugins) request.preferences = preferences try: preferences.parse_cookies(request.cookies) except: request.errors.append(gettext("Invalid settings, please edit your preferences")) # merge GET, POST vars # request.form request.form = dict(request.form.items()) for k, v in request.args.items(): if k not in request.form: request.form[k] = v # request.user_plugins request.user_plugins = [] allowed_plugins = preferences.plugins.get_enabled() disabled_plugins = preferences.plugins.get_disabled() for plugin in plugins: if (plugin.default_on and plugin.id not in disabled_plugins) or plugin.id in allowed_plugins: request.user_plugins.append(plugin)
def config(): return jsonify({'categories': list(categories.keys()), 'engines': [{'name': engine_name, 'categories': engine.categories, 'shortcut': engine.shortcut, 'enabled': not engine.disabled, 'paging': engine.paging, 'language_support': engine.language_support, 'supported_languages': list(engine.supported_languages.keys()) if isinstance(engine.supported_languages, dict) else engine.supported_languages, 'safesearch': engine.safesearch, 'timeout': engine.timeout} for engine_name, engine in engines.items()], 'instance_name': settings['general']['instance_name'], 'locales': settings['locales'], 'default_locale': settings['ui']['default_locale'], 'autocomplete': settings['search']['autocomplete'], 'safe_search': settings['search']['safe_search'], 'default_theme': settings['ui']['default_theme'], 'version': VERSION_STRING, 'default_doi_resolver': settings['default_doi_resolver'], })
def render(template_name, override_theme=None, **kwargs): blocked_engines = get_blocked_engines(engines, request.cookies) autocomplete = request.cookies.get('autocomplete', settings['search']['autocomplete']) if autocomplete not in autocomplete_backends: autocomplete = None nonblocked_categories = set(category for engine_name in engines for category in engines[engine_name].categories if (engine_name, category) not in blocked_engines) if 'categories' not in kwargs: kwargs['categories'] = ['general'] kwargs['categories'].extend(x for x in sorted(categories.keys()) if x != 'general' and x in nonblocked_categories) if 'all_categories' not in kwargs: kwargs['all_categories'] = ['general'] kwargs['all_categories'].extend(x for x in sorted(categories.keys()) if x != 'general') if 'selected_categories' not in kwargs: kwargs['selected_categories'] = [] for arg in request.args: if arg.startswith('category_'): c = arg.split('_', 1)[1] if c in categories: kwargs['selected_categories'].append(c) if not kwargs['selected_categories']: cookie_categories = request.cookies.get('categories', '').split(',') for ccateg in cookie_categories: if ccateg in categories: kwargs['selected_categories'].append(ccateg) if not kwargs['selected_categories']: kwargs['selected_categories'] = ['general'] if 'autocomplete' not in kwargs: kwargs['autocomplete'] = autocomplete if get_locale() in rtl_locales and 'rtl' not in kwargs: kwargs['rtl'] = True kwargs['searx_version'] = VERSION_STRING kwargs['method'] = request.cookies.get('method', 'POST') kwargs['safesearch'] = request.cookies.get('safesearch', str(settings['search']['safe_search'])) # override url_for function in templates kwargs['url_for'] = url_for_theme kwargs['image_proxify'] = image_proxify kwargs['get_result_template'] = get_result_template kwargs['theme'] = get_current_theme_name(override=override_theme) kwargs['template_name'] = template_name kwargs['cookies'] = request.cookies kwargs['scripts'] = set() for plugin in request.user_plugins: for script in plugin.js_dependencies: kwargs['scripts'].add(script) kwargs['styles'] = set() for plugin in request.user_plugins: for css in plugin.css_dependencies: kwargs['styles'].add(css) return render_template( '{}/{}'.format(kwargs['theme'], template_name), **kwargs)
def _get_ordered_categories(): ordered_categories = list(settings['ui']['categories_order']) ordered_categories.extend(x for x in sorted(categories.keys()) if x not in ordered_categories) return ordered_categories
def render(template_name, override_theme=None, **kwargs): disabled_engines = request.preferences.engines.get_disabled() enabled_categories = set( category for engine_name in engines for category in engines[engine_name].categories if (engine_name, category) not in disabled_engines ) if "categories" not in kwargs: kwargs["categories"] = ["general"] kwargs["categories"].extend(x for x in sorted(categories.keys()) if x != "general" and x in enabled_categories) if "all_categories" not in kwargs: kwargs["all_categories"] = ["general"] kwargs["all_categories"].extend(x for x in sorted(categories.keys()) if x != "general") if "selected_categories" not in kwargs: kwargs["selected_categories"] = [] for arg in request.args: if arg.startswith("category_"): c = arg.split("_", 1)[1] if c in categories: kwargs["selected_categories"].append(c) if not kwargs["selected_categories"]: cookie_categories = request.preferences.get_value("categories") for ccateg in cookie_categories: kwargs["selected_categories"].append(ccateg) if not kwargs["selected_categories"]: kwargs["selected_categories"] = ["general"] if "autocomplete" not in kwargs: kwargs["autocomplete"] = request.preferences.get_value("autocomplete") if get_locale() in rtl_locales and "rtl" not in kwargs: kwargs["rtl"] = True kwargs["searx_version"] = VERSION_STRING kwargs["method"] = request.preferences.get_value("method") kwargs["safesearch"] = str(request.preferences.get_value("safesearch")) # override url_for function in templates kwargs["url_for"] = url_for_theme kwargs["image_proxify"] = image_proxify kwargs["proxify"] = proxify if settings.get("result_proxy") else None kwargs["get_result_template"] = get_result_template kwargs["theme"] = get_current_theme_name(override=override_theme) kwargs["template_name"] = template_name kwargs["cookies"] = request.cookies kwargs["errors"] = request.errors kwargs["instance_name"] = settings["general"]["instance_name"] kwargs["results_on_new_tab"] = request.preferences.get_value("results_on_new_tab") kwargs["scripts"] = set() for plugin in request.user_plugins: for script in plugin.js_dependencies: kwargs["scripts"].add(script) kwargs["styles"] = set() for plugin in request.user_plugins: for css in plugin.css_dependencies: kwargs["styles"].add(css) return render_template("{}/{}".format(kwargs["theme"], template_name), **kwargs)
def render(template_name, override_theme=None, **kwargs): disabled_engines = request.preferences.engines.get_disabled() enabled_categories = set(category for engine_name in engines for category in engines[engine_name].categories if (engine_name, category) not in disabled_engines) if 'categories' not in kwargs: kwargs['categories'] = ['general'] kwargs['categories'].extend(x for x in sorted(categories.keys()) if x != 'general' and x in enabled_categories) if 'all_categories' not in kwargs: kwargs['all_categories'] = ['general'] kwargs['all_categories'].extend(x for x in sorted(categories.keys()) if x != 'general') if 'selected_categories' not in kwargs: kwargs['selected_categories'] = [] for arg in request.args: if arg.startswith('category_'): c = arg.split('_', 1)[1] if c in categories: kwargs['selected_categories'].append(c) if not kwargs['selected_categories']: cookie_categories = request.preferences.get_value('categories') for ccateg in cookie_categories: kwargs['selected_categories'].append(ccateg) if not kwargs['selected_categories']: kwargs['selected_categories'] = ['general'] if 'autocomplete' not in kwargs: kwargs['autocomplete'] = request.preferences.get_value('autocomplete') locale = request.preferences.get_value('locale') if locale in rtl_locales and 'rtl' not in kwargs: kwargs['rtl'] = True kwargs['searx_version'] = VERSION_STRING kwargs['method'] = request.preferences.get_value('method') kwargs['safesearch'] = str(request.preferences.get_value('safesearch')) kwargs['language_codes'] = languages if 'current_language' not in kwargs: kwargs['current_language'] = match_language(request.preferences.get_value('language'), LANGUAGE_CODES) # override url_for function in templates kwargs['url_for'] = url_for_theme kwargs['image_proxify'] = image_proxify kwargs['proxify'] = proxify if settings.get('result_proxy', {}).get('url') else None kwargs['get_result_template'] = get_result_template kwargs['theme'] = get_current_theme_name(override=override_theme) kwargs['template_name'] = template_name kwargs['cookies'] = request.cookies kwargs['errors'] = request.errors kwargs['instance_name'] = settings['general']['instance_name'] kwargs['results_on_new_tab'] = request.preferences.get_value('results_on_new_tab') kwargs['unicode'] = unicode kwargs['preferences'] = request.preferences kwargs['brand'] = brand kwargs['scripts'] = set() for plugin in request.user_plugins: for script in plugin.js_dependencies: kwargs['scripts'].add(script) kwargs['styles'] = set() for plugin in request.user_plugins: for css in plugin.css_dependencies: kwargs['styles'].add(css) return render_template( '{}/{}'.format(kwargs['theme'], template_name), **kwargs)
def render(template_name, override_theme=None, **kwargs): blocked_engines = get_blocked_engines(engines, request.cookies) autocomplete = request.cookies.get('autocomplete', settings['search']['autocomplete']) if autocomplete not in autocomplete_backends: autocomplete = None nonblocked_categories = set(category for engine_name in engines for category in engines[engine_name].categories if (engine_name, category) not in blocked_engines) if 'categories' not in kwargs: kwargs['categories'] = ['general'] kwargs['categories'].extend( x for x in sorted(categories.keys()) if x != 'general' and x in nonblocked_categories) if 'all_categories' not in kwargs: kwargs['all_categories'] = ['general'] kwargs['all_categories'].extend(x for x in sorted(categories.keys()) if x != 'general') if 'selected_categories' not in kwargs: kwargs['selected_categories'] = [] for arg in request.args: if arg.startswith('category_'): c = arg.split('_', 1)[1] if c in categories: kwargs['selected_categories'].append(c) if not kwargs['selected_categories']: cookie_categories = request.cookies.get('categories', '').split(',') for ccateg in cookie_categories: if ccateg in categories: kwargs['selected_categories'].append(ccateg) if not kwargs['selected_categories']: kwargs['selected_categories'] = ['general'] if 'autocomplete' not in kwargs: kwargs['autocomplete'] = autocomplete if get_locale() in rtl_locales and 'rtl' not in kwargs: kwargs['rtl'] = True kwargs['searx_version'] = VERSION_STRING kwargs['method'] = request.cookies.get('method', 'POST') kwargs['safesearch'] = request.cookies.get( 'safesearch', str(settings['search']['safe_search'])) # override url_for function in templates kwargs['url_for'] = url_for_theme kwargs['image_proxify'] = image_proxify kwargs['get_result_template'] = get_result_template kwargs['theme'] = get_current_theme_name(override=override_theme) kwargs['template_name'] = template_name kwargs['cookies'] = request.cookies kwargs['instance_name'] = settings['general']['instance_name'] kwargs['scripts'] = set() for plugin in request.user_plugins: for script in plugin.js_dependencies: kwargs['scripts'].add(script) kwargs['styles'] = set() for plugin in request.user_plugins: for css in plugin.css_dependencies: kwargs['styles'].add(css) return render_template('{}/{}'.format(kwargs['theme'], template_name), **kwargs)
def render(template_name, override_theme=None, **kwargs): blocked_engines = get_blocked_engines(engines, request.cookies) autocomplete = request.cookies.get("autocomplete", settings["search"]["autocomplete"]) if autocomplete not in autocomplete_backends: autocomplete = None nonblocked_categories = set( category for engine_name in engines for category in engines[engine_name].categories if (engine_name, category) not in blocked_engines ) if "categories" not in kwargs: kwargs["categories"] = ["general"] kwargs["categories"].extend( x for x in sorted(categories.keys()) if x != "general" and x in nonblocked_categories ) if "all_categories" not in kwargs: kwargs["all_categories"] = ["general"] kwargs["all_categories"].extend(x for x in sorted(categories.keys()) if x != "general") if "selected_categories" not in kwargs: kwargs["selected_categories"] = [] for arg in request.args: if arg.startswith("category_"): c = arg.split("_", 1)[1] if c in categories: kwargs["selected_categories"].append(c) if not kwargs["selected_categories"]: cookie_categories = request.cookies.get("categories", "").split(",") for ccateg in cookie_categories: if ccateg in categories: kwargs["selected_categories"].append(ccateg) if not kwargs["selected_categories"]: kwargs["selected_categories"] = ["general"] if "autocomplete" not in kwargs: kwargs["autocomplete"] = autocomplete if get_locale() in rtl_locales and "rtl" not in kwargs: kwargs["rtl"] = True kwargs["searx_version"] = VERSION_STRING kwargs["method"] = request.cookies.get("method", "POST") kwargs["safesearch"] = request.cookies.get("safesearch", str(settings["search"]["safe_search"])) # override url_for function in templates kwargs["url_for"] = url_for_theme kwargs["image_proxify"] = image_proxify kwargs["get_result_template"] = get_result_template kwargs["theme"] = get_current_theme_name(override=override_theme) kwargs["template_name"] = template_name kwargs["cookies"] = request.cookies kwargs["instance_name"] = settings["general"]["instance_name"] kwargs["scripts"] = set() for plugin in request.user_plugins: for script in plugin.js_dependencies: kwargs["scripts"].add(script) kwargs["styles"] = set() for plugin in request.user_plugins: for css in plugin.css_dependencies: kwargs["styles"].add(css) return render_template("{}/{}".format(kwargs["theme"], template_name), **kwargs)
Searx (all) @website https://github.com/asciimoo/searx @provide-api yes (https://asciimoo.github.io/searx/dev/search_api.html) @using-api yes @results JSON @stable yes (using api) @parse url, title, content """ from json import loads from searx.engines import categories as searx_categories categories = searx_categories.keys() # search-url instance_urls = [] instance_index = 0 # do search-request def request(query, params): global instance_index params['url'] = instance_urls[instance_index % len(instance_urls)] params['method'] = 'POST' instance_index += 1 params['data'] = {
from json import loads from searx.engines import categories as searx_categories # about about = { "website": 'https://github.com/searxng/searxng', "wikidata_id": 'Q17639196', "official_api_documentation": 'https://searxng.github.io/searxng/dev/search_api.html', "use_official_api": True, "require_api_key": False, "results": 'JSON', } categories = searx_categories.keys() # search-url instance_urls = [] instance_index = 0 # do search-request def request(query, params): global instance_index params['url'] = instance_urls[instance_index % len(instance_urls)] params['method'] = 'POST' instance_index += 1 params['data'] = {
def render(template_name, override_theme=None, **kwargs): disabled_engines = request.preferences.engines.get_disabled() enabled_categories = set(category for engine_name in engines for category in engines[engine_name].categories if (engine_name, category) not in disabled_engines) if 'categories' not in kwargs: kwargs['categories'] = ['general'] kwargs['categories'].extend(x for x in sorted(categories.keys()) if x != 'general' and x in enabled_categories) if 'all_categories' not in kwargs: kwargs['all_categories'] = ['general'] kwargs['all_categories'].extend(x for x in sorted(categories.keys()) if x != 'general') if 'selected_categories' not in kwargs: kwargs['selected_categories'] = [] for arg in request.args: if arg.startswith('category_'): c = arg.split('_', 1)[1] if c in categories: kwargs['selected_categories'].append(c) if not kwargs['selected_categories']: cookie_categories = request.preferences.get_value('categories') for ccateg in cookie_categories: kwargs['selected_categories'].append(ccateg) if not kwargs['selected_categories']: kwargs['selected_categories'] = ['general'] if 'autocomplete' not in kwargs: kwargs['autocomplete'] = request.preferences.get_value('autocomplete') if get_locale() in rtl_locales and 'rtl' not in kwargs: kwargs['rtl'] = True kwargs['searx_version'] = VERSION_STRING kwargs['method'] = request.preferences.get_value('method') kwargs['safesearch'] = str(request.preferences.get_value('safesearch')) kwargs['language_codes'] = languages if 'current_language' not in kwargs: kwargs['current_language'] = match_language(request.preferences.get_value('language'), LANGUAGE_CODES, fallback=settings['search']['language']) # override url_for function in templates kwargs['url_for'] = url_for_theme kwargs['image_proxify'] = image_proxify kwargs['proxify'] = proxify if settings.get('result_proxy', {}).get('url') else None kwargs['get_result_template'] = get_result_template kwargs['theme'] = get_current_theme_name(override=override_theme) kwargs['template_name'] = template_name kwargs['cookies'] = request.cookies kwargs['errors'] = request.errors kwargs['instance_name'] = settings['general']['instance_name'] kwargs['results_on_new_tab'] = request.preferences.get_value('results_on_new_tab') kwargs['unicode'] = unicode kwargs['preferences'] = request.preferences kwargs['scripts'] = set() for plugin in request.user_plugins: for script in plugin.js_dependencies: kwargs['scripts'].add(script) kwargs['styles'] = set() for plugin in request.user_plugins: for css in plugin.css_dependencies: kwargs['styles'].add(css) return render_template( '{}/{}'.format(kwargs['theme'], template_name), **kwargs)