From 97afb945c2e619f8d1aabb1b7fa02c671ccbb28e Mon Sep 17 00:00:00 2001
From: Enrique Garcia <garcia@lapp.in2p3.fr>
Date: Tue, 28 Sep 2021 08:48:44 +0000
Subject: [PATCH] Upload records to the OSSR on notebook and improve __repr__
 on Records class

---
 eossr/api/zenodo/__init__.py                  |   7 +-
 examples/notebooks/Harvest_zenodo.ipynb       |   6 +-
 ....ipynb => ossr_api-Explore_the_OSSR.ipynb} | 214 +++++--
 .../ossr_api-Upload_records_OSSR.ipynb        | 575 ++++++++++++++++++
 4 files changed, 750 insertions(+), 52 deletions(-)
 rename examples/notebooks/{ossr_api.ipynb => ossr_api-Explore_the_OSSR.ipynb} (57%)
 create mode 100644 examples/notebooks/ossr_api-Upload_records_OSSR.ipynb

diff --git a/eossr/api/zenodo/__init__.py b/eossr/api/zenodo/__init__.py
index 043e31f0..3f055e5c 100644
--- a/eossr/api/zenodo/__init__.py
+++ b/eossr/api/zenodo/__init__.py
@@ -415,7 +415,6 @@ class ZenodoAPI:
               "\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")
 
-
     def get_user_records(self):
         request = self.fetch_user_entries()
         return [Record[hit] for hit in request.json()]
@@ -433,7 +432,7 @@ class Record:
         return f"Record #{self.id} : {self.title}"
 
     def __repr__(self):
-        return f"Record({self.data})"
+        return json.dumps(self.data, indent=4, sort_keys=True)
 
     @property
     def id(self):
@@ -479,7 +478,6 @@ class Record:
         return binder_zenodo_url + doi
 
 
-
 def get_zenodo_records(search='', sandbox=False, **kwargs):
     """
     Search Zenodo for records whose names or descriptions include the provided string `search`.
@@ -534,6 +532,3 @@ def get_record(record_id, sandbox=False):
         raise ValueError(f"Error {json['status']} : {json['message']}")
     else:
         return Record(json)
-
-
-
diff --git a/examples/notebooks/Harvest_zenodo.ipynb b/examples/notebooks/Harvest_zenodo.ipynb
index d7e137c4..ad36b200 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 bd379b11..4ebe50ef 100644
--- a/examples/notebooks/ossr_api.ipynb
+++ b/examples/notebooks/ossr_api-Explore_the_OSSR.ipynb
@@ -5,7 +5,12 @@
    "id": "4a25feec",
    "metadata": {},
    "source": [
-    "# Find ESCAPE OSSR records"
+    "# Find ESCAPE OSSR records\n",
+    "\n",
+    "\n",
+    "**Please note** that to fetch information from the OSSR, **token is needed**. \n",
+    "\n",
+    "The EOSSR API will get the public information that is available in the repository."
    ]
   },
   {
@@ -102,7 +107,170 @@
     {
      "data": {
       "text/plain": [
-       "Record({'conceptdoi': '10.5281/zenodo.5524912', 'conceptrecid': '5524912', 'created': '2021-09-23T15:03:51.644210+00:00', 'doi': '10.5281/zenodo.5524913', 'files': [{'bucket': '165e5f9a-17bc-4792-bd04-b01cef8b9fc7', 'checksum': 'md5:20d7ce7abc06541bed2655f19edfb956', 'key': 'codemeta.json', 'links': {'self': 'https://zenodo.org/api/files/165e5f9a-17bc-4792-bd04-b01cef8b9fc7/codemeta.json'}, 'size': 3271, 'type': 'json'}, {'bucket': '165e5f9a-17bc-4792-bd04-b01cef8b9fc7', 'checksum': 'md5:33489eacd42433ffdb66da2972b3e900', 'key': 'Docker_v0.2.tar', 'links': {'self': 'https://zenodo.org/api/files/165e5f9a-17bc-4792-bd04-b01cef8b9fc7/Docker_v0.2.tar'}, 'size': 3085572608, 'type': 'tar'}, {'bucket': '165e5f9a-17bc-4792-bd04-b01cef8b9fc7', 'checksum': 'md5:ef70d30cd1d548e1ba8ebd71679cbbb8', 'key': 'eossr-v0.2.zip', 'links': {'self': 'https://zenodo.org/api/files/165e5f9a-17bc-4792-bd04-b01cef8b9fc7/eossr-v0.2.zip'}, 'size': 60988, 'type': 'zip'}], 'id': 5524913, 'links': {'badge': 'https://zenodo.org/badge/doi/10.5281/zenodo.5524913.svg', 'bucket': 'https://zenodo.org/api/files/165e5f9a-17bc-4792-bd04-b01cef8b9fc7', 'conceptbadge': 'https://zenodo.org/badge/doi/10.5281/zenodo.5524912.svg', 'conceptdoi': 'https://doi.org/10.5281/zenodo.5524912', 'doi': 'https://doi.org/10.5281/zenodo.5524913', 'html': 'https://zenodo.org/record/5524913', 'latest': 'https://zenodo.org/api/records/5524913', 'latest_html': 'https://zenodo.org/record/5524913', 'self': 'https://zenodo.org/api/records/5524913'}, 'metadata': {'access_right': 'open', 'access_right_category': 'success', 'communities': [{'id': 'escape2020'}], 'creators': [{'affiliation': 'LAPP, CNRS', 'name': 'Vuillaume, Thomas', 'orcid': '0000-0002-5686-2078'}, {'affiliation': 'LAPP, CNRS', 'name': 'Garcia, Enrique', 'orcid': '0000-0003-2224-4594'}, {'affiliation': 'GSI', 'name': 'Tacke, Christian', 'orcid': '0000-0002-5321-8404'}, {'affiliation': 'ECAP, FAU (Nuremberg, Germany)', 'name': 'Gál, Tamás', 'orcid': '0000-0001-7821-8673'}], 'description': '<p>ESCAPE OSSR library</p>\\n\\n<ul>\\n\\t<li>Code: <a href=\"https://gitlab.in2p3.fr/escape2020/wp3/eossr\">https://gitlab.in2p3.fr/escape2020/wp3/eossr</a></li>\\n\\t<li>Documentation: <a href=\"https://escape2020.pages.in2p3.fr/wp3/eossr/\">https://escape2020.pages.in2p3.fr/wp3/eossr/</a></li>\\n</ul>', 'doi': '10.5281/zenodo.5524913', 'grants': [{'acronym': 'ESCAPE', 'code': '824064', 'funder': {'acronyms': [], 'doi': '10.13039/501100000780', 'links': {'self': 'https://zenodo.org/api/funders/10.13039/501100000780'}, 'name': 'European Commission'}, 'links': {'self': 'https://zenodo.org/api/grants/10.13039/501100000780::824064'}, 'program': 'H2020', 'title': 'European Science Cluster of Astronomy & Particle physics ESFRI research infrastructures'}], 'keywords': ['jupyter-notebook'], 'language': 'eng', 'license': {'id': 'MIT'}, 'notes': \"Release Notes:\\nThis major release of the eossr introduces 3 pillars that allow the user to interact easily with the ESCAPE OSSR:\\n\\n\\n- **API** module: introduces an API to communicate with the OSSR built on Zenodo's API:\\n   - fetch OSSR records\\n   - get records metadata\\n   - upload a new record\\n   - update an existing record\\n\\n\\n- **metadata** module:\\n   - implement the official metadata schema for the OSSR based on codemeta schema\\n   - method to translate codemeta metadata into zenodo metadata\\n\\n- **continuous integration**: collection of methods and snippets to allow users to use the gitlab CI to: \\n   - make a new record in the OSSR\\n   - update an existing record in the OSSR\\n   - build a Docker container / image\\n   - build a Singularity container / image\\n   - add containers to the gitlab registry\\n   - add images to your OSSR upload\", 'publication_date': '2021-09-23', 'related_identifiers': [{'identifier': 'https://gitlab.in2p3.fr/escape2020/wp3/eossr', 'relation': 'isSupplementTo', 'resource_type': 'software', 'scheme': 'url'}, {'identifier': '10.5281/zenodo.5524912', 'relation': 'isVersionOf', 'scheme': 'doi'}], 'relations': {'version': [{'count': 1, 'index': 0, 'is_last': True, 'last_child': {'pid_type': 'recid', 'pid_value': '5524913'}, 'parent': {'pid_type': 'recid', 'pid_value': '5524912'}}]}, 'resource_type': {'title': 'Software', 'type': 'software'}, 'title': 'eossr', 'version': 'v0.2'}, 'owners': [37616], 'revision': 4, 'stats': {'downloads': 11.0, 'unique_downloads': 6.0, 'unique_views': 3.0, 'version_downloads': 11.0, 'version_unique_downloads': 6.0, 'version_unique_views': 3.0, 'version_views': 5.0, 'version_volume': 3085720752.0, 'views': 5.0, 'volume': 3085720752.0}, 'updated': '2021-09-24T13:48:31.042154+00:00'})"
+       "{\n",
+       "    \"conceptdoi\": \"10.5281/zenodo.5524912\",\n",
+       "    \"conceptrecid\": \"5524912\",\n",
+       "    \"created\": \"2021-09-23T15:03:51.644210+00:00\",\n",
+       "    \"doi\": \"10.5281/zenodo.5524913\",\n",
+       "    \"files\": [\n",
+       "        {\n",
+       "            \"bucket\": \"165e5f9a-17bc-4792-bd04-b01cef8b9fc7\",\n",
+       "            \"checksum\": \"md5:20d7ce7abc06541bed2655f19edfb956\",\n",
+       "            \"key\": \"codemeta.json\",\n",
+       "            \"links\": {\n",
+       "                \"self\": \"https://zenodo.org/api/files/165e5f9a-17bc-4792-bd04-b01cef8b9fc7/codemeta.json\"\n",
+       "            },\n",
+       "            \"size\": 3271,\n",
+       "            \"type\": \"json\"\n",
+       "        },\n",
+       "        {\n",
+       "            \"bucket\": \"165e5f9a-17bc-4792-bd04-b01cef8b9fc7\",\n",
+       "            \"checksum\": \"md5:33489eacd42433ffdb66da2972b3e900\",\n",
+       "            \"key\": \"Docker_v0.2.tar\",\n",
+       "            \"links\": {\n",
+       "                \"self\": \"https://zenodo.org/api/files/165e5f9a-17bc-4792-bd04-b01cef8b9fc7/Docker_v0.2.tar\"\n",
+       "            },\n",
+       "            \"size\": 3085572608,\n",
+       "            \"type\": \"tar\"\n",
+       "        },\n",
+       "        {\n",
+       "            \"bucket\": \"165e5f9a-17bc-4792-bd04-b01cef8b9fc7\",\n",
+       "            \"checksum\": \"md5:ef70d30cd1d548e1ba8ebd71679cbbb8\",\n",
+       "            \"key\": \"eossr-v0.2.zip\",\n",
+       "            \"links\": {\n",
+       "                \"self\": \"https://zenodo.org/api/files/165e5f9a-17bc-4792-bd04-b01cef8b9fc7/eossr-v0.2.zip\"\n",
+       "            },\n",
+       "            \"size\": 60988,\n",
+       "            \"type\": \"zip\"\n",
+       "        }\n",
+       "    ],\n",
+       "    \"id\": 5524913,\n",
+       "    \"links\": {\n",
+       "        \"badge\": \"https://zenodo.org/badge/doi/10.5281/zenodo.5524913.svg\",\n",
+       "        \"bucket\": \"https://zenodo.org/api/files/165e5f9a-17bc-4792-bd04-b01cef8b9fc7\",\n",
+       "        \"conceptbadge\": \"https://zenodo.org/badge/doi/10.5281/zenodo.5524912.svg\",\n",
+       "        \"conceptdoi\": \"https://doi.org/10.5281/zenodo.5524912\",\n",
+       "        \"doi\": \"https://doi.org/10.5281/zenodo.5524913\",\n",
+       "        \"html\": \"https://zenodo.org/record/5524913\",\n",
+       "        \"latest\": \"https://zenodo.org/api/records/5524913\",\n",
+       "        \"latest_html\": \"https://zenodo.org/record/5524913\",\n",
+       "        \"self\": \"https://zenodo.org/api/records/5524913\"\n",
+       "    },\n",
+       "    \"metadata\": {\n",
+       "        \"access_right\": \"open\",\n",
+       "        \"access_right_category\": \"success\",\n",
+       "        \"communities\": [\n",
+       "            {\n",
+       "                \"id\": \"escape2020\"\n",
+       "            }\n",
+       "        ],\n",
+       "        \"creators\": [\n",
+       "            {\n",
+       "                \"affiliation\": \"LAPP, CNRS\",\n",
+       "                \"name\": \"Vuillaume, Thomas\",\n",
+       "                \"orcid\": \"0000-0002-5686-2078\"\n",
+       "            },\n",
+       "            {\n",
+       "                \"affiliation\": \"LAPP, CNRS\",\n",
+       "                \"name\": \"Garcia, Enrique\",\n",
+       "                \"orcid\": \"0000-0003-2224-4594\"\n",
+       "            },\n",
+       "            {\n",
+       "                \"affiliation\": \"GSI\",\n",
+       "                \"name\": \"Tacke, Christian\",\n",
+       "                \"orcid\": \"0000-0002-5321-8404\"\n",
+       "            },\n",
+       "            {\n",
+       "                \"affiliation\": \"ECAP, FAU (Nuremberg, Germany)\",\n",
+       "                \"name\": \"G\\u00e1l, Tam\\u00e1s\",\n",
+       "                \"orcid\": \"0000-0001-7821-8673\"\n",
+       "            }\n",
+       "        ],\n",
+       "        \"description\": \"<p>ESCAPE OSSR library</p>\\n\\n<ul>\\n\\t<li>Code: <a href=\\\"https://gitlab.in2p3.fr/escape2020/wp3/eossr\\\">https://gitlab.in2p3.fr/escape2020/wp3/eossr</a></li>\\n\\t<li>Documentation: <a href=\\\"https://escape2020.pages.in2p3.fr/wp3/eossr/\\\">https://escape2020.pages.in2p3.fr/wp3/eossr/</a></li>\\n</ul>\",\n",
+       "        \"doi\": \"10.5281/zenodo.5524913\",\n",
+       "        \"grants\": [\n",
+       "            {\n",
+       "                \"acronym\": \"ESCAPE\",\n",
+       "                \"code\": \"824064\",\n",
+       "                \"funder\": {\n",
+       "                    \"acronyms\": [],\n",
+       "                    \"doi\": \"10.13039/501100000780\",\n",
+       "                    \"links\": {\n",
+       "                        \"self\": \"https://zenodo.org/api/funders/10.13039/501100000780\"\n",
+       "                    },\n",
+       "                    \"name\": \"European Commission\"\n",
+       "                },\n",
+       "                \"links\": {\n",
+       "                    \"self\": \"https://zenodo.org/api/grants/10.13039/501100000780::824064\"\n",
+       "                },\n",
+       "                \"program\": \"H2020\",\n",
+       "                \"title\": \"European Science Cluster of Astronomy & Particle physics ESFRI research infrastructures\"\n",
+       "            }\n",
+       "        ],\n",
+       "        \"keywords\": [\n",
+       "            \"jupyter-notebook\"\n",
+       "        ],\n",
+       "        \"language\": \"eng\",\n",
+       "        \"license\": {\n",
+       "            \"id\": \"MIT\"\n",
+       "        },\n",
+       "        \"notes\": \"Release Notes:\\nThis major release of the eossr introduces 3 pillars that allow the user to interact easily with the ESCAPE OSSR:\\n\\n\\n- **API** module: introduces an API to communicate with the OSSR built on Zenodo's API:\\n   - fetch OSSR records\\n   - get records metadata\\n   - upload a new record\\n   - update an existing record\\n\\n\\n- **metadata** module:\\n   - implement the official metadata schema for the OSSR based on codemeta schema\\n   - method to translate codemeta metadata into zenodo metadata\\n\\n- **continuous integration**: collection of methods and snippets to allow users to use the gitlab CI to: \\n   - make a new record in the OSSR\\n   - update an existing record in the OSSR\\n   - build a Docker container / image\\n   - build a Singularity container / image\\n   - add containers to the gitlab registry\\n   - add images to your OSSR upload\",\n",
+       "        \"publication_date\": \"2021-09-23\",\n",
+       "        \"related_identifiers\": [\n",
+       "            {\n",
+       "                \"identifier\": \"https://gitlab.in2p3.fr/escape2020/wp3/eossr\",\n",
+       "                \"relation\": \"isSupplementTo\",\n",
+       "                \"resource_type\": \"software\",\n",
+       "                \"scheme\": \"url\"\n",
+       "            },\n",
+       "            {\n",
+       "                \"identifier\": \"10.5281/zenodo.5524912\",\n",
+       "                \"relation\": \"isVersionOf\",\n",
+       "                \"scheme\": \"doi\"\n",
+       "            }\n",
+       "        ],\n",
+       "        \"relations\": {\n",
+       "            \"version\": [\n",
+       "                {\n",
+       "                    \"count\": 1,\n",
+       "                    \"index\": 0,\n",
+       "                    \"is_last\": true,\n",
+       "                    \"last_child\": {\n",
+       "                        \"pid_type\": \"recid\",\n",
+       "                        \"pid_value\": \"5524913\"\n",
+       "                    },\n",
+       "                    \"parent\": {\n",
+       "                        \"pid_type\": \"recid\",\n",
+       "                        \"pid_value\": \"5524912\"\n",
+       "                    }\n",
+       "                }\n",
+       "            ]\n",
+       "        },\n",
+       "        \"resource_type\": {\n",
+       "            \"title\": \"Software\",\n",
+       "            \"type\": \"software\"\n",
+       "        },\n",
+       "        \"title\": \"eossr\",\n",
+       "        \"version\": \"v0.2\"\n",
+       "    },\n",
+       "    \"owners\": [\n",
+       "        37616\n",
+       "    ],\n",
+       "    \"revision\": 4,\n",
+       "    \"stats\": {\n",
+       "        \"downloads\": 13.0,\n",
+       "        \"unique_downloads\": 7.0,\n",
+       "        \"unique_views\": 6.0,\n",
+       "        \"version_downloads\": 13.0,\n",
+       "        \"version_unique_downloads\": 7.0,\n",
+       "        \"version_unique_views\": 6.0,\n",
+       "        \"version_views\": 8.0,\n",
+       "        \"version_volume\": 3085785011.0,\n",
+       "        \"views\": 8.0,\n",
+       "        \"volume\": 3085785011.0\n",
+       "    },\n",
+       "    \"updated\": \"2021-09-24T13:48:31.042154+00:00\"\n",
+       "}"
       ]
      },
      "execution_count": 6,
@@ -483,46 +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",
-    "This is also used by the continuous integration to automatise project's uploads from GitLab to Zenodo.\n",
-    "\n",
-    "To do so, you will need to use your Zenodo token ([create one](https://zenodo.org/account/settings/applications/tokens/new/))."
-   ]
-  },
-  {
-   "cell_type": "code",
-   "execution_count": 17,
-   "id": "69c6f758",
-   "metadata": {},
-   "outputs": [],
-   "source": [
-    "from eossr.api.zenodo import ZenodoAPI\n",
-    "token = ''\n",
-    "z = ZenodoAPI(access_token=token, sandbox=False)"
-   ]
-  },
-  {
-   "cell_type": "code",
-   "execution_count": null,
-   "id": "83075f0b",
-   "metadata": {},
-   "outputs": [],
-   "source": []
   }
  ],
  "metadata": {
@@ -541,7 +669,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-Upload_records_OSSR.ipynb b/examples/notebooks/ossr_api-Upload_records_OSSR.ipynb
new file mode 100644
index 00000000..c771da50
--- /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
+}
-- 
GitLab