46def response(resp):
47 results = []
48 json_data = resp.json()
49
50 for result in json_data['data']:
51 source = result['_source']
52 url = None
53 if source.get('urls'):
54 url = source['urls'][0].replace('http://', 'https://', 1)
55
56 if url is None and source.get('doi'):
57
58 url = 'https://doi.org/' + source['doi']
59
60 if url is None and source.get('downloadUrl'):
61
62 url = source['downloadUrl']
63
64 if url is None and source.get('identifiers'):
65
66
67
68 arkids = [
69 identifier[5:]
70 for identifier in source.get('identifiers')
71 if isinstance(identifier, str) and identifier.startswith('ark:/')
72 ]
73 if len(arkids) > 0:
74 url = 'https://n2t.net/' + arkids[0]
75
76 if url is None:
77 continue
78
79 publishedDate = None
80 time = source['publishedDate'] or source['depositedDate']
81 if time:
82 publishedDate = datetime.fromtimestamp(time / 1000)
83
84
85 journals = [j['title'] for j in (source.get('journals') or []) if j['title']]
86
87 publisher = source['publisher']
88 if publisher:
89 publisher = source['publisher'].strip("'")
90
91 results.append(
92 {
93 'template': 'paper.html',
94 'title': source['title'],
95 'url': url,
96 'content': source['description'] or '',
97
98 'tags': source['topics'],
99 'publishedDate': publishedDate,
100 'type': (source['types'] or [None])[0],
101 'authors': source['authors'],
102 'editor': ', '.join(source['contributors'] or []),
103 'publisher': publisher,
104 'journal': ', '.join(journals),
105
106
107
108 'doi': source['doi'],
109 'issn': [x for x in [source.get('issn')] if x],
110 'isbn': [x for x in [source.get('isbn')] if x],
111 'pdf_url': source.get('repositoryDocument', {}).get('pdfOrigin'),
112 }
113 )
114
115 return results