.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
6
from
datetime
import
datetime
7
from
json
import
loads
8
from
urllib.parse
import
urlencode
9
10
from
searx.exceptions
import
SearxEngineAPIException
11
12
about = {
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
21
categories = [
'science'
,
'scientific publications'
]
22
paging =
True
23
nb_per_page = 10
24
api_key =
'unset'
25
26
base_url =
'https://api.springernature.com/metadata/json?'
27
28
29
def
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
38
def
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
searx.exceptions.SearxEngineAPIException
Definition
exceptions.py:54
searx.engines.springer.request
request(query, params)
Definition
springer.py:29
searx.engines.springer.response
response(resp)
Definition
springer.py:38
searx.exceptions
Definition
exceptions.py:1
searxng
searx
engines
springer.py
Generated on Sat Nov 16 2024 00:10:57 for .oO SearXNG Developer Documentation Oo. by
1.12.0