2015-05-02 13:45:17 +00:00
|
|
|
"""
|
|
|
|
Gigablast (Web)
|
|
|
|
|
2015-12-22 19:25:57 +00:00
|
|
|
@website https://gigablast.com
|
|
|
|
@provide-api yes (https://gigablast.com/api.html)
|
2015-05-02 13:45:17 +00:00
|
|
|
|
|
|
|
@using-api yes
|
|
|
|
@results XML
|
|
|
|
@stable yes
|
|
|
|
@parse url, title, content
|
|
|
|
"""
|
2020-05-28 17:24:03 +00:00
|
|
|
# pylint: disable=missing-function-docstring, invalid-name
|
2015-02-08 13:12:14 +00:00
|
|
|
|
2015-10-16 10:05:50 +00:00
|
|
|
from time import time
|
2020-05-28 17:24:03 +00:00
|
|
|
from json import loads
|
2016-11-30 17:43:03 +00:00
|
|
|
from searx.url_utils import urlencode
|
2015-02-08 13:12:14 +00:00
|
|
|
|
|
|
|
# engine dependent config
|
|
|
|
categories = ['general']
|
|
|
|
paging = True
|
2015-12-23 17:43:35 +00:00
|
|
|
number_of_results = 10
|
|
|
|
language_support = True
|
|
|
|
safesearch = True
|
2015-02-08 13:12:14 +00:00
|
|
|
|
2015-12-23 17:43:35 +00:00
|
|
|
# search-url
|
2019-12-21 19:51:30 +00:00
|
|
|
|
2020-05-28 17:24:03 +00:00
|
|
|
base_url = 'https://gigablast.com/'
|
2015-02-08 13:12:14 +00:00
|
|
|
|
|
|
|
# do search-request
|
2020-05-28 17:24:03 +00:00
|
|
|
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(
|
|
|
|
c = 'main'
|
|
|
|
, n = number_of_results
|
|
|
|
, format = 'json'
|
|
|
|
, q = query
|
|
|
|
# The gigablast HTTP client sends a random number and a nsga argument
|
|
|
|
# (the values don't seem to matter)
|
|
|
|
, rand = int(time() * 1000)
|
|
|
|
, nsga = int(time() * 1000)
|
|
|
|
)
|
|
|
|
|
|
|
|
page_no = (params['pageno'] - 1)
|
|
|
|
if page_no:
|
|
|
|
# API quirk; adds +2 to the number_of_results
|
|
|
|
offset = (params['pageno'] - 1) * number_of_results
|
|
|
|
query_args['s'] = offset
|
|
|
|
|
|
|
|
if params['language'] and params['language'] != 'all':
|
|
|
|
query_args['qlangcountry'] = params['language']
|
|
|
|
query_args['qlang'] = params['language'].split('-')[0]
|
2015-12-23 17:43:35 +00:00
|
|
|
|
|
|
|
if params['safesearch'] >= 1:
|
2020-05-28 17:24:03 +00:00
|
|
|
query_args['ff'] = 1
|
2015-12-23 17:43:35 +00:00
|
|
|
|
2020-05-28 17:24:03 +00:00
|
|
|
search_url = 'search?' + urlencode(query_args)
|
|
|
|
params['url'] = base_url + search_url
|
2015-02-08 13:12:14 +00:00
|
|
|
|
|
|
|
return params
|
|
|
|
|
|
|
|
# get response from search-request
|
|
|
|
def response(resp):
|
|
|
|
results = []
|
|
|
|
|
2020-05-28 17:24:03 +00:00
|
|
|
response_json = loads(resp.text)
|
2016-01-31 12:24:09 +00:00
|
|
|
for result in response_json['results']:
|
2020-05-28 17:24:03 +00:00
|
|
|
# see "Example JSON Output (&format=json)"
|
|
|
|
# at http://www.gigablast.com/api.html#/search
|
|
|
|
|
|
|
|
# sort out meaningless result
|
|
|
|
|
|
|
|
title = result.get('title')
|
|
|
|
if len(title) < 2:
|
|
|
|
continue
|
|
|
|
|
|
|
|
url = result.get('url')
|
|
|
|
if len(url) < 9:
|
|
|
|
continue
|
|
|
|
|
|
|
|
content = result.get('sum')
|
|
|
|
if len(content) < 5:
|
|
|
|
continue
|
|
|
|
|
|
|
|
# extend fields
|
|
|
|
|
|
|
|
subtitle = result.get('title')
|
|
|
|
if len(subtitle) > 3:
|
|
|
|
title += " - " + subtitle
|
|
|
|
|
|
|
|
results.append(dict(
|
|
|
|
url = url
|
|
|
|
, title = title
|
|
|
|
, content = content
|
|
|
|
))
|
2015-02-08 13:12:14 +00:00
|
|
|
|
|
|
|
return results
|