26def response(resp):
27 results = []
28 for record in resp.json()["message"]["items"]:
29
30 if record["type"] == "component":
31
32 continue
33 result = {
34 "template": "paper.html",
35 "content": record.get("abstract", ""),
36 "doi": record.get("DOI"),
37 "pages": record.get("page"),
38 "publisher": record.get("publisher"),
39 "tags": record.get("subject"),
40 "type": record.get("type"),
41 "url": record.get("URL"),
42 "volume": record.get("volume"),
43 }
44 if record["type"] == "book-chapter":
45 result["title"] = record["container-title"][0]
46 if record["title"][0].lower().strip() != result["title"].lower().strip():
47 result["title"] += f" ({record['title'][0]})"
48 else:
49 result["title"] = record["title"][0] if "title" in record else record.get("container-title", [None])[0]
50 result["journal"] = record.get("container-title", [None])[0] if "title" in record else None
51
52 if "resource" in record and "primary" in record["resource"] and "URL" in record["resource"]["primary"]:
53 result["url"] = record["resource"]["primary"]["URL"]
54 if "published" in record and "date-parts" in record["published"]:
55 result["publishedDate"] = datetime(*(record["published"]["date-parts"][0] + [1, 1][:3]))
56 result["authors"] = [a.get("given", "") + " " + a.get("family", "") for a in record.get("author", [])]
57 result["isbn"] = record.get("isbn") or [i["value"] for i in record.get("isbn-type", [])]
58
59
60
61 results.append(result)
62
63 return results