forked from Ponysearch/Ponysearch
commit
e74aaa781e
3 changed files with 0 additions and 147 deletions
|
@ -1,70 +0,0 @@
|
||||||
"""
|
|
||||||
Blekko (Images)
|
|
||||||
|
|
||||||
@website https://blekko.com
|
|
||||||
@provide-api yes (inofficial)
|
|
||||||
|
|
||||||
@using-api yes
|
|
||||||
@results JSON
|
|
||||||
@stable yes
|
|
||||||
@parse url, title, img_src
|
|
||||||
"""
|
|
||||||
|
|
||||||
from json import loads
|
|
||||||
from searx.url_utils import urlencode
|
|
||||||
|
|
||||||
# engine dependent config
|
|
||||||
categories = ['images']
|
|
||||||
paging = True
|
|
||||||
safesearch = True
|
|
||||||
|
|
||||||
# search-url
|
|
||||||
base_url = 'https://blekko.com'
|
|
||||||
search_url = '/api/images?{query}&c={c}'
|
|
||||||
|
|
||||||
# safesearch definitions
|
|
||||||
safesearch_types = {2: '1',
|
|
||||||
1: '',
|
|
||||||
0: '0'}
|
|
||||||
|
|
||||||
|
|
||||||
# do search-request
|
|
||||||
def request(query, params):
|
|
||||||
c = (params['pageno'] - 1) * 48
|
|
||||||
|
|
||||||
params['url'] = base_url +\
|
|
||||||
search_url.format(query=urlencode({'q': query}),
|
|
||||||
c=c)
|
|
||||||
|
|
||||||
if params['pageno'] != 1:
|
|
||||||
params['url'] += '&page={pageno}'.format(pageno=(params['pageno'] - 1))
|
|
||||||
|
|
||||||
# let Blekko know we wan't have profiling
|
|
||||||
params['cookies']['tag_lesslogging'] = '1'
|
|
||||||
|
|
||||||
# parse safesearch argument
|
|
||||||
params['cookies']['safesearch'] = safesearch_types.get(params['safesearch'], '')
|
|
||||||
|
|
||||||
return params
|
|
||||||
|
|
||||||
|
|
||||||
# get response from search-request
|
|
||||||
def response(resp):
|
|
||||||
results = []
|
|
||||||
|
|
||||||
search_results = loads(resp.text)
|
|
||||||
|
|
||||||
# return empty array if there are no results
|
|
||||||
if not search_results:
|
|
||||||
return []
|
|
||||||
|
|
||||||
for result in search_results:
|
|
||||||
# append result
|
|
||||||
results.append({'url': result['page_url'],
|
|
||||||
'title': result['title'],
|
|
||||||
'content': '',
|
|
||||||
'img_src': result['url'],
|
|
||||||
'template': 'images.html'})
|
|
||||||
|
|
||||||
# return results
|
|
||||||
return results
|
|
|
@ -652,12 +652,6 @@ engines:
|
||||||
shortcut : 1337x
|
shortcut : 1337x
|
||||||
disabled : True
|
disabled : True
|
||||||
|
|
||||||
#The blekko technology and team have joined IBM Watson! -> https://blekko.com/
|
|
||||||
# - name : blekko images
|
|
||||||
# engine : blekko_images
|
|
||||||
# locale : en-US
|
|
||||||
# shortcut : bli
|
|
||||||
|
|
||||||
# - name : yacy
|
# - name : yacy
|
||||||
# engine : yacy
|
# engine : yacy
|
||||||
# shortcut : ya
|
# shortcut : ya
|
||||||
|
|
|
@ -1,71 +0,0 @@
|
||||||
from collections import defaultdict
|
|
||||||
import mock
|
|
||||||
from searx.engines import blekko_images
|
|
||||||
from searx.testing import SearxTestCase
|
|
||||||
|
|
||||||
|
|
||||||
class TestBlekkoImagesEngine(SearxTestCase):
|
|
||||||
|
|
||||||
def test_request(self):
|
|
||||||
query = 'test_query'
|
|
||||||
dicto = defaultdict(dict)
|
|
||||||
dicto['pageno'] = 0
|
|
||||||
dicto['safesearch'] = 1
|
|
||||||
params = blekko_images.request(query, dicto)
|
|
||||||
self.assertIn('url', params)
|
|
||||||
self.assertIn(query, params['url'])
|
|
||||||
self.assertIn('blekko.com', params['url'])
|
|
||||||
self.assertIn('page', params['url'])
|
|
||||||
|
|
||||||
dicto['pageno'] = 1
|
|
||||||
params = blekko_images.request(query, dicto)
|
|
||||||
self.assertNotIn('page', params['url'])
|
|
||||||
|
|
||||||
def test_response(self):
|
|
||||||
self.assertRaises(AttributeError, blekko_images.response, None)
|
|
||||||
self.assertRaises(AttributeError, blekko_images.response, [])
|
|
||||||
self.assertRaises(AttributeError, blekko_images.response, '')
|
|
||||||
self.assertRaises(AttributeError, blekko_images.response, '[]')
|
|
||||||
|
|
||||||
response = mock.Mock(text='[]')
|
|
||||||
self.assertEqual(blekko_images.response(response), [])
|
|
||||||
|
|
||||||
json = """
|
|
||||||
[
|
|
||||||
{
|
|
||||||
"c": 1,
|
|
||||||
"page_url": "http://result_url.html",
|
|
||||||
"title": "Photo title",
|
|
||||||
"tn_url": "http://ts1.mm.bing.net/th?id=HN.608050619474382748&pid=15.1",
|
|
||||||
"url": "http://result_image.jpg"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"c": 2,
|
|
||||||
"page_url": "http://companyorange.simpsite.nl/OSM",
|
|
||||||
"title": "OSM",
|
|
||||||
"tn_url": "http://ts2.mm.bing.net/th?id=HN.608048068264919461&pid=15.1",
|
|
||||||
"url": "http://simpsite.nl/userdata2/58985/Home/OSM.bmp"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"c": 3,
|
|
||||||
"page_url": "http://invincible.webklik.nl/page/osm",
|
|
||||||
"title": "OSM",
|
|
||||||
"tn_url": "http://ts1.mm.bing.net/th?id=HN.608024514657649476&pid=15.1",
|
|
||||||
"url": "http://www.webklik.nl/user_files/2009_09/65324/osm.gif"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"c": 4,
|
|
||||||
"page_url": "http://www.offshorenorway.no/event/companyDetail/id/12492",
|
|
||||||
"title": "Go to OSM Offshore AS homepage",
|
|
||||||
"tn_url": "http://ts2.mm.bing.net/th?id=HN.608054265899847285&pid=15.1",
|
|
||||||
"url": "http://www.offshorenorway.no/firmalogo/OSM-logo.png"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
"""
|
|
||||||
response = mock.Mock(text=json)
|
|
||||||
results = blekko_images.response(response)
|
|
||||||
self.assertEqual(type(results), list)
|
|
||||||
self.assertEqual(len(results), 4)
|
|
||||||
self.assertEqual(results[0]['title'], 'Photo title')
|
|
||||||
self.assertEqual(results[0]['url'], 'http://result_url.html')
|
|
||||||
self.assertEqual(results[0]['img_src'], 'http://result_image.jpg')
|
|
Loading…
Reference in a new issue