41def response(resp):
42 results = []
43
44 for item in resp.json().get("docs", []):
45 cover = None
46 if 'lending_identifier_s' in item:
47 cover = f"https://archive.org/services/img/{item['lending_identifier_s']}"
48
49 published = item.get('publish_date')
50 if published:
51 published_dates = [date for date in map(_parse_date, published) if date]
52 if published_dates:
53 published = min(published_dates)
54
55 if not published:
56 published = parser.parse(str(item.get('first_published_year')))
57
58 result = {
59 'template': 'paper.html',
60 'url': f"{base_url}{item['key']}",
61 'title': item['title'],
62 'content': re.sub(r"\{|\}", "", item['first_sentence'][0]) if item.get('first_sentence') else '',
63 'isbn': item.get('isbn', [])[:5],
64 'authors': item.get('author_name', []),
65 'thumbnail': cover,
66 'publishedDate': published,
67 'tags': item.get('subject', [])[:10] + item.get('place', [])[:10],
68 }
69 results.append(result)
70
71 return results