blob: 6f3a5adb75665e8c619f67ea77b9661a40facb85 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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
|