[mod] core.ac.uk: use paper.html template

Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
This commit is contained in:
Markus Heiser 2022-09-24 13:17:01 +02:00
parent 3ff2ad939d
commit c76830d8a8
1 changed files with 27 additions and 17 deletions

View File

@ -4,7 +4,6 @@
""" """
from json import loads
from datetime import datetime from datetime import datetime
from urllib.parse import urlencode from urllib.parse import urlencode
@ -48,36 +47,47 @@ def request(query, params):
def response(resp): def response(resp):
results = [] results = []
json_data = loads(resp.text) json_data = resp.json()
for result in json_data['data']: for result in json_data['data']:
source = result['_source'] source = result['_source']
if not source['urls']: if not source['urls']:
continue continue
time = source['publishedDate'] or source['depositedDate'] time = source['publishedDate'] or source['depositedDate']
if time: if time:
date = datetime.fromtimestamp(time / 1000) publishedDate = datetime.fromtimestamp(time / 1000)
else:
date = None
metadata = [] journals = []
if source['publisher'] and len(source['publisher']) > 3: if source['journals']:
metadata.append(source['publisher']) for j in source['journals']:
if source['topics']: journals.append(j['title'])
metadata.append(source['topics'][0])
if source['doi']: publisher = source['publisher']
metadata.append(source['doi']) if publisher:
metadata = ' / '.join(metadata) publisher = source['publisher'].strip("'")
results.append( results.append(
{ {
'url': source['urls'][0].replace('http://', 'https://', 1), 'template': 'paper.html',
'title': source['title'], 'title': source['title'],
'url': source['urls'][0].replace('http://', 'https://', 1),
'content': source['description'], 'content': source['description'],
'publishedDate': date, # 'comments': '',
'metadata': metadata, 'tags': source['topics'],
'publishedDate': publishedDate,
'type': (source['types'] or [None])[0],
'authors': source['authors'],
'editor': ', '.join(source['contributors'] or []),
'publisher': publisher,
'journal': ', '.join(journals),
# 'volume': '',
# 'pages' : '',
# 'number': '',
'doi': source['doi'],
'issn': source['issn'],
'isbn': source.get('isbn'), # exists in the rawRecordXml
'pdf_url': source.get('repositoryDocument', {}).get('pdfOrigin'),
} }
) )