diff options
author | Cqoicebordel <Cqoicebordel@users.noreply.github.com> | 2015-06-02 20:36:58 +0200 |
---|---|---|
committer | Cqoicebordel <Cqoicebordel@users.noreply.github.com> | 2015-06-02 20:36:58 +0200 |
commit | f05087b93ac1ebef3bdacd353524bac0d8041832 (patch) | |
tree | 41d3d6901cc969f216c485811b7f19baf62212ff /searx/engines/qwant.py | |
parent | 884eeb8541e0a4cf3d65c2a17e1c2f788cab7fb1 (diff) | |
download | searxng-f05087b93ac1ebef3bdacd353524bac0d8041832.tar.gz searxng-f05087b93ac1ebef3bdacd353524bac0d8041832.zip |
Refactor
Use only one engine for the four search from Qwant
Diffstat (limited to 'searx/engines/qwant.py')
-rw-r--r-- | searx/engines/qwant.py | 38 |
1 files changed, 30 insertions, 8 deletions
diff --git a/searx/engines/qwant.py b/searx/engines/qwant.py index 91c12a19e..38bafb043 100644 --- a/searx/engines/qwant.py +++ b/searx/engines/qwant.py @@ -1,5 +1,5 @@ """ - Qwant (Web) + Qwant (Web, Images, News, Social) @website https://qwant.com/ @provide-api not officially (https://api.qwant.com/api/search/) @@ -12,21 +12,25 @@ from urllib import urlencode from json import loads +from datetime import datetime # engine dependent config -categories = ['general'] +categories = None paging = True language_support = True +search_url_keyword = None + # search-url -url = 'https://api.qwant.com/api/search/web?count=10&offset={offset}&f=&{query}' +url = 'https://api.qwant.com/api/search/{keyword}?count=10&offset={offset}&f=&{query}' # do search-request def request(query, params): offset = (params['pageno'] - 1) * 10 - params['url'] = url.format(query=urlencode({'q': query}), + params['url'] = url.format(keyword=search_url_keyword, + query=urlencode({'q': query}), offset=offset) # add language tag if specified @@ -57,10 +61,28 @@ def response(resp): res_url = result['url'] content = result['desc'] - # append result - results.append({'title': title, - 'content': content, - 'url': res_url}) + if search_url_keyword == 'web': + results.append({'title': title, + 'content': content, + 'url': res_url}) + + elif search_url_keyword == 'images': + thumbnail_src = result['thumbnail'] + img_src = result['media'] + results.append({'template': 'images.html', + 'url': res_url, + 'title': title, + 'content': '', + 'thumbnail_src': thumbnail_src, + 'img_src': img_src}) + + elif search_url_keyword == 'news' or search_url_keyword == 'social': + published_date = datetime.fromtimestamp(result['date'], None) + + results.append({'url': res_url, + 'title': title, + 'publishedDate': published_date, + 'content': content}) # return results return results |