Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
eossr
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
ESCAPE2020
WP3
eossr
Commits
d8256d57
Commit
d8256d57
authored
3 years ago
by
Vuillaume
Committed by
Enrique Garcia
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
handle lists and lowercase of args in search zenodo / ossr records
parent
0a2863bf
No related branches found
No related tags found
1 merge request
!59
handle lists and lowercase of args in search zenodo / ossr records
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
eossr/api/__init__.py
+17
-2
17 additions, 2 deletions
eossr/api/__init__.py
eossr/api/tests/test_api.py
+1
-1
1 addition, 1 deletion
eossr/api/tests/test_api.py
eossr/api/zenodo/__init__.py
+25
-3
25 additions, 3 deletions
eossr/api/zenodo/__init__.py
with
43 additions
and
6 deletions
eossr/api/__init__.py
+
17
−
2
View file @
d8256d57
...
...
@@ -13,6 +13,7 @@ escape_community = 'escape2020'
def
get_ossr_records
(
search
=
''
,
sandbox
=
False
,
**
kwargs
):
"""
Search the OSSR for records whose names or descriptions include the provided string `search`.
The default record type is
'
software
'
or
'
record
'
.
Function rewritten from pyzenodo3 (https://github.com/space-physics/pyzenodo3)
:param search: string
...
...
@@ -22,12 +23,19 @@ def get_ossr_records(search='', sandbox=False, **kwargs):
Common arguments are:
- size: int
Number of results to return
Default = 100
- all_versions: int
Show (1) or hide (0) all versions of records
- type: string
- type: string or list[string]
Default: [
'
software
'
,
'
dataset
'
]
Records of the specified type (Publication, Poster, Presentation, Software, ...)
- keywords: string
A logical OR is applied in case of a list
- keywords: string or list[string]
Records with the specified keywords
A logical OR is applied in case of a list
- file_type: string or list[string]
Records from the specified keywords
A logical OR is applied in case of a list
:return:
list of `Record`
...
...
@@ -41,7 +49,14 @@ def get_ossr_records(search='', sandbox=False, **kwargs):
# if another community is specified, a logical OR is apply be zenodo API,
# thus potentially finding entries that are not part of escape2020
# ruling out that possibility at the moment
if
'
communities
'
in
kwargs
and
kwargs
[
'
communities
'
]
!=
escape_community
:
raise
NotImplementedError
(
"
Searching in another community will search outside of the OSSR
"
"
Use `eossr.api.zenodo.get_zenodo_records` to do so
"
)
kwargs
[
'
communities
'
]
=
escape_community
# OSSR is limited to software and datasets
kwargs
.
setdefault
(
'
type
'
,
[
'
software
'
,
'
dataset
'
])
return
get_zenodo_records
(
search
,
sandbox
=
sandbox
,
**
kwargs
)
This diff is collapsed.
Click to expand it.
eossr/api/tests/test_api.py
+
1
−
1
View file @
d8256d57
...
...
@@ -3,7 +3,7 @@ from eossr import api
def
test_get_ossr_records
():
ossr_records
=
api
.
get_ossr_records
()
assert
len
(
ossr_records
)
>=
1
5
# number of records
Septem
ber
1
0, 2021
assert
len
(
ossr_records
)
>=
1
2
# number of records
Octo
ber 0
1
, 2021
all_ids
=
[
rec
.
data
[
'
id
'
]
for
rec
in
ossr_records
]
assert
4923992
in
all_ids
# id of the ESCAPE template project
This diff is collapsed.
Click to expand it.
eossr/api/zenodo/__init__.py
+
25
−
3
View file @
d8256d57
...
...
@@ -502,12 +502,21 @@ def get_zenodo_records(search='', sandbox=False, **kwargs):
Common arguments are:
- size: int
Number of results to return
Default = 100
- all_versions: int
Show (1) or hide (0) all versions of records
- type: string
- type: string
or list[string]
Records of the specified type (Publication, Poster, Presentation, Software, ...)
- keywords: string
A logical OR is applied in case of a list
- keywords: string or list[string]
Records with the specified keywords
A logical OR is applied in case of a list
- communities: string or list[string]
Records from the specified keywords
A logical OR is applied in case of a list
- file_type: string or list[string]
Records from the specified keywords
A logical OR is applied in case of a list
:return:
list of `Record`
...
...
@@ -519,8 +528,21 @@ def get_zenodo_records(search='', sandbox=False, **kwargs):
**
kwargs
}
params
.
setdefault
(
'
size
'
,
100
)
def
lowercase
(
param
):
if
isinstance
(
param
,
str
):
param
=
param
.
lower
()
if
isinstance
(
param
,
list
):
param
=
[
char
.
lower
()
for
char
in
param
]
return
param
for
param_name
in
[
'
communities
'
,
'
type
'
,
'
file_type
'
]:
if
param_name
in
kwargs
:
params
[
param_name
]
=
lowercase
(
kwargs
[
param_name
])
api_url
=
zenodo_sandobx_api_url
if
sandbox
else
zenodo_api_url
url
=
api_url
+
"
/records?
"
+
urlencode
(
params
)
url
=
api_url
+
"
/records?
"
+
urlencode
(
params
,
doseq
=
True
)
recs
=
[
Record
(
hit
)
for
hit
in
requests
.
get
(
url
).
json
()[
"
hits
"
][
"
hits
"
]]
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment