.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
springer.py
Go to the documentation of this file.
1# SPDX-License-Identifier: AGPL-3.0-or-later
2"""Springer Nature (science)
3
4"""
5
6from datetime import datetime
7from json import loads
8from urllib.parse import urlencode
9
10from searx.exceptions import SearxEngineAPIException
11
12about = {
13 "website": 'https://www.springernature.com/',
14 "wikidata_id": 'Q21096327',
15 "official_api_documentation": 'https://dev.springernature.com/',
16 "use_official_api": True,
17 "require_api_key": True,
18 "results": 'JSON',
19}
20
21categories = ['science', 'scientific publications']
22paging = True
23nb_per_page = 10
24api_key = 'unset'
25
26base_url = 'https://api.springernature.com/metadata/json?'
27
28
29def request(query, params):
30 if api_key == 'unset':
31 raise SearxEngineAPIException('missing Springer-Nature API key')
32 args = urlencode({'q': query, 's': nb_per_page * (params['pageno'] - 1), 'p': nb_per_page, 'api_key': api_key})
33 params['url'] = base_url + args
34 logger.debug("query_url --> %s", params['url'])
35 return params
36
37
38def response(resp):
39 results = []
40 json_data = loads(resp.text)
41
42 for record in json_data['records']:
43 published = datetime.strptime(record['publicationDate'], '%Y-%m-%d')
44 authors = [" ".join(author['creator'].split(', ')[::-1]) for author in record['creators']]
45 tags = record.get('genre')
46 if isinstance(tags, str):
47 tags = [tags]
48 results.append(
49 {
50 'template': 'paper.html',
51 'url': record['url'][0]['value'].replace('http://', 'https://', 1),
52 'title': record['title'],
53 'content': record['abstract'],
54 'comments': record['publicationName'],
55 'tags': tags,
56 'publishedDate': published,
57 'type': record.get('contentType'),
58 'authors': authors,
59 # 'editor': '',
60 'publisher': record.get('publisher'),
61 'journal': record.get('publicationName'),
62 'volume': record.get('volume') or None,
63 'pages': '-'.join([x for x in [record.get('startingPage'), record.get('endingPage')] if x]),
64 'number': record.get('number') or None,
65 'doi': record.get('doi'),
66 'issn': [x for x in [record.get('issn')] if x],
67 'isbn': [x for x in [record.get('isbn')] if x],
68 # 'pdf_url' : ''
69 }
70 )
71 return results
request(query, params)
Definition springer.py:29