on master help sign in
[enh] Add Springer Nature engine

Springer Nature is a global publisher dedicated to providing service to research community [1] with official API [2]. To test this PR, first get your API key following this page: https://dev.springernature.com/signup In searx/engines/springer.py at line 24, add this API key. I left my own key, commented out in the line aboce. Feel free to use it, if needed. [1] https://www.springernature.com/ [2] https://dev.springernature.com/

commit3a0f896b68b24957421c593dc2bfacdd36b8bcb3 authorPierre Chevalier <pierrechevaliergeol@gmail.com> dateWed 17 Mar 2021, 16:43 (6 years ago) parent839e5b1
3 files changed+84
manage+1 searx/engines/springer.py+74 searx/settings.yml+9
manage+1
@@ -32,6 +32,7 @@ PYLINT_FILES=(
3232 searx/engines/meilisearch.py
3333 searx/engines/solidtorrents.py
3434 searx/engines/solr.py
35+ searx/engines/springer.py
3536 searx/engines/google_scholar.py
3637 searx/engines/yahoo_news.py
3738 searx/engines/apkmirror.py
searx/engines/springer.pynew file+74
@@ -0,0 +1,74 @@
1+# SPDX-License-Identifier: AGPL-3.0-or-later
2+"""Springer Nature (science)
3+
4+"""
5+
6+# pylint: disable=missing-function-docstring
7+
8+from datetime import datetime
9+from json import loads
10+from urllib.parse import urlencode
11+
12+from searx import logger
13+from searx.exceptions import SearxEngineAPIException
14+
15+logger = logger.getChild('Springer Nature engine')
16+
17+about = {
18+ "website": 'https://www.springernature.com/',
19+ "wikidata_id": 'Q21096327',
20+ "official_api_documentation": 'https://dev.springernature.com/',
21+ "use_official_api": True,
22+ "require_api_key": True,
23+ "results": 'JSON',
24+}
25+
26+categories = ['science']
27+paging = True
28+nb_per_page = 10
29+api_key = 'unset'
30+
31+base_url = 'https://api.springernature.com/metadata/json?'
32+
33+def request(query, params):
34+ if api_key == 'unset':
35+ raise SearxEngineAPIException('missing Springer-Nature API key')
36+ args = urlencode({
37+ 'q' : query,
38+ 's' : nb_per_page * (params['pageno'] - 1),
39+ 'p' : nb_per_page,
40+ 'api_key' : api_key
41+ })
42+ params['url'] = base_url + args
43+ logger.debug("query_url --> %s", params['url'])
44+ return params
45+
46+
47+def response(resp):
48+ results = []
49+ json_data = loads(resp.text)
50+
51+ for record in json_data['records']:
52+ content = record['abstract'][0:500]
53+ if len(record['abstract']) > len(content):
54+ content += "..."
55+ published = datetime.strptime(record['publicationDate'], '%Y-%m-%d')
56+
57+ metadata = [record[x] for x in [
58+ 'publicationName',
59+ 'identifier',
60+ 'contentType',
61+ ] if record.get(x) is not None]
62+
63+ metadata = ' / '.join(metadata)
64+ if record.get('startingPage') and record.get('endingPage') is not None:
65+ metadata += " (%(startingPage)s-%(endingPage)s)" % record
66+
67+ results.append({
68+ 'title': record['title'],
69+ 'url': record['url'][0]['value'].replace('http://', 'https://', 1),
70+ 'content' : content,
71+ 'publishedDate' : published,
72+ 'metadata' : metadata
73+ })
74+ return results
searx/settings.yml+9
@@ -989,6 +989,15 @@ engines:
989989# query_fields : '' # query fields
990990# enable_http : True
991991
992+# - name : springer nature
993+# engine : springer
994+# # get your API key from: https://dev.springernature.com/signup
995+# api_key : 'unset' # working API key, for test & debug: "a69685087d07eca9f13db62f65b8f601"
996+# disabled: True
997+# shortcut : springer
998+# categories : science
999+# timeout : 6.0
1000+
9921001 - name : startpage
9931002 engine : startpage
9941003 shortcut : sp