Skip to content
Snippets Groups Projects

New stable release

3 files
+ 96
116
Compare changes
  • Side-by-side
  • Inline

Files

+ 357
0
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"pycharm": {
"name": "#%% md\n"
}
},
"source": [
"# Deposit\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"pycharm": {
"name": "#%%\n"
}
},
"outputs": [],
"source": [
"import re\n",
"import requests as rq\n",
"\n",
"host = \"https://test.researchdata.tuwien.ac.at\"\n",
"file = \"./resources/audio.wav\"\n",
"token = \"kJTJMtRKzmA0S92A9Jks7Y1OQbtRWElzgUrldXehDbeXESxIGQ0BQ6JFEFyg\""
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"pycharm": {
"name": "#%%\n"
}
},
"outputs": [],
"source": [
"headers = {\n",
" \"Authorization\": \"Bearer \" + token\n",
"}\n",
"filename = re.findall(\"([a-zA-z0-9_-]+\\\\.wav)\", file)[0]"
]
},
{
"cell_type": "markdown",
"metadata": {
"pycharm": {
"name": "#%% md\n"
}
},
"source": [
"Create Record"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"pycharm": {
"name": "#%%\n"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'links': {'self': 'https://test.researchdata.tuwien.ac.at/api/records/pqb7y-mtf49/draft', 'self_html': 'https://test.researchdata.tuwien.ac.at/uploads/pqb7y-mtf49', 'files': 'https://test.researchdata.tuwien.ac.at/api/records/pqb7y-mtf49/draft/files', 'record': 'https://test.researchdata.tuwien.ac.at/api/records/pqb7y-mtf49', 'record_html': 'https://test.researchdata.tuwien.ac.at/records/pqb7y-mtf49', 'publish': 'https://test.researchdata.tuwien.ac.at/api/records/pqb7y-mtf49/draft/actions/publish', 'review': 'https://test.researchdata.tuwien.ac.at/api/records/pqb7y-mtf49/draft/review', 'versions': 'https://test.researchdata.tuwien.ac.at/api/records/pqb7y-mtf49/versions', 'access_links': 'https://test.researchdata.tuwien.ac.at/api/records/pqb7y-mtf49/access/links', 'reserve_doi': 'https://test.researchdata.tuwien.ac.at/api/records/pqb7y-mtf49/draft/pids/doi'}, 'created': '2022-07-19T07:39:42.344631+00:00', 'is_draft': True, 'expires_at': '2022-07-19 07:39:42.344656', 'is_published': False, 'metadata': {'title': 'The SeFiRe field recording dataset', 'resource_type': {'title': {'de': 'Audio', 'en': 'Audio'}, 'id': 'sound'}, 'creators': [{'affiliations': [{'name': 'University of Ljubljana'}], 'person_or_org': {'given_name': 'Matija', 'name': 'Marolt, Matija', 'identifiers': [{'scheme': 'orcid', 'identifier': '0000-0002-0619-8789'}], 'type': 'personal', 'family_name': 'Marolt'}}, {'affiliations': [{'name': 'University of Ljubljana'}], 'person_or_org': {'given_name': 'Ciril', 'name': 'Bohak, Ciril', 'identifiers': [{'scheme': 'orcid', 'identifier': '0000-0002-9015-2897'}], 'type': 'personal', 'family_name': 'Bohak'}}, {'affiliations': [{'name': 'University of Ljubljana'}], 'person_or_org': {'given_name': 'Alenka', 'name': 'Kavčič, Alenka', 'type': 'personal', 'family_name': 'Kavčič'}}, {'affiliations': [{'name': 'University of Ljubljana'}], 'person_or_org': {'given_name': 'Matevž', 'name': 'Pesek, Matevž', 'identifiers': [{'scheme': 'orcid', 'identifier': '0000-0001-9101-0471'}], 'type': 'personal', 'family_name': 'Pesek'}}], 'publication_date': '2019-01-28'}, 'id': 'pqb7y-mtf49', 'updated': '2022-07-19T07:39:42.362952+00:00', 'pids': {}, 'parent': {'communities': {}, 'id': '3yzsn-zkn15', 'access': {'links': [], 'owned_by': [{'user': 47}]}}, 'revision_id': 4, 'files': {'enabled': True, 'order': []}, 'versions': {'index': 1, 'is_latest': False, 'is_latest_draft': True}, 'access': {'files': 'public', 'record': 'public', 'embargo': {'reason': None, 'active': False}, 'status': 'metadata-only'}, 'errors': [{'field': 'access.embargo', 'messages': ['Field may not be null.']}]}\n"
]
}
],
"source": [
"response = rq.post(host + \"/api/records\", json={\n",
" \"access\": {\n",
" \"record\": \"public\",\n",
" \"files\": \"public\",\n",
" \"embargo\": None\n",
" },\n",
" \"files\": {\n",
" \"enabled\": True,\n",
" \"default_preview\": None\n",
" },\n",
" \"metadata\": {\n",
" \"creators\": [{\n",
" \"affiliations\": [\n",
" {\n",
" \"name\": \"University of Ljubljana\"\n",
" }\n",
" ],\n",
" \"person_or_org\": {\n",
" \"type\": \"personal\",\n",
" \"name\": \"M. Marolt\",\n",
" \"identifiers\": [\n",
" {\n",
" \"scheme\": \"orcid\",\n",
" \"identifier\": \"0000-0002-0619-8789\"\n",
" }\n",
" ],\n",
" \"given_name\": \"Matija\",\n",
" \"family_name\": \"Marolt\"\n",
" }\n",
" }, {\n",
" \"affiliations\": [\n",
" {\n",
" \"name\": \"University of Ljubljana\"\n",
" }\n",
" ],\n",
" \"person_or_org\": {\n",
" \"type\": \"personal\",\n",
" \"name\": \"C. Bohak\",\n",
" \"identifiers\": [\n",
" {\n",
" \"scheme\": \"orcid\",\n",
" \"identifier\": \"0000-0002-9015-2897\"\n",
" }\n",
" ],\n",
" \"given_name\": \"Ciril\",\n",
" \"family_name\": \"Bohak\"\n",
" }\n",
" }, {\n",
" \"affiliations\": [\n",
" {\n",
" \"name\": \"University of Ljubljana\"\n",
" }\n",
" ],\n",
" \"person_or_org\": {\n",
" \"type\": \"personal\",\n",
" \"name\": \"A. Kavčič\",\n",
" \"given_name\": \"Alenka\",\n",
" \"family_name\": \"Kavčič\"\n",
" }\n",
" }, {\n",
" \"affiliations\": [\n",
" {\n",
" \"name\": \"University of Ljubljana\"\n",
" }\n",
" ],\n",
" \"person_or_org\": {\n",
" \"type\": \"personal\",\n",
" \"name\": \"M. Pesek\",\n",
" \"identifiers\": [\n",
" {\n",
" \"scheme\": \"orcid\",\n",
" \"identifier\": \"0000-0001-9101-0471\"\n",
" }\n",
" ],\n",
" \"given_name\": \"Matevž\",\n",
" \"family_name\": \"Pesek\"\n",
" }\n",
" }],\n",
" \"title\": \"The SeFiRe field recording dataset\",\n",
" \"resource_type\": {\n",
" \"id\": \"sound\"\n",
" },\n",
" \"publication_date\": \"2019-01-28\"\n",
" }\n",
"}, headers=headers).json()\n",
"print(response)\n",
"record_id = response[\"id\"]"
]
},
{
"cell_type": "markdown",
"metadata": {
"pycharm": {
"name": "#%% md\n"
}
},
"source": [
"Announce"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"pycharm": {
"name": "#%%\n"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'enabled': True, 'links': {'self': 'https://test.researchdata.tuwien.ac.at/api/records/pqb7y-mtf49/draft/files'}, 'entries': [{'links': {'self': 'https://test.researchdata.tuwien.ac.at/api/records/pqb7y-mtf49/draft/files/audio.wav', 'content': 'https://test.researchdata.tuwien.ac.at/api/records/pqb7y-mtf49/draft/files/audio.wav/content', 'commit': 'https://test.researchdata.tuwien.ac.at/api/records/pqb7y-mtf49/draft/files/audio.wav/commit'}, 'created': '2022-07-19T07:39:48.031184+00:00', 'metadata': None, 'updated': '2022-07-19T07:39:48.032401+00:00', 'key': 'audio.wav', 'status': 'pending'}], 'default_preview': None, 'order': []}\n"
]
}
],
"source": [
"response = rq.post(host + \"/api/records/\" + record_id + \"/draft/files\", json=[{\n",
" \"key\": filename\n",
"}], headers=headers).json()\n",
"print(response)"
]
},
{
"cell_type": "markdown",
"metadata": {
"pycharm": {
"name": "#%% md\n"
}
},
"source": [
"Upload"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"pycharm": {
"name": "#%%\n"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'links': {'self': 'https://test.researchdata.tuwien.ac.at/api/records/pqb7y-mtf49/draft/files/audio.wav', 'content': 'https://test.researchdata.tuwien.ac.at/api/records/pqb7y-mtf49/draft/files/audio.wav/content', 'commit': 'https://test.researchdata.tuwien.ac.at/api/records/pqb7y-mtf49/draft/files/audio.wav/commit'}, 'created': '2022-07-19T07:39:48.031184+00:00', 'metadata': None, 'updated': '2022-07-19T07:39:48.032401+00:00', 'key': 'audio.wav', 'status': 'pending'}\n"
]
}
],
"source": [
"with open(file, mode='rb') as f:\n",
" response = rq.put(host + \"/api/records/\" + record_id + \"/draft/files/\" + filename + \"/content\", data=f.read(),\n",
" headers=headers).json()\n",
"print(response)"
]
},
{
"cell_type": "markdown",
"metadata": {
"pycharm": {
"name": "#%% md\n"
}
},
"source": [
"Commit"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"pycharm": {
"name": "#%%\n"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'links': {'self': 'https://test.researchdata.tuwien.ac.at/api/records/pqb7y-mtf49/draft/files/audio.wav', 'content': 'https://test.researchdata.tuwien.ac.at/api/records/pqb7y-mtf49/draft/files/audio.wav/content', 'commit': 'https://test.researchdata.tuwien.ac.at/api/records/pqb7y-mtf49/draft/files/audio.wav/commit'}, 'created': '2022-07-19T07:39:48.031184+00:00', 'checksum': 'md5:1e9f213a91e95bc4c54eac7c9ea7564d', 'mimetype': 'audio/x-wav', 'metadata': None, 'storage_class': 'S', 'updated': '2022-07-19T07:40:02.377175+00:00', 'file_id': '06493a5d-548d-4f7e-a27a-fd6f554d7687', 'key': 'audio.wav', 'size': 1792556, 'version_id': '17721b99-107d-49f9-b186-28fcd38cb495', 'status': 'completed', 'bucket_id': 'a0478dfa-23b6-434f-b0dd-2cedc2691c69'}\n"
]
}
],
"source": [
"response = rq.post(host + \"/api/records/\" + record_id + \"/draft/files/\" + filename + \"/commit\", headers=headers).json()\n",
"print(response)"
]
},
{
"cell_type": "markdown",
"metadata": {
"pycharm": {
"name": "#%% md\n"
}
},
"source": [
"Publish"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"pycharm": {
"name": "#%%\n"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'links': {'self': 'https://test.researchdata.tuwien.ac.at/api/records/pqb7y-mtf49', 'self_html': 'https://test.researchdata.tuwien.ac.at/records/pqb7y-mtf49', 'self_doi': 'https://test.researchdata.tuwien.ac.at/doi/10.70124/pqb7y-mtf49', 'doi': 'https://doi.org/10.70124/pqb7y-mtf49', 'files': 'https://test.researchdata.tuwien.ac.at/api/records/pqb7y-mtf49/files', 'latest': 'https://test.researchdata.tuwien.ac.at/api/records/pqb7y-mtf49/versions/latest', 'latest_html': 'https://test.researchdata.tuwien.ac.at/records/pqb7y-mtf49/latest', 'draft': 'https://test.researchdata.tuwien.ac.at/api/records/pqb7y-mtf49/draft', 'versions': 'https://test.researchdata.tuwien.ac.at/api/records/pqb7y-mtf49/versions', 'access_links': 'https://test.researchdata.tuwien.ac.at/api/records/pqb7y-mtf49/access/links', 'reserve_doi': 'https://test.researchdata.tuwien.ac.at/api/records/pqb7y-mtf49/draft/pids/doi'}, 'created': '2022-07-19T07:40:07.922234+00:00', 'is_draft': False, 'is_published': True, 'metadata': {'title': 'The SeFiRe field recording dataset', 'resource_type': {'title': {'de': 'Audio', 'en': 'Audio'}, 'id': 'sound'}, 'creators': [{'affiliations': [{'name': 'University of Ljubljana'}], 'person_or_org': {'given_name': 'Matija', 'name': 'Marolt, Matija', 'identifiers': [{'scheme': 'orcid', 'identifier': '0000-0002-0619-8789'}], 'type': 'personal', 'family_name': 'Marolt'}}, {'affiliations': [{'name': 'University of Ljubljana'}], 'person_or_org': {'given_name': 'Ciril', 'name': 'Bohak, Ciril', 'identifiers': [{'scheme': 'orcid', 'identifier': '0000-0002-9015-2897'}], 'type': 'personal', 'family_name': 'Bohak'}}, {'affiliations': [{'name': 'University of Ljubljana'}], 'person_or_org': {'given_name': 'Alenka', 'name': 'Kavčič, Alenka', 'type': 'personal', 'family_name': 'Kavčič'}}, {'affiliations': [{'name': 'University of Ljubljana'}], 'person_or_org': {'given_name': 'Matevž', 'name': 'Pesek, Matevž', 'identifiers': [{'scheme': 'orcid', 'identifier': '0000-0001-9101-0471'}], 'type': 'personal', 'family_name': 'Pesek'}}], 'publication_date': '2019-01-28'}, 'id': 'pqb7y-mtf49', 'updated': '2022-07-19T07:40:07.966322+00:00', 'pids': {'oai': {'provider': 'oai', 'identifier': 'oai:test.researchdata.tuwien.ac.at:pqb7y-mtf49'}, 'doi': {'client': 'datacite', 'provider': 'datacite', 'identifier': '10.70124/pqb7y-mtf49'}}, 'parent': {'communities': {}, 'id': '3yzsn-zkn15', 'access': {'links': [], 'owned_by': [{'user': 47}]}}, 'revision_id': 3, 'files': {'enabled': True, 'order': []}, 'versions': {'index': 1, 'is_latest': True, 'is_latest_draft': True}, 'access': {'files': 'public', 'record': 'public', 'embargo': {'reason': None, 'active': False}, 'status': 'open'}}\n"
]
}
],
"source": [
"response = rq.post(host + \"/api/records/\" + record_id + \"/draft/actions/publish\", headers=headers).json()\n",
"print(response)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"pycharm": {
"name": "#%%\n"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"https://test.researchdata.tuwien.ac.at/doi/10.70124/pqb7y-mtf49\n"
]
}
],
"source": [
"print(response[\"links\"][\"self_doi\"])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"pycharm": {
"name": "#%%\n"
}
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.10.4"
}
},
"nbformat": 4,
"nbformat_minor": 1
}
\ No newline at end of file
Loading