{ "cells": [ { "cell_type": "markdown", "id": "4c41a2bd-7340-4a3b-9257-8d8615a20a09", "metadata": {}, "source": [ "## 体测人员导入" ] }, { "cell_type": "code", "execution_count": 7, "id": "eb9aa782-ce2c-4814-bdf6-92c7e892854d", "metadata": { "execution": { "iopub.execute_input": "2025-03-04T04:48:50.513279Z", "iopub.status.busy": "2025-03-04T04:48:50.512517Z", "iopub.status.idle": "2025-03-04T04:48:50.542095Z", "shell.execute_reply": "2025-03-04T04:48:50.541445Z", "shell.execute_reply.started": "2025-03-04T04:48:50.513207Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "49\n", "ok\n" ] } ], "source": [ "import openpyxl\n", "import json\n", "from datetime import date\n", "\n", "wb = openpyxl.load_workbook('data/海淀老干部局第一期.xlsx')\n", "sheet = wb.active\n", "# sheets = wb.sheetnames\n", "person = {}\n", "\n", "for n in range(3, sheet.max_row+1):\n", " code = int(sheet.cell(n, 1).value)\n", " person.setdefault(code, {})\n", " dict1 = {}\n", " dict1['name'] = sheet.cell(n, 2).value\n", " dict1['sex'] = sheet.cell(n, 3).value\n", " dict1['unit'] = '第一期'\n", " dict1['birth'] = str(sheet.cell(n, 4).value).replace('/','-').split(' ')[0]\n", " dict1['id'] = sheet.cell(n, 5).value\n", " if sheet.cell(n,6).value is not None:\n", " dict1['phone'] = str(sheet.cell(n,6).value) \n", " person[code] = dict1\n", "filename = 'data/海淀区老干部大学第一期.json'\n", "with open(filename, 'w') as fl:\n", " json.dump(person, fl, ensure_ascii=False)\n", "print(len(person))\n", "print('ok')" ] }, { "cell_type": "markdown", "id": "40f2c77d-1504-4288-9ed0-a0a4678579ee", "metadata": {}, "source": [ "## 生成读卡系统文件" ] }, { "cell_type": "code", "execution_count": 6, "id": "4e0de75e-6957-434a-9591-da96c21f4659", "metadata": { "execution": { "iopub.execute_input": "2025-03-03T07:21:43.877959Z", "iopub.status.busy": "2025-03-03T07:21:43.877156Z", "iopub.status.idle": "2025-03-03T07:21:43.888327Z", "shell.execute_reply": "2025-03-03T07:21:43.887102Z", "shell.execute_reply.started": "2025-03-03T07:21:43.877887Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "ok\n" ] } ], "source": [ "import json\n", "\n", "filename = 'data/海淀区老干部大学第一期.json'\n", "with open(filename,'r') as fl:\n", " dict1 = json.load(fl)\n", "list1 = []\n", "for k, v in dict1.items():\n", " dict2 = {}\n", " #if dict1['sex'] =='男':\n", " # sex = 1\n", " \n", " dict2 = {'id':k,'name':v['name'],'gender':v['sex'],'birth':v['birth'],'unit':v['unit']}\n", " list1.append(dict2)\n", "json_data = json.dumps(list1,ensure_ascii=False, indent=4) \n", "\n", "# 将 json 数据写入文件\n", "with open(\"data/card_海淀区老干部大学.json\", \"w\",encoding = 'utf-8') as file:\n", " file.write(json_data) \n", "print('ok')" ] }, { "cell_type": "code", "execution_count": null, "id": "26dbb945-2b62-4a46-9c72-aa321be7321d", "metadata": {}, "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.12.3" } }, "nbformat": 4, "nbformat_minor": 5 }