From de361420bf431f15c47339d36df2afe3c3d6dcc5 Mon Sep 17 00:00:00 2001 From: Dcosthephalump Date: Wed, 19 Jul 2023 18:04:17 -0600 Subject: [PATCH] #19 work --- manuscriptFiles.ipynb | 165 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 164 insertions(+), 1 deletion(-) diff --git a/manuscriptFiles.ipynb b/manuscriptFiles.ipynb index d403b1a..0d23fda 100644 --- a/manuscriptFiles.ipynb +++ b/manuscriptFiles.ipynb @@ -34,7 +34,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 2, "metadata": { "tags": [] }, @@ -456,6 +456,169 @@ "uploader.value" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## saveTranscript\n", + "\n", + "Like ```saveImage```, the ```saveTranscript``` function takes in:\n", + "- ```files```: a dictionary with data from a ```FileUploader``` widget\n", + "- ```targetDirectory```: a path to a directory for saving the relevant files" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "#| export\n", + "def saveTranscript(files:dict, targetDirectory):\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "tags": [] + }, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "67cb3e95f7fb46bf98037416306f03e9", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "FileUpload(value=(), description='Upload Manuscript Transcripts', layout=Layout(height='auto', width='auto'), …" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#| hide\n", + "import ipywidgets as widgets\n", + "\n", + "uploader = widgets.FileUpload(\n", + " accept = '', # Accepted file extension e.g. '.txt', '.pdf', 'image/*', 'image/*,.pdf'\n", + " multiple = True, # True to accept multiple files upload else False\n", + " description = 'Upload Manuscript Transcripts',\n", + " layout = widgets.Layout(height='auto', width='auto')\n", + ")\n", + "uploader" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "tags": [] + }, + "outputs": [ + { + "data": { + "text/plain": [ + "({'name': '15_01_0053_0006_f_3r_res.xml',\n", + " 'type': 'text/xml',\n", + " 'size': 18246,\n", + " 'content': ,\n", + " 'last_modified': datetime.datetime(2021, 7, 9, 16, 4, 20, tzinfo=datetime.timezone.utc)},\n", + " {'name': '15_01_0053_0007_f_3v_res.xml',\n", + " 'type': 'text/xml',\n", + " 'size': 27037,\n", + " 'content': ,\n", + " 'last_modified': datetime.datetime(2021, 7, 9, 16, 4, 20, tzinfo=datetime.timezone.utc)},\n", + " {'name': '15_01_0053_0008_f_4r_res.xml',\n", + " 'type': 'text/xml',\n", + " 'size': 26795,\n", + " 'content': ,\n", + " 'last_modified': datetime.datetime(2021, 7, 9, 16, 4, 20, tzinfo=datetime.timezone.utc)})" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "uploader.value" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": { + "tags": [] + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n" + ] + } + ], + "source": [ + "#| hide\n", + "import xml.etree.ElementTree as ET\n", + "input_stream = ET.parse(io.BytesIO(uploader.value[0]['content']))\n", + "root = input_stream.getroot()\n", + "\n", + "print(root)" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "metadata": { + "tags": [] + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "\n", + " \n" + ] + } + ], + "source": [ + "print(type(root))\n", + "\n", + "print(root[1][0].text)" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "metadata": { + "tags": [] + }, + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 32, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "root.keys" + ] + }, { "cell_type": "markdown", "metadata": {},