mirror of
				https://github.com/searxng/searxng.git
				synced 2025-10-30 18:22:31 -04:00 
			
		
		
		
	In 25.1.0 [2] an old bug has been fixed: "Docstring formatting does not apply to module docstrings" [3]. [1] https://github.com/psf/black/blob/main/CHANGES.md#2590 [2] https://github.com/psf/black/blob/main/CHANGES.md#2510 [3] https://github.com/psf/black/issues/4094 Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
		
			
				
	
	
		
			55 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			55 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
| # SPDX-License-Identifier: AGPL-3.0-or-later
 | |
| """
 | |
| 
 | |
| Openverse (formerly known as: Creative Commons search engine) [Images]
 | |
| 
 | |
| """
 | |
| 
 | |
| from json import loads
 | |
| from urllib.parse import urlencode
 | |
| 
 | |
| 
 | |
| about = {
 | |
|     "website": 'https://openverse.org/',
 | |
|     "wikidata_id": None,
 | |
|     "official_api_documentation": 'https://api.openverse.org/v1/',
 | |
|     "use_official_api": True,
 | |
|     "require_api_key": False,
 | |
|     "results": 'JSON',
 | |
| }
 | |
| 
 | |
| categories = ['images']
 | |
| 
 | |
| paging = True
 | |
| nb_per_page = 20
 | |
| 
 | |
| base_url = 'https://api.openverse.org/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
 |