2021-03-17 15:43:09 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
"""Springer Nature (science)
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
from datetime import datetime
|
|
|
|
from json import loads
|
|
|
|
from urllib.parse import urlencode
|
|
|
|
|
|
|
|
from searx.exceptions import SearxEngineAPIException
|
|
|
|
|
|
|
|
about = {
|
|
|
|
"website": 'https://www.springernature.com/',
|
|
|
|
"wikidata_id": 'Q21096327',
|
|
|
|
"official_api_documentation": 'https://dev.springernature.com/',
|
|
|
|
"use_official_api": True,
|
|
|
|
"require_api_key": True,
|
|
|
|
"results": 'JSON',
|
|
|
|
}
|
|
|
|
|
2022-08-26 16:10:12 +00:00
|
|
|
categories = ['science', 'scientific publications']
|
2021-03-17 15:43:09 +00:00
|
|
|
paging = True
|
|
|
|
nb_per_page = 10
|
|
|
|
api_key = 'unset'
|
|
|
|
|
|
|
|
base_url = 'https://api.springernature.com/metadata/json?'
|
|
|
|
|
2021-12-27 08:26:22 +00:00
|
|
|
|
2021-03-17 15:43:09 +00:00
|
|
|
def request(query, params):
|
|
|
|
if api_key == 'unset':
|
|
|
|
raise SearxEngineAPIException('missing Springer-Nature API key')
|
2021-12-27 08:26:22 +00:00
|
|
|
args = urlencode({'q': query, 's': nb_per_page * (params['pageno'] - 1), 'p': nb_per_page, 'api_key': api_key})
|
2021-03-17 15:43:09 +00:00
|
|
|
params['url'] = base_url + args
|
|
|
|
logger.debug("query_url --> %s", params['url'])
|
|
|
|
return params
|
|
|
|
|
|
|
|
|
|
|
|
def response(resp):
|
|
|
|
results = []
|
|
|
|
json_data = loads(resp.text)
|
|
|
|
|
|
|
|
for record in json_data['records']:
|
|
|
|
published = datetime.strptime(record['publicationDate'], '%Y-%m-%d')
|
2022-08-26 16:10:12 +00:00
|
|
|
authors = [" ".join(author['creator'].split(', ')[::-1]) for author in record['creators']]
|
|
|
|
tags = record.get('genre')
|
|
|
|
if isinstance(tags, str):
|
|
|
|
tags = [tags]
|
2021-12-27 08:26:22 +00:00
|
|
|
results.append(
|
|
|
|
{
|
2022-08-26 16:10:12 +00:00
|
|
|
'template': 'paper.html',
|
2021-12-27 08:26:22 +00:00
|
|
|
'url': record['url'][0]['value'].replace('http://', 'https://', 1),
|
2022-09-25 12:57:02 +00:00
|
|
|
'title': record['title'],
|
|
|
|
'content': record['abstract'],
|
|
|
|
'comments': record['publicationName'],
|
|
|
|
'tags': tags,
|
2021-12-27 08:26:22 +00:00
|
|
|
'publishedDate': published,
|
2022-09-25 12:57:02 +00:00
|
|
|
'type': record.get('contentType'),
|
2022-08-26 16:10:12 +00:00
|
|
|
'authors': authors,
|
2022-09-25 12:57:02 +00:00
|
|
|
# 'editor': '',
|
|
|
|
'publisher': record.get('publisher'),
|
2022-08-26 16:10:12 +00:00
|
|
|
'journal': record.get('publicationName'),
|
|
|
|
'volume': record.get('volume') or None,
|
2022-09-25 12:57:02 +00:00
|
|
|
'pages': '-'.join([x for x in [record.get('startingPage'), record.get('endingPage')] if x]),
|
2022-08-26 16:10:12 +00:00
|
|
|
'number': record.get('number') or None,
|
2022-09-25 12:57:02 +00:00
|
|
|
'doi': record.get('doi'),
|
|
|
|
'issn': [x for x in [record.get('issn')] if x],
|
|
|
|
'isbn': [x for x in [record.get('isbn')] if x],
|
|
|
|
# 'pdf_url' : ''
|
2021-12-27 08:26:22 +00:00
|
|
|
}
|
|
|
|
)
|
2021-03-17 15:43:09 +00:00
|
|
|
return results
|