Skip to content
Snippets Groups Projects
Commit 47c36309 authored by Vuillaume's avatar Vuillaume
Browse files

hotfix notebook

parent 9bf370f4
No related branches found
No related tags found
1 merge request!53hotfix notebook
Pipeline #138035 passed
%% Cell type:markdown id:d5e9bc28 tags: %% Cell type:markdown id:d5e9bc28 tags:
# Upload records on the OSSR # Upload records on the OSSR
%% Cell type:markdown id:a4123841 tags: %% Cell type:markdown id:a4123841 tags:
To upload records on the OSSR, you may use the [Zenodo client](https://gitlab.in2p3.fr/escape2020/wp3/eossr/-/blob/master/eossr/api/zenodo.py). To upload records on the OSSR, you may use the [Zenodo client](https://gitlab.in2p3.fr/escape2020/wp3/eossr/-/blob/master/eossr/api/zenodo.py).
The client is also used by the continuous integration to automatise project's uploads from GitLab to Zenodo [check the EOSSR scripts here](https://gitlab.in2p3.fr/escape2020/wp3/eossr/-/tree/master/eossr/scripts). The client is also used by the continuous integration to automatise project's uploads from GitLab to Zenodo [check the EOSSR scripts here](https://gitlab.in2p3.fr/escape2020/wp3/eossr/-/tree/master/eossr/scripts).
**However**, to upload records to the OSSR, you **will need** to use your Zenodo token ([create one](https://zenodo.org/account/settings/applications/tokens/new/)). **However**, to upload records to the OSSR, you **will need** to use your Zenodo token ([create one](https://zenodo.org/account/settings/applications/tokens/new/)).
%% Cell type:code id:52aedbb2 tags: %% Cell type:code id:52aedbb2 tags:
``` python ``` python
token = $SANDBOX_ZENODO_TOKEN_GARCIA import os
token = os.getenv('SANDBOX_ZENODO_TOKEN_GARCIA') # Replace with your own token
``` ```
%% Cell type:code id:6fcd7ef2 tags: %% Cell type:code id:6fcd7ef2 tags:
``` python ``` python
import json import json
from eossr.api.zenodo import ZenodoAPI from eossr.api.zenodo import ZenodoAPI
# Please note that for this demo we are using Zenodo Sandbox. # Please note that for this demo we are using Zenodo Sandbox.
z = ZenodoAPI(access_token=token, sandbox=True) z = ZenodoAPI(access_token=token, sandbox=True)
``` ```
%% Cell type:code id:24eecce0 tags: %% Cell type:code id:24eecce0 tags:
``` python ``` python
``` ```
%% Cell type:markdown id:c13a5232 tags: %% Cell type:markdown id:c13a5232 tags:
## Create a new entry ## Create a new entry
First we would need to create a new entry First we would need to create a new entry
%% Cell type:code id:83075f0b tags: %% Cell type:code id:83075f0b tags:
``` python ``` python
new_entry = z.create_new_entry() new_entry = z.create_new_entry()
``` ```
%% Cell type:code id:84173c5d tags: %% Cell type:code id:84173c5d tags:
``` python ``` python
``` ```
%% Cell type:markdown id:fcd8e90c tags: %% Cell type:markdown id:fcd8e90c tags:
### Zenodo API answer handler ### Zenodo API answer handler
We have also developped a REST API response client to manage the answers from the Zenodo API. We have also developped a REST API response client to manage the answers from the Zenodo API.
%% Cell type:code id:22f8e2b2 tags: %% Cell type:code id:22f8e2b2 tags:
``` python ``` python
from eossr.api.zenodo.http_status import ZenodoHTTPStatus from eossr.api.zenodo.http_status import ZenodoHTTPStatus
``` ```
%% Cell type:code id:07fd3360 tags: %% Cell type:code id:07fd3360 tags:
``` python ``` python
status_new_entry = ZenodoHTTPStatus(new_entry.status_code, new_entry.json()) status_new_entry = ZenodoHTTPStatus(new_entry.status_code, new_entry.json())
print(status_new_entry) print(status_new_entry)
``` ```
%% Cell type:markdown id:b8761071 tags: %% Cell type:markdown id:b8761071 tags:
## Add files to the entry ## Add files to the entry
Then we upload to the new entry a file (let's say a `codemeta.json` metadata file) Then we upload to the new entry a file (let's say a `codemeta.json` metadata file)
%% Cell type:code id:74351af6 tags: %% Cell type:code id:74351af6 tags:
``` python ``` python
deposit_id = new_entry.json()['id'] deposit_id = new_entry.json()['id']
upload_file = z.upload_file_entry(deposit_id, upload_file = z.upload_file_entry(deposit_id,
name_file='codemeta.json', name_file='codemeta.json',
path_file='../../codemeta.json') path_file='../../codemeta.json')
``` ```
%% Cell type:code id:a836e493 tags: %% Cell type:code id:a836e493 tags:
``` python ``` python
status_upload = ZenodoHTTPStatus(upload_file.status_code, upload_file.json()) status_upload = ZenodoHTTPStatus(upload_file.status_code, upload_file.json())
print(status_upload) print(status_upload)
``` ```
%% Cell type:code id:7809adba tags: %% Cell type:code id:7809adba tags:
``` python ``` python
``` ```
%% Cell type:markdown id:aadbd21e tags: %% Cell type:markdown id:aadbd21e tags:
## Add metadata to the entry ## Add metadata to the entry
We add metadata to the Zenodo entry using the EOSSR codemeta2zenodo conversor We add metadata to the Zenodo entry using the EOSSR codemeta2zenodo conversor
%% Cell type:code id:c622d5c9 tags: %% Cell type:code id:c622d5c9 tags:
``` python ``` python
from eossr.metadata.codemeta2zenodo import parse_codemeta_and_write_zenodo_metadata_file from eossr.metadata.codemeta2zenodo import parse_codemeta_and_write_zenodo_metadata_file
``` ```
%% Cell type:code id:d0b1af6d tags: %% Cell type:code id:d0b1af6d tags:
``` python ``` python
parse_codemeta_and_write_zenodo_metadata_file(codemeta_filename='../../codemeta.json', parse_codemeta_and_write_zenodo_metadata_file(codemeta_filename='../../codemeta.json',
zenodo_outname='.zenodo.json') zenodo_outname='.zenodo.json')
``` ```
%% Cell type:code id:9f3cfedc tags: %% Cell type:code id:9f3cfedc tags:
``` python ``` python
# Let's have a look to the output to the .zenodo.json file # Let's have a look to the output to the .zenodo.json file
! cat .zenodo.json ! cat .zenodo.json
``` ```
%% Cell type:code id:7c37dc70 tags: %% Cell type:code id:7c37dc70 tags:
``` python ``` python
with open('.zenodo.json') as f: with open('.zenodo.json') as f:
zenodo_metadata = json.load(f) zenodo_metadata = json.load(f)
update_metadata_info = z.update_metadata_entry(deposit_id, json_metadata=zenodo_metadata) update_metadata_info = z.update_metadata_entry(deposit_id, json_metadata=zenodo_metadata)
``` ```
%% Cell type:code id:ae6554d9 tags: %% Cell type:code id:ae6554d9 tags:
``` python ``` python
status_metadata = ZenodoHTTPStatus(update_metadata_info.status_code, update_metadata_info.json()) status_metadata = ZenodoHTTPStatus(update_metadata_info.status_code, update_metadata_info.json())
print(status_metadata) print(status_metadata)
``` ```
%% Cell type:code id:1f67832d tags: %% Cell type:code id:1f67832d tags:
``` python ``` python
``` ```
%% Cell type:markdown id:c6a4df85 tags: %% Cell type:markdown id:c6a4df85 tags:
### Check the content of the new entry ### Check the content of the new entry
The `request` answers contain all the information of the current upload The `request` answers contain all the information of the current upload
%% Cell type:code id:4389a073 tags: %% Cell type:code id:4389a073 tags:
``` python ``` python
update_metadata_info.json() update_metadata_info.json()
``` ```
%% Cell type:markdown id:a62874c5 tags: %% Cell type:markdown id:a62874c5 tags:
We can check the files that we have already uploaded We can check the files that we have already uploaded
%% Cell type:code id:f0328d01 tags: %% Cell type:code id:f0328d01 tags:
``` python ``` python
update_metadata_info.json()['files'] update_metadata_info.json()['files']
``` ```
%% Cell type:markdown id:ae3ccdb8 tags: %% Cell type:markdown id:ae3ccdb8 tags:
Or the metadata updated Or the metadata updated
%% Cell type:code id:7111b368 tags: %% Cell type:code id:7111b368 tags:
``` python ``` python
update_metadata_info.json()['metadata'] update_metadata_info.json()['metadata']
``` ```
%% Cell type:code id:30337677 tags: %% Cell type:code id:30337677 tags:
``` python ``` python
``` ```
%% Cell type:markdown id:fa18756a tags: %% Cell type:markdown id:fa18756a tags:
## Publish the entry ## Publish the entry
Finally we can publish the new entry. Finally we can publish the new entry.
However in this case, because this is just a demo, we will just erase the entry. However in this case, because this is just a demo, we will just erase the entry.
%% Cell type:code id:6a9f1f09 tags: %% Cell type:code id:6a9f1f09 tags:
``` python ``` python
# In case you would like to publish the entry, just uncomment the following lines. # In case you would like to publish the entry, just uncomment the following lines.
# # publish = z.publish_entry(deposit_id) # # publish = z.publish_entry(deposit_id)
# # status = ZenodoHTTPStatus(publish.status_code, publish.json()) # # status = ZenodoHTTPStatus(publish.status_code, publish.json())
``` ```
%% Cell type:code id:ec4570b6 tags: %% Cell type:code id:ec4570b6 tags:
``` python ``` python
erase_entry = z.erase_entry(deposit_id) erase_entry = z.erase_entry(deposit_id)
``` ```
%% Cell type:code id:3691016e tags: %% Cell type:code id:3691016e tags:
``` python ``` python
ZenodoHTTPStatus(erase_entry.status_code).description ZenodoHTTPStatus(erase_entry.status_code).description
``` ```
%% Cell type:code id:406541ef tags: %% Cell type:code id:406541ef tags:
``` python ``` python
``` ```
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment