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
b94653ce
Commit
b94653ce
authored
3 years ago
by
vuillaut
Browse files
Options
Downloads
Patches
Plain Diff
building upon pyzenodo3 to search the OSSR and get records
parent
5f18cfdd
No related branches found
No related tags found
1 merge request
!15
api
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
eossr/api/__init__.py
+83
-0
83 additions, 0 deletions
eossr/api/__init__.py
eossr/api/tests/test_api.py
+0
-0
0 additions, 0 deletions
eossr/api/tests/test_api.py
with
83 additions
and
0 deletions
eossr/api/__init__.py
+
83
−
0
View file @
b94653ce
from
pyzenodo3
import
Record
,
Zenodo
import
requests
__all__
=
[
'
Ossr
'
,
'
pprint_record
'
,
'
get_all_ossr_records
'
]
escape_community
=
'
escape2020
'
class
Ossr
(
Zenodo
):
def
__init__
(
self
):
super
().
__init__
()
def
search
(
self
,
search
:
str
,
**
kwargs
)
->
list
[
Record
]:
"""
Search the ESCAPE OSSR
:param search: string
:param kwargs: Zenodo query arguments.
For an exhaustive list, see the query arguments at https://developers.zenodo.org/#list36
Common arguments are:
- size: int
Number of results to return
- all_versions: int
Show (1) or hide (0) all versions of records
- type: string
Records of the specified type (Publication, Poster, Presentation, Software, ...)
- keywords: string
Records with the specified keywords
:return:
list of `pyzenodo3.Record`
"""
search
=
search
.
replace
(
"
/
"
,
"
"
)
# zenodo can't handle '/' in search query
# if another community is specified, a logical OR is apply be zenodo API,
# thus potentially finding entries that are not part of escap2020
# ruling out that possibility at the moment
kwargs
[
'
communities
'
]
=
escape_community
params
=
{
'
q
'
:
search
,
**
kwargs
}
recs
=
self
.
_get_records
(
params
)
if
not
recs
:
raise
LookupError
(
f
"
No records found for search
{
search
}
"
)
return
recs
def
pprint_record
(
record
:
Record
):
"""
Pretty print of a record
:param record: `pyzenodo3.Record`
"""
entry_id
=
record
.
data
[
'
id
'
]
metadata
=
record
.
data
[
'
metadata
'
]
print
(
f
"
=== Record #
{
entry_id
}
:
{
metadata
[
'
title
'
]
}
===
"
)
print
(
metadata
[
'
description
'
])
print
(
'
\n
'
)
def
get_all_ossr_records
():
"""
Retrieve all OSSR entries.
Potentially long when the number of entries in the OSSR increases.
:return: list[pyzenodo3.Record]
"""
ossr
=
Ossr
()
r
=
requests
.
get
(
ossr
.
base_url
+
'
/records
'
,
params
=
{
'
communities
'
:
escape_community
})
number_of_ossr_entries
=
r
.
json
()[
'
aggregations
'
][
'
access_right
'
][
'
buckets
'
][
0
][
'
doc_count
'
]
return
ossr
.
search
(
''
,
size
=
number_of_ossr_entries
)
This diff is collapsed.
Click to expand it.
eossr/api/tests/test_api.py
0 → 100644
+
0
−
0
View file @
b94653ce
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