2021-03-17 15:43:09 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
2021-04-26 18:18:20 +00:00
|
|
|
# lint: pylint
|
2021-03-17 15:43:09 +00:00
|
|
|
"""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']:
|
2022-08-26 16:10:12 +00:00
|
|
|
content = record['abstract']
|
2021-03-17 15:43:09 +00:00
|
|
|
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
|
|
|
'title': record['title'],
|
|
|
|
'url': record['url'][0]['value'].replace('http://', 'https://', 1),
|
2022-08-26 16:10:12 +00:00
|
|
|
'type': record.get('contentType'),
|
2021-12-27 08:26:22 +00:00
|
|
|
'content': content,
|
|
|
|
'publishedDate': published,
|
2022-08-26 16:10:12 +00:00
|
|
|
'authors': authors,
|
|
|
|
'doi': record.get('doi'),
|
|
|
|
'journal': record.get('publicationName'),
|
|
|
|
'start_page': record.get('start_page'),
|
|
|
|
'end_page': record.get('end_page'),
|
|
|
|
'tags': tags,
|
|
|
|
'issn': [record.get('issn')],
|
|
|
|
'isbn': [record.get('isbn')],
|
|
|
|
'volume': record.get('volume') or None,
|
|
|
|
'number': record.get('number') or None,
|
2021-12-27 08:26:22 +00:00
|
|
|
}
|
|
|
|
)
|
2021-03-17 15:43:09 +00:00
|
|
|
return results
|