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
Admin message
Authenticating with a password
with git over http
works again
. More information
here
.
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
ESCAPE2020
WP3
eossr
Commits
c183df6a
Commit
c183df6a
authored
3 years ago
by
vuillaut
Browse files
Options
Downloads
Patches
Plain Diff
add zenodo Record class and basic zenodo search function
parent
7ce44f8e
No related branches found
No related tags found
1 merge request
!15
api
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
eossr/api/zenodo.py
+71
-3
71 additions, 3 deletions
eossr/api/zenodo.py
with
71 additions
and
3 deletions
eossr/api/zenodo.py
+
71
−
3
View file @
c183df6a
...
...
@@ -6,8 +6,11 @@ import pprint
import
requests
from
os.path
import
abspath
from
pathlib
import
Path
from
urllib.parse
import
urlencode
from
..metadata.codemeta2zenodo
import
parse_codemeta_and_write_zenodo_metadata_file
zenodo_api_url
=
"
https://zenodo.org/api
"
class
ZenodoAPI
:
def
__init__
(
self
,
access_token
,
sandbox
=
True
,
proj_root_dir
=
'
./
'
):
...
...
@@ -38,11 +41,10 @@ class ZenodoAPI:
"""
if
sandbox
:
zenodo_api_url
=
"
https://sandbox.zenodo.org/api
"
self
.
zenodo_api_url
=
"
https://sandbox.zenodo.org/api
"
else
:
zenodo_api_url
=
"
https://zenodo.org/api
"
self
.
zenodo_api_url
=
zenodo_api_url
self
.
zenodo_api_url
=
zenodo_api_url
self
.
access_token
=
access_token
self
.
parameters
=
{
'
access_token
'
:
self
.
access_token
}
...
...
@@ -401,3 +403,69 @@ class ZenodoAPI:
"
`OSSR how to publish tutorial`:
\n
"
"
\t
https://escape2020.pages.in2p3.fr/wp3/ossr-pages/page/contribute/publish_tutorial/#3-add-the-following-code-snippet
\n
"
"
In case you do, please contact us !
\n
"
)
class
Record
:
def
__init__
(
self
,
data
:
dict
):
for
k
in
[
'
id
'
,
'
metadata
'
,
'
files
'
,
'
links
'
]:
if
k
not
in
data
.
keys
():
raise
ValueError
(
f
"
key
{
k
}
not present in data
"
)
self
.
data
=
data
def
__str__
(
self
):
entry_id
=
self
.
data
[
'
id
'
]
metadata
=
self
.
data
[
'
metadata
'
]
return
f
"
Record #
{
entry_id
}
:
{
metadata
[
'
title
'
]
}
"
def
__repr__
(
self
):
return
f
"
Record(
{
self
.
data
}
)
"
def
print_info
(
self
):
entry_id
=
self
.
data
[
'
id
'
]
metadata
=
self
.
data
[
'
metadata
'
]
descrp
=
metadata
[
'
description
'
]
print
(
f
"
=== Record #
{
entry_id
}
===
"
)
print
(
f
"
Title:
{
metadata
[
'
title
'
]
}
===
"
)
print
(
f
"
DOI:
{
self
.
data
[
'
doi
'
]
}
"
)
print
(
f
"
URL:
{
self
.
data
[
'
links
'
][
'
html
'
]
}
"
)
print
(
f
"
Description:
\n
{
descrp
}
"
)
print
(
'
\n
'
)
def
get_zenodo_records
(
search
=
''
,
**
kwargs
)
->
list
[
Record
]:
"""
Search the ossr based on `search`.
Function rewritten from pyzenodo3 (https://github.com/space-physics/pyzenodo3)
: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 `Record`
"""
search
=
search
.
replace
(
"
/
"
,
"
"
)
# zenodo can't handle '/' in search query
params
=
{
'
q
'
:
search
,
**
kwargs
}
url
=
zenodo_api_url
+
"
/records?
"
+
urlencode
(
params
)
recs
=
[
Record
(
hit
)
for
hit
in
requests
.
get
(
url
).
json
()[
"
hits
"
][
"
hits
"
]]
if
not
recs
:
raise
LookupError
(
f
"
No records found for search
{
search
}
"
)
return
recs
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