on master help sign in
Adds the Unsplash image engine
commitcd7849ffc82dc319e25ed80cae03dc021e5c7263 authorDenis Wernert <deniswernert@gmail.com> dateTue 2 Oct 2018, 15:08 (8 years ago) parentbc7c8a3
2 files changed+44
searx/engines/unsplash.py+39 searx/settings.yml+5
searx/engines/unsplash.pynew file+39
@@ -0,0 +1,39 @@
1+"""
2+ Unsplash
3+
4+ @website https://unsplash.com
5+ @provide-api yes (https://unsplash.com/developers)
6+
7+ @using-api no
8+ @results JSON (using search portal's infiniscroll API)
9+ @stable no (JSON format could change any time)
10+ @parse url, title, img_src, thumbnail_src
11+"""
12+
13+from searx.url_utils import urlencode
14+from json import loads
15+
16+url = 'https://unsplash.com/'
17+search_url = url + 'napi/search/photos?'
18+categories = ['images']
19+page_size = 20
20+paging = True
21+
22+
23+def request(query, params):
24+ params['url'] = search_url + urlencode({'query': query, 'page': params['pageno'], 'per_page': page_size})
25+ return params
26+
27+
28+def response(resp):
29+ results = []
30+ json_data = loads(resp.text)
31+
32+ for result in json_data['results']:
33+ results.append({'template': 'images.html',
34+ 'url': result['links']['html'],
35+ 'thumbnail_src': result['urls']['thumb'],
36+ 'img_src': result['urls']['full'],
37+ 'title': result['description'],
38+ 'content': ''})
39+ return results
searx/settings.yml+5
@@ -642,6 +642,11 @@ engines:
642642# content_xpath : //*[@class="meaning"]
643643# shortcut : ud
644644
645+ - name : unsplash
646+ engine : unsplash
647+ disabled: True
648+ shortcut : us
649+
645650 - name : yahoo
646651 engine : yahoo
647652 shortcut : yh