diff --git a/examples/notebooks/Harvest_zenodo.ipynb b/examples/notebooks/Harvest_zenodo.ipynb index d7e137c4d8912a4cced15010c60131aa254fdd2c..ad36b200fe3b78e593d4691d74d722dda3c96026 100644 --- a/examples/notebooks/Harvest_zenodo.ipynb +++ b/examples/notebooks/Harvest_zenodo.ipynb @@ -673,8 +673,8 @@ "source": [ "## eossr\n", "\n", - "The eossr library uses Zenodo REST API.\n", - "See the [OSSR API notebook](ossr_search.ipynb) for an example on how to use it.\n" + "The eossr library uses the Zenodo REST API.\n", + "See the OSSR API notebooks ([Explore the OSSR](ossr_api-Explore_the_OSSR.ipynb) and [How to upload records to the OSSR](ossr_api-Upload_records_OSSR.ipynb)) for examples on how to use it.\n" ] }, { @@ -702,7 +702,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.2" + "version": "3.6.10" } }, "nbformat": 4, diff --git a/examples/notebooks/ossr_api.ipynb b/examples/notebooks/ossr_api-Explore_the_OSSR.ipynb similarity index 57% rename from examples/notebooks/ossr_api.ipynb rename to examples/notebooks/ossr_api-Explore_the_OSSR.ipynb index 468b037402e8d12bfd1d3b93584c980de78f03c6..4ebe50efac13f960a8fc62d8f5ce42deacbf4a06 100644 --- a/examples/notebooks/ossr_api.ipynb +++ b/examples/notebooks/ossr_api-Explore_the_OSSR.ipynb @@ -651,556 +651,6 @@ "metadata": {}, "outputs": [], "source": [] - }, - { - "cell_type": "markdown", - "id": "d5e9bc28", - "metadata": {}, - "source": [ - "# Upload records on the OSSR" - ] - }, - { - "cell_type": "markdown", - "id": "a4123841", - "metadata": {}, - "source": [ - "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).\n", - "\n", - "The client is also used by the continuous integration to automatise project's uploads from GitLab to Zenodo [check the EOSSR script here](https://gitlab.in2p3.fr/escape2020/wp3/eossr/-/tree/master/eossr/scripts).\n", - "\n", - "**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", - "execution_count": 35, - "id": "52aedbb2", - "metadata": {}, - "outputs": [], - "source": [ - "token = ''" - ] - }, - { - "cell_type": "code", - "execution_count": 18, - "id": "69c6f758", - "metadata": {}, - "outputs": [], - "source": [ - "import json\n", - "from eossr.api.zenodo import ZenodoAPI\n", - "\n", - "# Please note that for this demo we are using Zenodo Sandbox.\n", - "z = ZenodoAPI(access_token=token, sandbox=True)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "f21db195", - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "markdown", - "id": "c13a5232", - "metadata": {}, - "source": [ - "## Create a new entry\n", - "First we would need to create a new entry" - ] - }, - { - "cell_type": "code", - "execution_count": 19, - "id": "83075f0b", - "metadata": {}, - "outputs": [], - "source": [ - "new_entry = z.create_new_entry()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "f95cc72a", - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "markdown", - "id": "fcd8e90c", - "metadata": {}, - "source": [ - "### Zenodo API answer handler\n", - "\n", - "We have also developped a REST API response client to manage the answers from the Zenodo API." - ] - }, - { - "cell_type": "code", - "execution_count": 20, - "id": "22f8e2b2", - "metadata": {}, - "outputs": [], - "source": [ - "from eossr.api.zenodo.http_status import ZenodoHTTPStatus" - ] - }, - { - "cell_type": "code", - "execution_count": 21, - "id": "07fd3360", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "HTTP Status Code: 201 - Created.\n", - "Request succeeded. Response included. Usually sent for POST requests.\n" - ] - } - ], - "source": [ - "status_new_entry = ZenodoHTTPStatus(new_entry.status_code, new_entry.json())\n", - "print(status_new_entry)" - ] - }, - { - "cell_type": "markdown", - "id": "b8761071", - "metadata": {}, - "source": [ - "## Add files to the entry\n", - "\n", - "Then we upload to the new entry a file (let's say a `codemeta.json` metadata file)" - ] - }, - { - "cell_type": "code", - "execution_count": 22, - "id": "74351af6", - "metadata": {}, - "outputs": [], - "source": [ - "deposit_id = new_entry.json()['id']\n", - "upload_file = z.upload_file_entry(deposit_id, \n", - " name_file='codemeta.json', \n", - " path_file='../../codemeta.json')" - ] - }, - { - "cell_type": "code", - "execution_count": 23, - "id": "a836e493", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "HTTP Status Code: 200 - OK.\n", - "Request succeeded. Response included. Usually sent for GET/PUT/PATCH requests.\n" - ] - } - ], - "source": [ - "status_upload = ZenodoHTTPStatus(upload_file.status_code, upload_file.json())\n", - "print(status_upload)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "209e6efd", - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "markdown", - "id": "aadbd21e", - "metadata": {}, - "source": [ - "## Add metadata to the entry\n", - "\n", - "We add metadata to the Zenodo entry using the EOSSR codemeta2zenodo conversor" - ] - }, - { - "cell_type": "code", - "execution_count": 24, - "id": "c622d5c9", - "metadata": {}, - "outputs": [], - "source": [ - "from eossr.metadata.codemeta2zenodo import parse_codemeta_and_write_zenodo_metadata_file" - ] - }, - { - "cell_type": "code", - "execution_count": 25, - "id": "d0b1af6d", - "metadata": {}, - "outputs": [], - "source": [ - "parse_codemeta_and_write_zenodo_metadata_file(codemeta_filename='../../codemeta.json', \n", - " zenodo_outname='.zenodo.json')" - ] - }, - { - "cell_type": "code", - "execution_count": 26, - "id": "9f3cfedc", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{\r\n", - " \"access_right\": \"open\",\r\n", - " \"communities\": [\r\n", - " {\r\n", - " \"identifier\": \"escape2020\"\r\n", - " }\r\n", - " ],\r\n", - " \"creators\": [\r\n", - " {\r\n", - " \"affiliation\": \"LAPP, CNRS\",\r\n", - " \"name\": \"Vuillaume, Thomas\",\r\n", - " \"orcid\": \"0000-0002-5686-2078\"\r\n", - " },\r\n", - " {\r\n", - " \"affiliation\": \"LAPP, CNRS\",\r\n", - " \"name\": \"Garcia, Enrique\",\r\n", - " \"orcid\": \"0000-0003-2224-4594\"\r\n", - " },\r\n", - " {\r\n", - " \"affiliation\": \"GSI\",\r\n", - " \"name\": \"Tacke, Christian\",\r\n", - " \"orcid\": \"0000-0002-5321-8404\"\r\n", - " },\r\n", - " {\r\n", - " \"affiliation\": \"ECAP, FAU (Nuremberg, Germany)\",\r\n", - " \"name\": \"G\\u00e1l, Tam\\u00e1s\",\r\n", - " \"orcid\": \"0000-0001-7821-8673\"\r\n", - " }\r\n", - " ],\r\n", - " \"description\": \"ESCAPE OSSR library\",\r\n", - " \"grants\": [\r\n", - " {\r\n", - " \"id\": \"10.13039/501100000780::824064\"\r\n", - " }\r\n", - " ],\r\n", - " \"keywords\": [\r\n", - " \"jupyter-notebook\"\r\n", - " ],\r\n", - " \"language\": \"eng\",\r\n", - " \"license\": \"MIT\",\r\n", - " \"notes\": \"Release Notes: \",\r\n", - " \"publication_date\": \"2021-09-23\",\r\n", - " \"title\": \"eossr\",\r\n", - " \"upload_type\": \"software\",\r\n", - " \"version\": \"v0.2\"\r\n", - "}" - ] - } - ], - "source": [ - "# Let's have a look to the output to the .zenodo.json file\n", - "! cat .zenodo.json" - ] - }, - { - "cell_type": "code", - "execution_count": 27, - "id": "7c37dc70", - "metadata": {}, - "outputs": [], - "source": [ - "with open('.zenodo.json') as f:\n", - " zenodo_metadata = json.load(f)\n", - "update_metadata_info = z.update_metadata_entry(deposit_id, json_metadata=zenodo_metadata)" - ] - }, - { - "cell_type": "code", - "execution_count": 28, - "id": "ae6554d9", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "HTTP Status Code: 200 - OK.\n", - "Request succeeded. Response included. Usually sent for GET/PUT/PATCH requests.\n" - ] - } - ], - "source": [ - "status_metadata = ZenodoHTTPStatus(update_metadata_info.status_code, update_metadata_info.json())\n", - "print(status_metadata)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "43dd7e42", - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "markdown", - "id": "c6a4df85", - "metadata": {}, - "source": [ - "### Check the content of the new entry\n", - "\n", - "The `request` answers contain all the information of the current upload" - ] - }, - { - "cell_type": "code", - "execution_count": 29, - "id": "4389a073", - "metadata": { - "scrolled": true - }, - "outputs": [ - { - "data": { - "text/plain": [ - "{'conceptrecid': '925085',\n", - " 'created': '2021-09-27T14:13:53.212998+00:00',\n", - " 'doi': '',\n", - " 'doi_url': 'https://doi.org/',\n", - " 'files': [{'checksum': '20d7ce7abc06541bed2655f19edfb956',\n", - " 'filename': 'codemeta.json',\n", - " 'filesize': 3271,\n", - " 'id': '18daad60-bed2-4cfc-bf80-572ee01f0d98',\n", - " 'links': {'download': 'https://sandbox.zenodo.org/api/files/3bbc44ab-abf8-40a3-808c-b5313ab8da1d/codemeta.json',\n", - " 'self': 'https://sandbox.zenodo.org/api/deposit/depositions/925086/files/18daad60-bed2-4cfc-bf80-572ee01f0d98'}}],\n", - " 'id': 925086,\n", - " 'links': {'bucket': 'https://sandbox.zenodo.org/api/files/3bbc44ab-abf8-40a3-808c-b5313ab8da1d',\n", - " 'discard': 'https://sandbox.zenodo.org/api/deposit/depositions/925086/actions/discard',\n", - " 'edit': 'https://sandbox.zenodo.org/api/deposit/depositions/925086/actions/edit',\n", - " 'files': 'https://sandbox.zenodo.org/api/deposit/depositions/925086/files',\n", - " 'html': 'https://sandbox.zenodo.org/deposit/925086',\n", - " 'latest_draft': 'https://sandbox.zenodo.org/api/deposit/depositions/925086',\n", - " 'latest_draft_html': 'https://sandbox.zenodo.org/deposit/925086',\n", - " 'newversion': 'https://sandbox.zenodo.org/api/deposit/depositions/925086/actions/newversion',\n", - " 'publish': 'https://sandbox.zenodo.org/api/deposit/depositions/925086/actions/publish',\n", - " 'registerconceptdoi': 'https://sandbox.zenodo.org/api/deposit/depositions/925086/actions/registerconceptdoi',\n", - " 'self': 'https://sandbox.zenodo.org/api/deposit/depositions/925086'},\n", - " 'metadata': {'access_right': 'open',\n", - " 'communities': [{'identifier': 'escape2020'}],\n", - " 'creators': [{'affiliation': 'LAPP, CNRS',\n", - " 'name': 'Vuillaume, Thomas',\n", - " 'orcid': '0000-0002-5686-2078'},\n", - " {'affiliation': 'LAPP, CNRS',\n", - " 'name': 'Garcia, Enrique',\n", - " 'orcid': '0000-0003-2224-4594'},\n", - " {'affiliation': 'GSI',\n", - " 'name': 'Tacke, Christian',\n", - " 'orcid': '0000-0002-5321-8404'},\n", - " {'affiliation': 'ECAP, FAU (Nuremberg, Germany)',\n", - " 'name': 'Gál, Tamás',\n", - " 'orcid': '0000-0001-7821-8673'}],\n", - " 'description': 'ESCAPE OSSR library',\n", - " 'doi': '',\n", - " 'grants': [{'id': '10.13039/501100000780::824064'}],\n", - " 'keywords': ['jupyter-notebook'],\n", - " 'language': 'eng',\n", - " 'license': 'MIT',\n", - " 'notes': 'Release Notes:',\n", - " 'prereserve_doi': {'doi': '10.5072/zenodo.925086', 'recid': 925086},\n", - " 'publication_date': '2021-09-23',\n", - " 'title': 'eossr',\n", - " 'upload_type': 'software',\n", - " 'version': 'v0.2'},\n", - " 'modified': '2021-09-27T14:13:54.246249+00:00',\n", - " 'owner': 34397,\n", - " 'record_id': 925086,\n", - " 'state': 'unsubmitted',\n", - " 'submitted': False,\n", - " 'title': 'eossr'}" - ] - }, - "execution_count": 29, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "update_metadata_info.json()" - ] - }, - { - "cell_type": "markdown", - "id": "a62874c5", - "metadata": {}, - "source": [ - "We can check the files that we have already uploaded" - ] - }, - { - "cell_type": "code", - "execution_count": 30, - "id": "f0328d01", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "[{'checksum': '20d7ce7abc06541bed2655f19edfb956',\n", - " 'filename': 'codemeta.json',\n", - " 'filesize': 3271,\n", - " 'id': '18daad60-bed2-4cfc-bf80-572ee01f0d98',\n", - " 'links': {'download': 'https://sandbox.zenodo.org/api/files/3bbc44ab-abf8-40a3-808c-b5313ab8da1d/codemeta.json',\n", - " 'self': 'https://sandbox.zenodo.org/api/deposit/depositions/925086/files/18daad60-bed2-4cfc-bf80-572ee01f0d98'}}]" - ] - }, - "execution_count": 30, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "update_metadata_info.json()['files']" - ] - }, - { - "cell_type": "markdown", - "id": "ae3ccdb8", - "metadata": {}, - "source": [ - "Or the metadata updated " - ] - }, - { - "cell_type": "code", - "execution_count": 31, - "id": "7111b368", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'access_right': 'open',\n", - " 'communities': [{'identifier': 'escape2020'}],\n", - " 'creators': [{'affiliation': 'LAPP, CNRS',\n", - " 'name': 'Vuillaume, Thomas',\n", - " 'orcid': '0000-0002-5686-2078'},\n", - " {'affiliation': 'LAPP, CNRS',\n", - " 'name': 'Garcia, Enrique',\n", - " 'orcid': '0000-0003-2224-4594'},\n", - " {'affiliation': 'GSI',\n", - " 'name': 'Tacke, Christian',\n", - " 'orcid': '0000-0002-5321-8404'},\n", - " {'affiliation': 'ECAP, FAU (Nuremberg, Germany)',\n", - " 'name': 'Gál, Tamás',\n", - " 'orcid': '0000-0001-7821-8673'}],\n", - " 'description': 'ESCAPE OSSR library',\n", - " 'doi': '',\n", - " 'grants': [{'id': '10.13039/501100000780::824064'}],\n", - " 'keywords': ['jupyter-notebook'],\n", - " 'language': 'eng',\n", - " 'license': 'MIT',\n", - " 'notes': 'Release Notes:',\n", - " 'prereserve_doi': {'doi': '10.5072/zenodo.925086', 'recid': 925086},\n", - " 'publication_date': '2021-09-23',\n", - " 'title': 'eossr',\n", - " 'upload_type': 'software',\n", - " 'version': 'v0.2'}" - ] - }, - "execution_count": 31, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "update_metadata_info.json()['metadata']" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "f7d54a26", - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "markdown", - "id": "fa18756a", - "metadata": {}, - "source": [ - "## Publish the entry\n", - "\n", - "Finally we can publish the new entry. \n", - "However in this case, because this is just a demo, we will just erase the entry." - ] - }, - { - "cell_type": "code", - "execution_count": 32, - "id": "6a9f1f09", - "metadata": {}, - "outputs": [], - "source": [ - "# In case you would like to publish the entry, just uncomment the following lines.\n", - "\n", - "# # publish = z.publish_entry(deposit_id)\n", - "# # status = ZenodoHTTPStatus(publish.status_code, publish.json())" - ] - }, - { - "cell_type": "code", - "execution_count": 33, - "id": "ec4570b6", - "metadata": {}, - "outputs": [], - "source": [ - "erase_entry = z.erase_entry(deposit_id)" - ] - }, - { - "cell_type": "code", - "execution_count": 34, - "id": "3691016e", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'Request succeeded. No response included. Usually sent for DELETE requests'" - ] - }, - "execution_count": 34, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "ZenodoHTTPStatus(erase_entry.status_code).description" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "83a087f5", - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { diff --git a/examples/notebooks/ossr_api-Upload_records_OSSR.ipynb b/examples/notebooks/ossr_api-Upload_records_OSSR.ipynb new file mode 100644 index 0000000000000000000000000000000000000000..c771da50b17f7e6abe4bafc21af000d8aaa7849c --- /dev/null +++ b/examples/notebooks/ossr_api-Upload_records_OSSR.ipynb @@ -0,0 +1,575 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "d5e9bc28", + "metadata": {}, + "source": [ + "# Upload records on the OSSR" + ] + }, + { + "cell_type": "markdown", + "id": "a4123841", + "metadata": {}, + "source": [ + "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).\n", + "\n", + "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).\n", + "\n", + "**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", + "execution_count": 19, + "id": "52aedbb2", + "metadata": {}, + "outputs": [], + "source": [ + "token = ''" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "6fcd7ef2", + "metadata": {}, + "outputs": [], + "source": [ + "import json\n", + "from eossr.api.zenodo import ZenodoAPI\n", + "\n", + "# Please note that for this demo we are using Zenodo Sandbox.\n", + "z = ZenodoAPI(access_token=token, sandbox=True)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "24eecce0", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "c13a5232", + "metadata": {}, + "source": [ + "## Create a new entry\n", + "First we would need to create a new entry" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "83075f0b", + "metadata": {}, + "outputs": [], + "source": [ + "new_entry = z.create_new_entry()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "84173c5d", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "fcd8e90c", + "metadata": {}, + "source": [ + "### Zenodo API answer handler\n", + "\n", + "We have also developped a REST API response client to manage the answers from the Zenodo API." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "22f8e2b2", + "metadata": {}, + "outputs": [], + "source": [ + "from eossr.api.zenodo.http_status import ZenodoHTTPStatus" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "07fd3360", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "HTTP Status Code: 201 - Created.\n", + "Request succeeded. Response included. Usually sent for POST requests.\n" + ] + } + ], + "source": [ + "status_new_entry = ZenodoHTTPStatus(new_entry.status_code, new_entry.json())\n", + "print(status_new_entry)" + ] + }, + { + "cell_type": "markdown", + "id": "b8761071", + "metadata": {}, + "source": [ + "## Add files to the entry\n", + "\n", + "Then we upload to the new entry a file (let's say a `codemeta.json` metadata file)" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "74351af6", + "metadata": {}, + "outputs": [], + "source": [ + "deposit_id = new_entry.json()['id']\n", + "upload_file = z.upload_file_entry(deposit_id, \n", + " name_file='codemeta.json', \n", + " path_file='../../codemeta.json')" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "a836e493", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "HTTP Status Code: 200 - OK.\n", + "Request succeeded. Response included. Usually sent for GET/PUT/PATCH requests.\n" + ] + } + ], + "source": [ + "status_upload = ZenodoHTTPStatus(upload_file.status_code, upload_file.json())\n", + "print(status_upload)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7809adba", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "aadbd21e", + "metadata": {}, + "source": [ + "## Add metadata to the entry\n", + "\n", + "We add metadata to the Zenodo entry using the EOSSR codemeta2zenodo conversor" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "c622d5c9", + "metadata": {}, + "outputs": [], + "source": [ + "from eossr.metadata.codemeta2zenodo import parse_codemeta_and_write_zenodo_metadata_file" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "d0b1af6d", + "metadata": {}, + "outputs": [], + "source": [ + "parse_codemeta_and_write_zenodo_metadata_file(codemeta_filename='../../codemeta.json', \n", + " zenodo_outname='.zenodo.json')" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "9f3cfedc", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{\r\n", + " \"access_right\": \"open\",\r\n", + " \"communities\": [\r\n", + " {\r\n", + " \"identifier\": \"escape2020\"\r\n", + " }\r\n", + " ],\r\n", + " \"creators\": [\r\n", + " {\r\n", + " \"affiliation\": \"LAPP, CNRS\",\r\n", + " \"name\": \"Vuillaume, Thomas\",\r\n", + " \"orcid\": \"0000-0002-5686-2078\"\r\n", + " },\r\n", + " {\r\n", + " \"affiliation\": \"LAPP, CNRS\",\r\n", + " \"name\": \"Garcia, Enrique\",\r\n", + " \"orcid\": \"0000-0003-2224-4594\"\r\n", + " },\r\n", + " {\r\n", + " \"affiliation\": \"GSI\",\r\n", + " \"name\": \"Tacke, Christian\",\r\n", + " \"orcid\": \"0000-0002-5321-8404\"\r\n", + " },\r\n", + " {\r\n", + " \"affiliation\": \"ECAP, FAU (Nuremberg, Germany)\",\r\n", + " \"name\": \"G\\u00e1l, Tam\\u00e1s\",\r\n", + " \"orcid\": \"0000-0001-7821-8673\"\r\n", + " }\r\n", + " ],\r\n", + " \"description\": \"ESCAPE OSSR library\",\r\n", + " \"grants\": [\r\n", + " {\r\n", + " \"id\": \"10.13039/501100000780::824064\"\r\n", + " }\r\n", + " ],\r\n", + " \"keywords\": [\r\n", + " \"jupyter-notebook\"\r\n", + " ],\r\n", + " \"language\": \"eng\",\r\n", + " \"license\": \"MIT\",\r\n", + " \"notes\": \"Release Notes: \",\r\n", + " \"publication_date\": \"2021-09-23\",\r\n", + " \"title\": \"eossr\",\r\n", + " \"upload_type\": \"software\",\r\n", + " \"version\": \"v0.2\"\r\n", + "}" + ] + } + ], + "source": [ + "# Let's have a look to the output to the .zenodo.json file\n", + "! cat .zenodo.json" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "7c37dc70", + "metadata": {}, + "outputs": [], + "source": [ + "with open('.zenodo.json') as f:\n", + " zenodo_metadata = json.load(f)\n", + "update_metadata_info = z.update_metadata_entry(deposit_id, json_metadata=zenodo_metadata)" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "id": "ae6554d9", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "HTTP Status Code: 200 - OK.\n", + "Request succeeded. Response included. Usually sent for GET/PUT/PATCH requests.\n" + ] + } + ], + "source": [ + "status_metadata = ZenodoHTTPStatus(update_metadata_info.status_code, update_metadata_info.json())\n", + "print(status_metadata)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1f67832d", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "c6a4df85", + "metadata": {}, + "source": [ + "### Check the content of the new entry\n", + "\n", + "The `request` answers contain all the information of the current upload" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "id": "4389a073", + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "text/plain": [ + "{'conceptrecid': '925643',\n", + " 'created': '2021-09-28T08:24:19.636324+00:00',\n", + " 'doi': '',\n", + " 'doi_url': 'https://doi.org/',\n", + " 'files': [{'checksum': '20d7ce7abc06541bed2655f19edfb956',\n", + " 'filename': 'codemeta.json',\n", + " 'filesize': 3271,\n", + " 'id': '635a061a-dbad-42dc-af7e-4815597e4570',\n", + " 'links': {'download': 'https://sandbox.zenodo.org/api/files/5c5ca785-e9a0-4b29-8c84-9b75f37ac963/codemeta.json',\n", + " 'self': 'https://sandbox.zenodo.org/api/deposit/depositions/925644/files/635a061a-dbad-42dc-af7e-4815597e4570'}}],\n", + " 'id': 925644,\n", + " 'links': {'bucket': 'https://sandbox.zenodo.org/api/files/5c5ca785-e9a0-4b29-8c84-9b75f37ac963',\n", + " 'discard': 'https://sandbox.zenodo.org/api/deposit/depositions/925644/actions/discard',\n", + " 'edit': 'https://sandbox.zenodo.org/api/deposit/depositions/925644/actions/edit',\n", + " 'files': 'https://sandbox.zenodo.org/api/deposit/depositions/925644/files',\n", + " 'html': 'https://sandbox.zenodo.org/deposit/925644',\n", + " 'latest_draft': 'https://sandbox.zenodo.org/api/deposit/depositions/925644',\n", + " 'latest_draft_html': 'https://sandbox.zenodo.org/deposit/925644',\n", + " 'newversion': 'https://sandbox.zenodo.org/api/deposit/depositions/925644/actions/newversion',\n", + " 'publish': 'https://sandbox.zenodo.org/api/deposit/depositions/925644/actions/publish',\n", + " 'registerconceptdoi': 'https://sandbox.zenodo.org/api/deposit/depositions/925644/actions/registerconceptdoi',\n", + " 'self': 'https://sandbox.zenodo.org/api/deposit/depositions/925644'},\n", + " 'metadata': {'access_right': 'open',\n", + " 'communities': [{'identifier': 'escape2020'}],\n", + " 'creators': [{'affiliation': 'LAPP, CNRS',\n", + " 'name': 'Vuillaume, Thomas',\n", + " 'orcid': '0000-0002-5686-2078'},\n", + " {'affiliation': 'LAPP, CNRS',\n", + " 'name': 'Garcia, Enrique',\n", + " 'orcid': '0000-0003-2224-4594'},\n", + " {'affiliation': 'GSI',\n", + " 'name': 'Tacke, Christian',\n", + " 'orcid': '0000-0002-5321-8404'},\n", + " {'affiliation': 'ECAP, FAU (Nuremberg, Germany)',\n", + " 'name': 'Gál, Tamás',\n", + " 'orcid': '0000-0001-7821-8673'}],\n", + " 'description': 'ESCAPE OSSR library',\n", + " 'doi': '',\n", + " 'grants': [{'id': '10.13039/501100000780::824064'}],\n", + " 'keywords': ['jupyter-notebook'],\n", + " 'language': 'eng',\n", + " 'license': 'MIT',\n", + " 'notes': 'Release Notes:',\n", + " 'prereserve_doi': {'doi': '10.5072/zenodo.925644', 'recid': 925644},\n", + " 'publication_date': '2021-09-23',\n", + " 'title': 'eossr',\n", + " 'upload_type': 'software',\n", + " 'version': 'v0.2'},\n", + " 'modified': '2021-09-28T08:24:20.541025+00:00',\n", + " 'owner': 34397,\n", + " 'record_id': 925644,\n", + " 'state': 'unsubmitted',\n", + " 'submitted': False,\n", + " 'title': 'eossr'}" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "update_metadata_info.json()" + ] + }, + { + "cell_type": "markdown", + "id": "a62874c5", + "metadata": {}, + "source": [ + "We can check the files that we have already uploaded" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "id": "f0328d01", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[{'checksum': '20d7ce7abc06541bed2655f19edfb956',\n", + " 'filename': 'codemeta.json',\n", + " 'filesize': 3271,\n", + " 'id': '635a061a-dbad-42dc-af7e-4815597e4570',\n", + " 'links': {'download': 'https://sandbox.zenodo.org/api/files/5c5ca785-e9a0-4b29-8c84-9b75f37ac963/codemeta.json',\n", + " 'self': 'https://sandbox.zenodo.org/api/deposit/depositions/925644/files/635a061a-dbad-42dc-af7e-4815597e4570'}}]" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "update_metadata_info.json()['files']" + ] + }, + { + "cell_type": "markdown", + "id": "ae3ccdb8", + "metadata": {}, + "source": [ + "Or the metadata updated " + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "id": "7111b368", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'access_right': 'open',\n", + " 'communities': [{'identifier': 'escape2020'}],\n", + " 'creators': [{'affiliation': 'LAPP, CNRS',\n", + " 'name': 'Vuillaume, Thomas',\n", + " 'orcid': '0000-0002-5686-2078'},\n", + " {'affiliation': 'LAPP, CNRS',\n", + " 'name': 'Garcia, Enrique',\n", + " 'orcid': '0000-0003-2224-4594'},\n", + " {'affiliation': 'GSI',\n", + " 'name': 'Tacke, Christian',\n", + " 'orcid': '0000-0002-5321-8404'},\n", + " {'affiliation': 'ECAP, FAU (Nuremberg, Germany)',\n", + " 'name': 'Gál, Tamás',\n", + " 'orcid': '0000-0001-7821-8673'}],\n", + " 'description': 'ESCAPE OSSR library',\n", + " 'doi': '',\n", + " 'grants': [{'id': '10.13039/501100000780::824064'}],\n", + " 'keywords': ['jupyter-notebook'],\n", + " 'language': 'eng',\n", + " 'license': 'MIT',\n", + " 'notes': 'Release Notes:',\n", + " 'prereserve_doi': {'doi': '10.5072/zenodo.925644', 'recid': 925644},\n", + " 'publication_date': '2021-09-23',\n", + " 'title': 'eossr',\n", + " 'upload_type': 'software',\n", + " 'version': 'v0.2'}" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "update_metadata_info.json()['metadata']" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "30337677", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "fa18756a", + "metadata": {}, + "source": [ + "## Publish the entry\n", + "\n", + "Finally we can publish the new entry. \n", + "However in this case, because this is just a demo, we will just erase the entry." + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "id": "6a9f1f09", + "metadata": {}, + "outputs": [], + "source": [ + "# In case you would like to publish the entry, just uncomment the following lines.\n", + "\n", + "# # publish = z.publish_entry(deposit_id)\n", + "# # status = ZenodoHTTPStatus(publish.status_code, publish.json())" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "id": "ec4570b6", + "metadata": {}, + "outputs": [], + "source": [ + "erase_entry = z.erase_entry(deposit_id)" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "id": "3691016e", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Request succeeded. No response included. Usually sent for DELETE requests'" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "ZenodoHTTPStatus(erase_entry.status_code).description" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "406541ef", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.6.10" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}