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
|
|
|
|
"""
|
2015-02-08 13:12:14 +00:00
|
|
|
|
2016-01-31 12:24:09 +00:00
|
|
|
from json import loads
|
2015-10-16 10:05:50 +00:00
|
|
|
from random import randint
|
|
|
|
from time import time
|
2016-01-31 12:24:09 +00:00
|
|
|
from urllib 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
|
2015-12-22 19:25:57 +00:00
|
|
|
base_url = 'https://gigablast.com/'
|
2015-12-23 17:43:35 +00:00
|
|
|
search_string = 'search?{query}'\
|
|
|
|
'&n={number_of_results}'\
|
2016-01-31 12:24:09 +00:00
|
|
|
'&c=main'\
|
2015-12-23 17:43:35 +00:00
|
|
|
'&s={offset}'\
|
2016-01-31 12:24:09 +00:00
|
|
|
'&format=json'\
|
2015-12-23 17:43:35 +00:00
|
|
|
'&qh=0'\
|
|
|
|
'&qlang={lang}'\
|
2016-06-11 22:06:31 +00:00
|
|
|
'&ff={safesearch}'\
|
|
|
|
'&rxikd={rxikd}' # random number - 9 digits
|
2015-02-08 13:12:14 +00:00
|
|
|
|
|
|
|
# specific xpath variables
|
|
|
|
results_xpath = '//response//result'
|
|
|
|
url_xpath = './/url'
|
|
|
|
title_xpath = './/title'
|
|
|
|
content_xpath = './/sum'
|
|
|
|
|
2016-08-07 03:19:21 +00:00
|
|
|
supported_languages = ["en", "fr", "es", "ru", "tr", "ja", "zh-CN", "zh-TW", "ko", "de",
|
|
|
|
"nl", "it", "fi", "sv", "no", "pt", "vi", "ar", "he", "id", "el",
|
|
|
|
"th", "hi", "bn", "pl", "tl", "la", "eo", "ca", "bg", "tx", "sr",
|
|
|
|
"hu", "da", "lt", "cs", "gl", "ka", "gd", "go", "ro", "ga", "lv",
|
|
|
|
"hy", "is", "ag", "gv", "io", "fa", "te", "vv", "mg", "ku", "lb", "et"]
|
|
|
|
|
2015-02-08 13:12:14 +00:00
|
|
|
|
|
|
|
# do search-request
|
|
|
|
def request(query, params):
|
|
|
|
offset = (params['pageno'] - 1) * number_of_results
|
|
|
|
|
2015-12-23 17:43:35 +00:00
|
|
|
if params['language'] == 'all':
|
|
|
|
language = 'xx'
|
|
|
|
else:
|
2016-08-07 03:19:21 +00:00
|
|
|
language = params['language'].replace('-', '_').lower()
|
|
|
|
if language.split('-')[0] != 'zh':
|
|
|
|
language = language.split('-')[0]
|
2015-12-23 17:43:35 +00:00
|
|
|
|
|
|
|
if params['safesearch'] >= 1:
|
|
|
|
safesearch = 1
|
|
|
|
else:
|
|
|
|
safesearch = 0
|
|
|
|
|
|
|
|
search_path = search_string.format(query=urlencode({'q': query}),
|
|
|
|
offset=offset,
|
|
|
|
number_of_results=number_of_results,
|
2016-06-11 22:06:31 +00:00
|
|
|
rxikd=str(time())[:9],
|
2015-12-23 17:43:35 +00:00
|
|
|
lang=language,
|
|
|
|
safesearch=safesearch)
|
2015-02-08 13:12:14 +00:00
|
|
|
|
|
|
|
params['url'] = base_url + search_path
|
|
|
|
|
|
|
|
return params
|
|
|
|
|
|
|
|
|
|
|
|
# get response from search-request
|
|
|
|
def response(resp):
|
|
|
|
results = []
|
|
|
|
|
|
|
|
# parse results
|
2016-01-31 12:24:09 +00:00
|
|
|
response_json = loads(resp.text)
|
2015-02-08 13:12:14 +00:00
|
|
|
|
2016-01-31 12:24:09 +00:00
|
|
|
for result in response_json['results']:
|
2015-02-08 13:12:14 +00:00
|
|
|
# append result
|
2016-01-31 12:24:09 +00:00
|
|
|
results.append({'url': result['url'],
|
2016-12-09 10:44:24 +00:00
|
|
|
'title': result['title'],
|
|
|
|
'content': result['sum']})
|
2015-02-08 13:12:14 +00:00
|
|
|
|
|
|
|
# return results
|
|
|
|
return results
|