From 416a65c303c074b1499ab1afa3287fc0f7a482be Mon Sep 17 00:00:00 2001 From: 512song Date: Tue, 19 Oct 2021 06:31:09 +0800 Subject: [PATCH] 20211018 --- 体质检测管理.ipynb | 130 ++++++++++++++++++++++----------------------- 1 file changed, 63 insertions(+), 67 deletions(-) diff --git a/体质检测管理.ipynb b/体质检测管理.ipynb index 29c5463..20cc579 100644 --- a/体质检测管理.ipynb +++ b/体质检测管理.ipynb @@ -69,27 +69,12 @@ }, { "cell_type": "code", - "execution_count": 77, + "execution_count": null, "id": "91a8f4f4-c417-4db7-94ba-2d3404e5c2c9", "metadata": { - "execution": { - "iopub.execute_input": "2021-10-18T02:34:07.188682Z", - "iopub.status.busy": "2021-10-18T02:34:07.187761Z", - "iopub.status.idle": "2021-10-18T02:34:07.230533Z", - "shell.execute_reply": "2021-10-18T02:34:07.227725Z", - "shell.execute_reply.started": "2021-10-18T02:34:07.188577Z" - }, "tags": [] }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "ok!\n" - ] - } - ], + "outputs": [], "source": [ "import pymongo\n", "from bson.objectid import ObjectId\n", @@ -179,27 +164,12 @@ }, { "cell_type": "code", - "execution_count": 79, + "execution_count": null, "id": "82e1b982-3c88-4f01-ad94-49177c4a46f6", "metadata": { - "execution": { - "iopub.execute_input": "2021-10-18T02:36:32.491973Z", - "iopub.status.busy": "2021-10-18T02:36:32.491036Z", - "iopub.status.idle": "2021-10-18T02:36:34.395918Z", - "shell.execute_reply": "2021-10-18T02:36:34.393177Z", - "shell.execute_reply.started": "2021-10-18T02:36:32.491866Z" - }, "tags": [] }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n" - ] - } - ], + "outputs": [], "source": [ "import json\n", "import pymongo\n", @@ -245,12 +215,11 @@ " s = v['id_num']\n", " dict2['id_num'] = s\n", " dict2['birth'] = f'{s[6:10]}-{s[10:12]}-{s[12:14]}'\n", - " dict2.setdefault('exam',[])\n", - " dict3['code'] = 120\n", - " dict3['sn'] = k\n", - " dict3['result'] = res[k]\n", - " dict2['exam'].append(dict3)\n", - "\n", + " dict2.setdefault('exam',[])\n", + " dict3['code'] = 120\n", + " dict3['sn'] = k\n", + " dict3['result'] = res[k]\n", + " dict2['exam'].append(dict3)\n", " list1.append(dict2)\n", "x = mycol.insert_many(list1)\n", "mycol1 = mydb[\"event\"]\n", @@ -303,14 +272,6 @@ " " ] }, - { - "cell_type": "code", - "execution_count": null, - "id": "44149ba0-1730-43d4-b07f-82a53dca4ce4", - "metadata": {}, - "outputs": [], - "source": [] - }, { "cell_type": "markdown", "id": "2bb3cbdd-9fe1-4345-8c5a-53acb1a386de", @@ -321,29 +282,12 @@ }, { "cell_type": "code", - "execution_count": 75, + "execution_count": null, "id": "910c3fcd-121a-42c0-9465-ad79a5829239", "metadata": { - "execution": { - "iopub.execute_input": "2021-10-18T02:29:20.586805Z", - "iopub.status.busy": "2021-10-18T02:29:20.585860Z", - "iopub.status.idle": "2021-10-18T02:29:24.051120Z", - "shell.execute_reply": "2021-10-18T02:29:24.049117Z", - "shell.execute_reply.started": "2021-10-18T02:29:20.586699Z" - }, "tags": [] }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - "运动项目信息:\n", - "ok\n" - ] - } - ], + "outputs": [], "source": [ "import pymysql\n", "import json\n", @@ -542,10 +486,62 @@ "print(item['1'])" ] }, + { + "cell_type": "markdown", + "id": "c47e9547-d896-4fe2-8f70-8635c92fa792", + "metadata": {}, + "source": [ + "## 压缩体检报告" + ] + }, { "cell_type": "code", "execution_count": null, "id": "1ccab0f2-448b-4423-ae21-aa1c0f6470da", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "from pdf2image import convert_from_path, convert_from_bytes\n", + "import img2pdf \n", + "import glob\n", + "import os,sys\n", + "import tempfile\n", + "from pdf2image.exceptions import (\n", + " PDFInfoNotInstalledError,\n", + " PDFPageCountError,\n", + " PDFSyntaxError\n", + ")\n", + "#images = convert_from_path('1.pdf',dpi=200,fmt='jpg', output_folder='./sample_data')\n", + "fl_path = 'file/210924'\n", + "new_path ='file/new'\n", + "old = glob.glob(f'{fl_path}/*.pdf')\n", + "old.sort()\n", + "for old_file in old:\n", + " s = os.path.basename(old_file).split('.')[0].rjust(5,'0')\n", + " new_file = f'{new_path}/{s}.pdf'\n", + " \n", + " with tempfile.TemporaryDirectory() as path:\n", + " images_from_path = convert_from_path(old_file, dpi=100,fmt='jpg', output_folder=path)\n", + " fl=glob.glob(f'{path}/*.jpg')\n", + " fl.sort()\n", + " a4inpt = (img2pdf.mm_to_pt(210),img2pdf.mm_to_pt(297))\n", + " layout_fun = img2pdf.get_layout_fun(a4inpt)\n", + " with open(new_file,\"wb\") as f:\n", + " f.write(img2pdf.convert(fl,layout_fun=layout_fun))\n", + "\n", + "\n", + " #print(path)\n", + "\n", + " print(new_file,'ok')\n", + "#print(old)\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "5af86665-8abc-493d-a47f-fd9c53b8caea", "metadata": {}, "outputs": [], "source": []