artic.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. # SPDX-License-Identifier: AGPL-3.0-or-later
  2. """The Art Institute of Chicago
  3. Explore thousands of artworks from The Art Institute of Chicago.
  4. * https://artic.edu
  5. """
  6. from json import loads
  7. from urllib.parse import urlencode
  8. about = {
  9. "website": 'https://www.artic.edu',
  10. "wikidata_id": 'Q239303',
  11. "official_api_documentation": 'http://api.artic.edu/docs/',
  12. "use_official_api": True,
  13. "require_api_key": False,
  14. "results": 'JSON',
  15. }
  16. categories = ['images']
  17. paging = True
  18. nb_per_page = 20
  19. search_api = 'https://api.artic.edu/api/v1/artworks/search?'
  20. image_api = 'https://www.artic.edu/iiif/2/'
  21. def request(query, params):
  22. args = urlencode(
  23. {
  24. 'q': query,
  25. 'page': params['pageno'],
  26. 'fields': 'id,title,artist_display,medium_display,image_id,date_display,dimensions,artist_titles',
  27. 'limit': nb_per_page,
  28. }
  29. )
  30. params['url'] = search_api + args
  31. logger.debug("query_url --> %s", params['url'])
  32. return params
  33. def response(resp):
  34. results = []
  35. json_data = loads(resp.text)
  36. for result in json_data['data']:
  37. if not result['image_id']:
  38. continue
  39. results.append(
  40. {
  41. 'url': 'https://artic.edu/artworks/%(id)s' % result,
  42. 'title': result['title'] + " (%(date_display)s) // %(artist_display)s" % result,
  43. 'content': "%(medium_display)s // %(dimensions)s" % result,
  44. 'author': ', '.join(result['artist_titles']),
  45. 'img_src': image_api + '/%(image_id)s/full/843,/0/default.jpg' % result,
  46. 'template': 'images.html',
  47. }
  48. )
  49. return results