20220929
This commit is contained in:
1 parent
c037b1a44d
commit
d7b37d117d
1 file changed
+462
@@ -0,0 +1,462 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "e6a72068-83c7-45ff-a0d4-8ccd9abbc091",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## 人员信息导入"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "53b09d89-0cd6-4d84-b493-d47918664201",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### 人员基本信息导入"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "ce9b96fd-4bc1-4fd3-8339-5992a86c7001",
|
||||
"metadata": {
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import openpyxl\n",
|
||||
"import json\n",
|
||||
"\n",
|
||||
"wb = openpyxl.load_workbook('data/交警支队最新名册.xlsx')\n",
|
||||
"sheet = wb.active\n",
|
||||
"# sheets = wb.sheetnames\n",
|
||||
"person = {}\n",
|
||||
"for n in range(2, sheet.max_row+1):\n",
|
||||
" if sheet.cell(n,2).value is None:\n",
|
||||
" break\n",
|
||||
" else:\n",
|
||||
" \n",
|
||||
" code = int(sheet.cell(n, 4).value)\n",
|
||||
" person.setdefault(code, {})\n",
|
||||
" dict1 = {}\n",
|
||||
" dict1['name'] = sheet.cell(n, 6).value \n",
|
||||
" xb = str(sheet.cell(n, 7).value)\n",
|
||||
" if xb == '1':\n",
|
||||
" sex = '男'\n",
|
||||
" elif xb =='2':\n",
|
||||
" sex = '女'\n",
|
||||
" dict1['sex'] = sex\n",
|
||||
" dict1['unit'] = sheet.cell(n, 3).value\n",
|
||||
" dict1['birth'] = str(sheet.cell(n,8).value).split(' ')[0]\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('ok')"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "fa233427-c1ea-4005-a2bd-b2b9e94604d0",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### 人员手机号码导入"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "2fd5b96c-0bbd-4a8f-8d72-002445101c92",
|
||||
"metadata": {
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import openpyxl\n",
|
||||
"import json\n",
|
||||
"\n",
|
||||
"wb = openpyxl.load_workbook('data/排序-淄博交警支队人员名单 _56473.xlsx')\n",
|
||||
"sheet = wb.active\n",
|
||||
"# sheets = wb.sheetnames\n",
|
||||
"person = {}\n",
|
||||
"for n in range(3, sheet.max_row+1):\n",
|
||||
" if sheet.cell(n,2).value is None:\n",
|
||||
" break\n",
|
||||
" else:\n",
|
||||
" phone = sheet.cell(n, 5).value\n",
|
||||
" person.setdefault(phone, {})\n",
|
||||
" dict1 = {}\n",
|
||||
" dict1['name'] = sheet.cell(n, 2).value \n",
|
||||
" xb = str(sheet.cell(n, 3).value)\n",
|
||||
" if xb == '1':\n",
|
||||
" sex = '男'\n",
|
||||
" elif xb =='2':\n",
|
||||
" sex = '女'\n",
|
||||
" dict1['sex'] = sex\n",
|
||||
" dict1['unit'] = sheet.cell(n, 1).value\n",
|
||||
" dict1['birth'] = str(sheet.cell(n,4).value).split(' ')[0]\n",
|
||||
" person[phone] = dict1\n",
|
||||
"filename = 'data/交警支队手机号码.json'\n",
|
||||
"with open(filename, 'w') as fl:\n",
|
||||
" json.dump(person, fl, ensure_ascii=False)\n",
|
||||
"print('ok')"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "c61f18ab-7411-44d4-9741-3dd50283f4bb",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### 关联人员手机号码"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "73895efd-0d5e-4872-aca9-a697c3a0e774",
|
||||
"metadata": {
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import json\n",
|
||||
"\n",
|
||||
"filename = 'data/交警支队名单.json'\n",
|
||||
"with open(filename,'r') as fl:\n",
|
||||
" dict1 = json.load(fl) \n",
|
||||
"list2 = []\n",
|
||||
"filename = 'data/交警支队手机号码.json'\n",
|
||||
"with open(filename,'r') as fl:\n",
|
||||
" dict2 = json.load(fl)\n",
|
||||
"for k, v in dict2.items(): \n",
|
||||
" list1 = [k,v['name'],v['birth']]\n",
|
||||
" list2.append(list1)\n",
|
||||
"for k, v in dict1.items():\n",
|
||||
" name = v['name']\n",
|
||||
" unit = v['birth']\n",
|
||||
" for item in list2:\n",
|
||||
" if name in item and unit in item:\n",
|
||||
" dict1[k]['phone'] = item[0]\n",
|
||||
" \n",
|
||||
" break\n",
|
||||
"filename = 'data/交警支队名单1.json'\n",
|
||||
"with open(filename, 'w') as fl:\n",
|
||||
" json.dump(dict1, fl, ensure_ascii=False)\n",
|
||||
"print('ok') \n",
|
||||
" \n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "8136ea7b-d485-452d-b032-0cfa538166a9",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### 修正人员信息"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "5678472e-b131-4940-9161-240dcd3461bb",
|
||||
"metadata": {
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import openpyxl\n",
|
||||
"import json\n",
|
||||
"\n",
|
||||
"filename = 'data/小鹅通人员信息.json'\n",
|
||||
"with open(filename,'r') as fl:\n",
|
||||
" dict2 = json.load(fl) \n",
|
||||
"\n",
|
||||
"wb = openpyxl.load_workbook('data/交警支队小鹅通中手机信息存在问题用户(修正).xlsx')\n",
|
||||
"sheet = wb.active\n",
|
||||
"# sheets = wb.sheetnames\n",
|
||||
"\n",
|
||||
"for n in range(2, sheet.max_row+1):\n",
|
||||
" if sheet.cell(n,1).value is None:\n",
|
||||
" break\n",
|
||||
" else:\n",
|
||||
" phone = sheet.cell(n, 4).value\n",
|
||||
" dict2[sheet.cell(n, 1).value]['phone'] = phone\n",
|
||||
"\n",
|
||||
"with open(filename, 'w') as fl:\n",
|
||||
" json.dump(dict2, fl, ensure_ascii=False)\n",
|
||||
"print('ok')"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "e3a23383-e918-41c7-818e-6914ebfe7baf",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### 小鹅通人员信息关联"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "fc1da208-192e-4b06-b42f-72e7d44245ad",
|
||||
"metadata": {
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import json\n",
|
||||
"filename = 'data/交警支队名单1.json'\n",
|
||||
"with open(filename,'r') as fl:\n",
|
||||
" dict1 = json.load(fl) \n",
|
||||
"dict2 = {}\n",
|
||||
"for k, v in dict1.items():\n",
|
||||
" if 'phone' in v.keys():\n",
|
||||
" dict2.setdefault(v['phone'], {})\n",
|
||||
" dict2[v['phone']]['name'] = v['name']\n",
|
||||
" dict2[v['phone']]['sex'] = v['sex']\n",
|
||||
" dict2[v['phone']]['unit'] = v['unit']\n",
|
||||
" dict2[v['phone']]['birth'] = v['birth']\n",
|
||||
"#print(dict2) \n",
|
||||
"list1 = dict2.keys()\n",
|
||||
"filename = 'data/小鹅通人员信息.json'\n",
|
||||
"with open(filename,'r') as fl:\n",
|
||||
" dict1 = json.load(fl) \n",
|
||||
"for k, v in dict1.items():\n",
|
||||
" phone = v['phone']\n",
|
||||
" if phone in list1:\n",
|
||||
" dict2[phone]['nick'] = v['nick']\n",
|
||||
" dict2[phone]['user'] = v['name']\n",
|
||||
" dict2[phone]['id'] = k\n",
|
||||
"filename = 'data/交警支队小鹅通信息.json'\n",
|
||||
"with open(filename, 'w') as fl:\n",
|
||||
" json.dump(dict2, fl, ensure_ascii=False)\n",
|
||||
"print('ok') "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "775a298e-600d-4644-bd43-1eb75a302a9f",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### 导出无手机号码人员"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "aa15ff39-1527-4f08-9331-d64bd298c1c2",
|
||||
"metadata": {
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import json\n",
|
||||
"filename = 'data/交警支队名单1.json'\n",
|
||||
"with open(filename,'r') as fl:\n",
|
||||
" dict1 = json.load(fl) \n",
|
||||
"\n",
|
||||
"for k, v in dict1.items():\n",
|
||||
" if 'phone' not in v.keys():\n",
|
||||
" print(v['name'],v['unit'])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "f684616c-98f2-4f37-81c8-77ab5a7389fa",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### 小鹅通人员信息导入"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "e610a572-8699-4f35-a3db-de4c0b971686",
|
||||
"metadata": {
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import json\n",
|
||||
"import os\n",
|
||||
"import glob\n",
|
||||
"import csv\n",
|
||||
"\n",
|
||||
"fi_path = 'data/小鹅通/'\n",
|
||||
"dict1 = {}\n",
|
||||
"fl = glob.glob(f'{fi_path}*.csv')\n",
|
||||
"list1 = []\n",
|
||||
"for fn in fl:\n",
|
||||
" with open(fn,'r',newline='') as csv_file:\n",
|
||||
" fl1 = csv.reader(csv_file,delimiter=',')\n",
|
||||
" header = next(fl1) \n",
|
||||
" for line in fl1:\n",
|
||||
" #line = re.sub('[\\r\\n\\f ]{1,}', '', line)\n",
|
||||
" list1.append(line)\n",
|
||||
"for item in list1:\n",
|
||||
" dict1.setdefault(item[0],{})\n",
|
||||
" dict1[item[0]]['nick'] = item[1]\n",
|
||||
" dict1[item[0]]['name'] = item[4] \n",
|
||||
" dict1[item[0]]['phone'] = item[5] \n",
|
||||
"filename = 'data/小鹅通人员信息.json'\n",
|
||||
"with open(filename,'w') as fl:\n",
|
||||
" json.dump(dict1, fl,ensure_ascii=False) "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "dc856c16-3ff0-4c24-a5ee-062129698e08",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## 打卡信息导入"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 92,
|
||||
"id": "c1a5aaef-70be-4fd2-9384-983aeb59f491",
|
||||
"metadata": {
|
||||
"execution": {
|
||||
"iopub.execute_input": "2022-09-29T12:20:48.500293Z",
|
||||
"iopub.status.busy": "2022-09-29T12:20:48.499768Z",
|
||||
"iopub.status.idle": "2022-09-29T12:20:48.627177Z",
|
||||
"shell.execute_reply": "2022-09-29T12:20:48.626065Z",
|
||||
"shell.execute_reply.started": "2022-09-29T12:20:48.500245Z"
|
||||
},
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"['data/交警支队/时长/2022-09-29-《气虚组》-视频学习详情_085022.csv', 'data/交警支队/时长/2022-09-28-《阳虚组》-视频学习详情_162739.csv', 'data/交警支队/时长/2022-09-29-《阴虚组》-视频学习详情_084653.csv', 'data/交警支队/时长/2022-09-28-《气郁组》-视频学习详情_155229.csv', 'data/交警支队/时长/2022-09-29-《痰湿组》-视频学习详情_084809.csv', 'data/交警支队/时长/2022-09-28-《血瘀组》-视频学习详情_163202.csv', 'data/交警支队/时长/2022-09-28-《特禀组》-视频学习详情_162914.csv', 'data/交警支队/时长/2022-09-29-《平和组》-视频学习详情_085511.csv', 'data/交警支队/时长/2022-09-29-《湿热组》-视频学习详情_084926.csv']\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"import json\n",
|
||||
"import os\n",
|
||||
"import glob\n",
|
||||
"import csv\n",
|
||||
"import re\n",
|
||||
"\n",
|
||||
"filename = 'data/交警支队小鹅通信息.json'\n",
|
||||
"with open(filename,'r') as fl:\n",
|
||||
" dict1 = json.load(fl) \n",
|
||||
"dict2 = {}\n",
|
||||
"for k, v in dict1.items():\n",
|
||||
" if 'id' in v.keys():\n",
|
||||
" dict2[v['nick']] = [v['name'],v['unit'],k] \n",
|
||||
"dict3 = {} \n",
|
||||
"fi_path = 'data/交警支队/'\n",
|
||||
"fl = glob.glob(f'{fi_path}*.csv')\n",
|
||||
"list1 = []\n",
|
||||
"for fn in fl:\n",
|
||||
" with open(fn,'r',newline='',encoding='gbk') as csv_file:\n",
|
||||
" fl1 = csv.reader(csv_file,delimiter=',')\n",
|
||||
" #header = next(fl1)\n",
|
||||
" i = 0\n",
|
||||
" for line in fl1:\n",
|
||||
" #line = re.sub('[\\r\\n\\f ]{1,}', '', line)\n",
|
||||
" if i> 1:\n",
|
||||
" list1.append(line)\n",
|
||||
" i +=1\n",
|
||||
"for item in list1:\n",
|
||||
" name = item.pop(0)\n",
|
||||
" num = item.count('√')\n",
|
||||
" if name in dict2.keys():\n",
|
||||
" dict3.setdefault(name,{})\n",
|
||||
" dict3[name]['name'] = dict2[name][0]\n",
|
||||
" dict3[name]['phone'] = dict2[name][2]\n",
|
||||
" dict3[name]['unit'] = dict2[name][1]\n",
|
||||
" if 'dk' in dict3[name].keys():\n",
|
||||
" dict3[name]['dk'] = num + dict3[name]['dk']\n",
|
||||
" else:\n",
|
||||
" dict3[name]['dk'] = num\n",
|
||||
"fi_path = 'data/交警支队/时长/'\n",
|
||||
"fl = glob.glob(f'{fi_path}*.csv')\n",
|
||||
"print(fl)\n",
|
||||
"list1 = []\n",
|
||||
"for fn in fl:\n",
|
||||
" with open(fn,'r',newline='',encoding='gb18030') as csv_file:\n",
|
||||
" fl1 = csv.reader(csv_file,delimiter=',')\n",
|
||||
" #header = next(fl1)\n",
|
||||
" i = 0\n",
|
||||
" for line in fl1:\n",
|
||||
" #line = re.sub('[\\r\\n\\f ]{1,}', '', line)\n",
|
||||
" if i> 1:\n",
|
||||
" list1.append(line)\n",
|
||||
" i +=1\n",
|
||||
"for item in list1:\n",
|
||||
" name = item[1]\n",
|
||||
" num = item[2].strip()\n",
|
||||
" if name in dict2.keys():\n",
|
||||
" dict3.setdefault(name,{})\n",
|
||||
" dict3[name]['name'] = dict2[name][0]\n",
|
||||
" dict3[name]['phone'] = dict2[name][2]\n",
|
||||
" dict3[name]['unit'] = dict2[name][1]\n",
|
||||
" dict3[name]['sc'] = num \n",
|
||||
"list1 = []\n",
|
||||
"for k, v in dict3.items():\n",
|
||||
" list2 = []\n",
|
||||
" if 'dk' in v.keys():\n",
|
||||
" dk = v['dk']\n",
|
||||
" else:\n",
|
||||
" dk = 0\n",
|
||||
" if 'sc' in v.keys():\n",
|
||||
" sc = v['sc']\n",
|
||||
" else:\n",
|
||||
" sc = ''\n",
|
||||
" list2 = [k,v['name'],v['phone'],v['unit'],dk,sc]\n",
|
||||
" list1.append(list2)\n",
|
||||
"title = ['昵称','姓名','手机号','部门','打卡次数','累计学习时长']\n",
|
||||
"filename = 'data/交警支队学习情况表.xlsx'\n",
|
||||
"wb = openpyxl.Workbook()\n",
|
||||
"sheet = wb.active\n",
|
||||
"sheet.append(title)\n",
|
||||
"for row in list1:\n",
|
||||
" sheet.append(row)\n",
|
||||
" \n",
|
||||
"wb.save(filename) "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "74e41826-7247-4a5a-99c7-db067dfd6d93",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## 学习时长信息导入"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "765cb3e6-d8ab-4aea-9fb3-9008001b9767",
|
||||
"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.8.10"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
||||
Reference in new issue
Block a user