diff options
author | Noémi Ványi <kvch@users.noreply.github.com> | 2021-02-04 22:35:08 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-04 22:35:08 +0100 |
commit | ffaf785f8272a8168e92dfe1c3a2179b6991bb18 (patch) | |
tree | 05de0bfee720dbf623827b00125a3aae3e1c393f | |
parent | 006f206dc9ff30893cfb6e431c2ee3a7f7768973 (diff) | |
parent | c4c1636b18cef866aad6a45e15e069eb0c8815d5 (diff) | |
download | searxng-ffaf785f8272a8168e92dfe1c3a2179b6991bb18.tar.gz searxng-ffaf785f8272a8168e92dfe1c3a2179b6991bb18.zip |
Merge pull request #2533 from mrwormo/ccengine
[Engine] Add Creative Commons search engine
-rw-r--r-- | searx/engines/ccengine.py | 53 | ||||
-rw-r--r-- | searx/settings.yml | 5 |
2 files changed, 58 insertions, 0 deletions
diff --git a/searx/engines/ccengine.py b/searx/engines/ccengine.py new file mode 100644 index 000000000..6f3a5adb7 --- /dev/null +++ b/searx/engines/ccengine.py @@ -0,0 +1,53 @@ +# SPDX-License-Identifier: AGPL-3.0-or-later +""" + + Creative Commons search engine (Images) + +""" + +from json import loads +from urllib.parse import urlencode + + +about = { + "website": 'https://search.creativecommons.org/', + "wikidata_id": None, + "official_api_documentation": 'https://api.creativecommons.engineering/v1/', + "use_official_api": True, + "require_api_key": False, + "results": 'JSON', +} + +categories = ['images'] + +paging = True +nb_per_page = 20 + +base_url = 'https://api.creativecommons.engineering/v1/images?' +search_string = '&page={page}&page_size={nb_per_page}&format=json&{query}' + + +def request(query, params): + + search_path = search_string.format( + query=urlencode({'q': query}), + nb_per_page=nb_per_page, + page=params['pageno']) + + params['url'] = base_url + search_path + + return params + + +def response(resp): + results = [] + + json_data = loads(resp.text) + + for result in json_data['results']: + results.append({'url': result['foreign_landing_url'], + 'title': result['title'], + 'img_src': result['url'], + 'template': 'images.html'}) + + return results diff --git a/searx/settings.yml b/searx/settings.yml index 05fb92c6e..4aac91702 100644 --- a/searx/settings.yml +++ b/searx/settings.yml @@ -256,6 +256,11 @@ engines: require_api_key: false results: HTML + - name : ccengine + engine : ccengine + categories : images + shortcut : cce + - name : crossref engine : json_engine paging : True |