46def response(resp):
47
48 results = []
49 json_data = resp.json()
50
51 json_results = json_data.get('results')
52 if not json_results:
53
54
55 if json_data.get('status') == 404:
56 return results
57
58 raise_for_httperror(resp)
59
60 for result in json_results:
61
62 url = result["item"].get("link")
63 if not url:
64 continue
65
66 img_src = result['item'].get('service_medium')
67 if not img_src or img_src == 'https://memory.loc.gov/pp/grp.gif':
68 continue
69
70 title = result['title']
71 if title.startswith('['):
72 title = title.strip('[]')
73
74 content_items = [
75 result['item'].get('created_published_date'),
76 result['item'].get('summary', [None])[0],
77 result['item'].get('notes', [None])[0],
78 result['item'].get('part_of', [None])[0],
79 ]
80
81 author = None
82 if result['item'].get('creators'):
83 author = result['item']['creators'][0]['title']
84
85 results.append(
86 {
87 'template': 'images.html',
88 'url': url,
89 'title': title,
90 'content': ' / '.join([i for i in content_items if i]),
91 'img_src': img_src,
92 'thumbnail_src': result['item'].get('thumb_gallery'),
93 'author': author,
94 }
95 )
96
97 return results