mirror of
https://github.com/searxng/searxng
synced 2024-01-01 18:24:07 +00:00
[fix] gigablast engine
fetch extra params after 3000 seconds
This commit is contained in:
parent
e4a2d354aa
commit
1a6207574e
@ -6,6 +6,7 @@
|
|||||||
# pylint: disable=invalid-name
|
# pylint: disable=invalid-name
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
from time import time
|
||||||
from json import loads
|
from json import loads
|
||||||
from urllib.parse import urlencode
|
from urllib.parse import urlencode
|
||||||
from searx.network import get
|
from searx.network import get
|
||||||
@ -28,13 +29,18 @@ safesearch = True
|
|||||||
|
|
||||||
# search-url
|
# search-url
|
||||||
base_url = 'https://gigablast.com'
|
base_url = 'https://gigablast.com'
|
||||||
|
search_path = '/search?'
|
||||||
|
|
||||||
# ugly hack: gigablast requires a random extra parameter which can be extracted
|
# ugly hack: gigablast requires a random extra parameter which can be extracted
|
||||||
# from the source code of the gigablast HTTP client
|
# from the source code of the gigablast HTTP client
|
||||||
extra_param = ''
|
extra_param = ''
|
||||||
extra_param_path='/search?c=main&qlangcountry=en-us&q=south&s=10'
|
# timestamp of the last fetch of extra_param
|
||||||
|
extra_param_ts = 0
|
||||||
|
# after how many seconds extra_param expire
|
||||||
|
extra_param_expiration_delay = 3000
|
||||||
|
|
||||||
def parse_extra_param(text):
|
|
||||||
|
def fetch_extra_param(query_args, headers):
|
||||||
|
|
||||||
# example:
|
# example:
|
||||||
#
|
#
|
||||||
@ -43,7 +49,12 @@ def parse_extra_param(text):
|
|||||||
#
|
#
|
||||||
# extra_param --> "rand=1590740241635&nsab=730863287"
|
# extra_param --> "rand=1590740241635&nsab=730863287"
|
||||||
|
|
||||||
global extra_param # pylint: disable=global-statement
|
global extra_param, extra_param_ts # pylint: disable=global-statement
|
||||||
|
|
||||||
|
extra_param_ts = time()
|
||||||
|
extra_param_path = search_path + urlencode(query_args)
|
||||||
|
text = get(base_url + extra_param_path, headers=headers).text
|
||||||
|
|
||||||
re_var= None
|
re_var= None
|
||||||
for line in text.splitlines():
|
for line in text.splitlines():
|
||||||
if re_var is None and extra_param_path in line:
|
if re_var is None and extra_param_path in line:
|
||||||
@ -54,21 +65,12 @@ def parse_extra_param(text):
|
|||||||
if re_var is not None and re_var.search(line):
|
if re_var is not None and re_var.search(line):
|
||||||
extra_param += re_var.search(line).group(1)
|
extra_param += re_var.search(line).group(1)
|
||||||
break
|
break
|
||||||
# logger.debug('gigablast extra_param="%s"', extra_param)
|
|
||||||
|
|
||||||
def init(engine_settings=None): # pylint: disable=unused-argument
|
|
||||||
parse_extra_param(get(base_url + extra_param_path).text)
|
|
||||||
|
|
||||||
|
|
||||||
# do search-request
|
# do search-request
|
||||||
def request(query, params): # pylint: disable=unused-argument
|
def request(query, params): # pylint: disable=unused-argument
|
||||||
|
|
||||||
# see API http://www.gigablast.com/api.html#/search
|
|
||||||
# Take into account, that the API has some quirks ..
|
|
||||||
|
|
||||||
query_args = dict(
|
query_args = dict(
|
||||||
c = 'main'
|
c = 'main'
|
||||||
, format = 'json'
|
|
||||||
, q = query
|
, q = query
|
||||||
, dr = 1
|
, dr = 1
|
||||||
, showgoodimages = 0
|
, showgoodimages = 0
|
||||||
@ -81,8 +83,13 @@ def request(query, params): # pylint: disable=unused-argument
|
|||||||
if params['safesearch'] >= 1:
|
if params['safesearch'] >= 1:
|
||||||
query_args['ff'] = 1
|
query_args['ff'] = 1
|
||||||
|
|
||||||
search_url = '/search?' + urlencode(query_args)
|
# see API http://www.gigablast.com/api.html#/search
|
||||||
params['url'] = base_url + search_url + extra_param
|
# Take into account, that the API has some quirks ..
|
||||||
|
if time() > (extra_param_ts + extra_param_expiration_delay):
|
||||||
|
fetch_extra_param(query_args, params['headers'])
|
||||||
|
|
||||||
|
query_args['format'] = 'json'
|
||||||
|
params['url'] = base_url + search_path + urlencode(query_args) + extra_param
|
||||||
|
|
||||||
return params
|
return params
|
||||||
|
|
||||||
|
@ -558,7 +558,7 @@ engines:
|
|||||||
- name: gigablast
|
- name: gigablast
|
||||||
engine: gigablast
|
engine: gigablast
|
||||||
shortcut: gb
|
shortcut: gb
|
||||||
timeout: 3.0
|
timeout: 4.0
|
||||||
disabled: true
|
disabled: true
|
||||||
additional_tests:
|
additional_tests:
|
||||||
rosebud: *test_rosebud
|
rosebud: *test_rosebud
|
||||||
|
Loading…
Reference in New Issue
Block a user