Parcourir la source

Merge pull request #1016 from misnyo/blekko

[mod]blekko images removed
Adam Tauber il y a 7 ans
Parent
révision
e74aaa781e
3 fichiers modifiés avec 0 ajouts et 147 suppressions
  1. 0
    70
      searx/engines/blekko_images.py
  2. 0
    6
      searx/settings.yml
  3. 0
    71
      tests/unit/engines/test_blekko_images.py

+ 0
- 70
searx/engines/blekko_images.py Voir le fichier

@@ -1,70 +0,0 @@
1
-"""
2
- Blekko (Images)
3
-
4
- @website     https://blekko.com
5
- @provide-api yes (inofficial)
6
-
7
- @using-api   yes
8
- @results     JSON
9
- @stable      yes
10
- @parse       url, title, img_src
11
-"""
12
-
13
-from json import loads
14
-from searx.url_utils import urlencode
15
-
16
-# engine dependent config
17
-categories = ['images']
18
-paging = True
19
-safesearch = True
20
-
21
-# search-url
22
-base_url = 'https://blekko.com'
23
-search_url = '/api/images?{query}&c={c}'
24
-
25
-# safesearch definitions
26
-safesearch_types = {2: '1',
27
-                    1: '',
28
-                    0: '0'}
29
-
30
-
31
-# do search-request
32
-def request(query, params):
33
-    c = (params['pageno'] - 1) * 48
34
-
35
-    params['url'] = base_url +\
36
-        search_url.format(query=urlencode({'q': query}),
37
-                          c=c)
38
-
39
-    if params['pageno'] != 1:
40
-        params['url'] += '&page={pageno}'.format(pageno=(params['pageno'] - 1))
41
-
42
-    # let Blekko know we wan't have profiling
43
-    params['cookies']['tag_lesslogging'] = '1'
44
-
45
-    # parse safesearch argument
46
-    params['cookies']['safesearch'] = safesearch_types.get(params['safesearch'], '')
47
-
48
-    return params
49
-
50
-
51
-# get response from search-request
52
-def response(resp):
53
-    results = []
54
-
55
-    search_results = loads(resp.text)
56
-
57
-    # return empty array if there are no results
58
-    if not search_results:
59
-        return []
60
-
61
-    for result in search_results:
62
-        # append result
63
-        results.append({'url': result['page_url'],
64
-                        'title': result['title'],
65
-                        'content': '',
66
-                        'img_src': result['url'],
67
-                        'template': 'images.html'})
68
-
69
-    # return results
70
-    return results

+ 0
- 6
searx/settings.yml Voir le fichier

@@ -652,12 +652,6 @@ engines:
652 652
     shortcut : 1337x
653 653
     disabled : True
654 654
 
655
-#The blekko technology and team have joined IBM Watson! -> https://blekko.com/
656
-#  - name : blekko images
657
-#    engine : blekko_images
658
-#    locale : en-US
659
-#    shortcut : bli
660
-
661 655
 #  - name : yacy
662 656
 #    engine : yacy
663 657
 #    shortcut : ya

+ 0
- 71
tests/unit/engines/test_blekko_images.py Voir le fichier

@@ -1,71 +0,0 @@
1
-from collections import defaultdict
2
-import mock
3
-from searx.engines import blekko_images
4
-from searx.testing import SearxTestCase
5
-
6
-
7
-class TestBlekkoImagesEngine(SearxTestCase):
8
-
9
-    def test_request(self):
10
-        query = 'test_query'
11
-        dicto = defaultdict(dict)
12
-        dicto['pageno'] = 0
13
-        dicto['safesearch'] = 1
14
-        params = blekko_images.request(query, dicto)
15
-        self.assertIn('url', params)
16
-        self.assertIn(query, params['url'])
17
-        self.assertIn('blekko.com', params['url'])
18
-        self.assertIn('page', params['url'])
19
-
20
-        dicto['pageno'] = 1
21
-        params = blekko_images.request(query, dicto)
22
-        self.assertNotIn('page', params['url'])
23
-
24
-    def test_response(self):
25
-        self.assertRaises(AttributeError, blekko_images.response, None)
26
-        self.assertRaises(AttributeError, blekko_images.response, [])
27
-        self.assertRaises(AttributeError, blekko_images.response, '')
28
-        self.assertRaises(AttributeError, blekko_images.response, '[]')
29
-
30
-        response = mock.Mock(text='[]')
31
-        self.assertEqual(blekko_images.response(response), [])
32
-
33
-        json = """
34
-        [
35
-            {
36
-                "c": 1,
37
-                "page_url": "http://result_url.html",
38
-                "title": "Photo title",
39
-                "tn_url": "http://ts1.mm.bing.net/th?id=HN.608050619474382748&pid=15.1",
40
-                "url": "http://result_image.jpg"
41
-            },
42
-            {
43
-                "c": 2,
44
-                "page_url": "http://companyorange.simpsite.nl/OSM",
45
-                "title": "OSM",
46
-                "tn_url": "http://ts2.mm.bing.net/th?id=HN.608048068264919461&pid=15.1",
47
-                "url": "http://simpsite.nl/userdata2/58985/Home/OSM.bmp"
48
-            },
49
-            {
50
-                "c": 3,
51
-                "page_url": "http://invincible.webklik.nl/page/osm",
52
-                "title": "OSM",
53
-                "tn_url": "http://ts1.mm.bing.net/th?id=HN.608024514657649476&pid=15.1",
54
-                "url": "http://www.webklik.nl/user_files/2009_09/65324/osm.gif"
55
-            },
56
-            {
57
-                "c": 4,
58
-                "page_url": "http://www.offshorenorway.no/event/companyDetail/id/12492",
59
-                "title": "Go to OSM Offshore AS homepage",
60
-                "tn_url": "http://ts2.mm.bing.net/th?id=HN.608054265899847285&pid=15.1",
61
-                "url": "http://www.offshorenorway.no/firmalogo/OSM-logo.png"
62
-            }
63
-        ]
64
-        """
65
-        response = mock.Mock(text=json)
66
-        results = blekko_images.response(response)
67
-        self.assertEqual(type(results), list)
68
-        self.assertEqual(len(results), 4)
69
-        self.assertEqual(results[0]['title'], 'Photo title')
70
-        self.assertEqual(results[0]['url'], 'http://result_url.html')
71
-        self.assertEqual(results[0]['img_src'], 'http://result_image.jpg')