Add yacy improvements: HTTP digest auth, category checking

This commit is contained in:
Noémi Ványi 2020-10-09 15:05:13 +02:00
parent a05c660e30
commit 72c7fd25fe
2 changed files with 12 additions and 4 deletions

View file

@ -16,6 +16,8 @@ from json import loads
from dateutil import parser from dateutil import parser
from urllib.parse import urlencode from urllib.parse import urlencode
from requests.auth import HTTPDigestAuth
from searx.utils import html_to_text from searx.utils import html_to_text
# engine dependent config # engine dependent config
@ -23,6 +25,8 @@ categories = ['general', 'images'] # TODO , 'music', 'videos', 'files'
paging = True paging = True
language_support = True language_support = True
number_of_results = 5 number_of_results = 5
http_digest_auth_user = ""
http_digest_auth_pass = ""
# search-url # search-url
base_url = 'http://localhost:8090' base_url = 'http://localhost:8090'
@ -51,6 +55,9 @@ def request(query, params):
limit=number_of_results, limit=number_of_results,
search_type=search_type) search_type=search_type)
if http_digest_auth_user and http_digest_auth_pass:
params['auth'] = HTTPDigestAuth(http_digest_auth_user, http_digest_auth_pass)
# add language tag if specified # add language tag if specified
if params['language'] != 'all': if params['language'] != 'all':
params['url'] += '&lr=lang_' + params['language'].split('-')[0] params['url'] += '&lr=lang_' + params['language'].split('-')[0]
@ -75,7 +82,7 @@ def response(resp):
for result in search_results[0].get('items', []): for result in search_results[0].get('items', []):
# parse image results # parse image results
if result.get('image') and result.get('width') and result.get('height'): if resp.search_params.get('category') == 'images':
result_url = '' result_url = ''
if 'url' in result: if 'url' in result:
@ -104,5 +111,4 @@ def response(resp):
# TODO parse video, audio and file results # TODO parse video, audio and file results
# return results
return results return results

View file

@ -97,7 +97,8 @@ def send_http_request(engine, request_params):
request_args = dict( request_args = dict(
headers=request_params['headers'], headers=request_params['headers'],
cookies=request_params['cookies'], cookies=request_params['cookies'],
verify=request_params['verify'] verify=request_params['verify'],
auth=request_params['auth']
) )
# setting engine based proxies # setting engine based proxies
@ -281,7 +282,8 @@ def default_request_params():
'data': {}, 'data': {},
'url': '', 'url': '',
'cookies': {}, 'cookies': {},
'verify': True 'verify': True,
'auth': None
} }