Files
jupyter/体测单位/北京农行.ipynb
T
2023-06-08 17:10:42 +08:00

630 lines
21 KiB
Plaintext

{
"cells": [
{
"cell_type": "markdown",
"id": "ba2deee7-9c63-4115-bcee-ad341175fc02",
"metadata": {},
"source": [
"## 人员信息导入"
]
},
{
"cell_type": "code",
"execution_count": 52,
"id": "dea5e486-6927-469f-aa57-e5efac4670be",
"metadata": {
"execution": {
"iopub.execute_input": "2023-05-31T05:19:09.972334Z",
"iopub.status.busy": "2023-05-31T05:19:09.971473Z",
"iopub.status.idle": "2023-05-31T05:19:10.054344Z",
"shell.execute_reply": "2023-05-31T05:19:10.053621Z",
"shell.execute_reply.started": "2023-05-31T05:19:09.972292Z"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ok\n"
]
}
],
"source": [
"import openpyxl\n",
"import json\n",
"\n",
"\n",
"wb = openpyxl.load_workbook('data/农业银行测试名单.xlsx')\n",
"sheet = wb.active\n",
"# sheets = wb.sheetnames\n",
"person = {}\n",
"\n",
"for n in range(2, sheet.max_row+1):\n",
" if sheet.cell(n,1).value is not None:\n",
" code = int(sheet.cell(n, 2).value)\n",
" person.setdefault(code, {})\n",
" dict1 = {}\n",
" dict1['name'] = sheet.cell(n, 3).value\n",
" if sheet.cell(n, 4).value ==1:\n",
" sex = '男'\n",
" else:\n",
" sex = '女'\n",
" dict1['sex'] = sex\n",
" birth = str(sheet.cell(n, 5).value).split()[0]\n",
" dict1['birth'] = birth\n",
" dict1['unit'] = sheet.cell(n, 1).value\n",
" if sheet.cell(n,10).value is not None:\n",
" dict1['phone'] = sheet.cell(n, 10).value \n",
" person[code] = dict1\n",
"\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": "1c00e1e4-101a-4e9f-a7ed-9c65200d19df",
"metadata": {},
"source": [
"## 成绩导入"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "fd73b8be-d3fe-49aa-99d2-3cc6df4a3eb0",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"import json\n",
"import time\n",
"import csv\n",
"\n",
"filename = '../item.json'\n",
"item = {}\n",
"unit = {}\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl) \n",
"for k,v in dict1.items():\n",
" item[k] = v\n",
"re_ta = {}\n",
"dict1 = {}\n",
"list1 = []\n",
"filename = 'data/北京农行人员名单.json'\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl) \n",
"\n",
"filename = 'data/places_result_20230521.csv'\n",
"with open(filename,'r',newline='') as csv_file:\n",
" fl = csv.reader(csv_file,delimiter=',')\n",
" header = next(fl) \n",
" for line in fl:\n",
" #line = re.sub('[\\r\\n\\f ]{1,}', '', line)\n",
" list1.append(line)\n",
"#print(list1)\n",
"for result in list1:\n",
" user = str(result[2])\n",
" if user in dict1.keys(): \n",
" m_item = str(result[3]) \n",
" re_ta.setdefault(user,{}) \n",
" re_ta[user]['name'] = dict1[user]['name']\n",
" re_ta[user]['sex'] = dict1[user]['sex'] \n",
" re_ta[user]['unit'] = dict1[user]['unit']\n",
" item_name = item[m_item]['name']\n",
" re_ta[user].setdefault(item_name,{}) \n",
" score = int(result[4])/item[m_item]['divisor'] \n",
" re_ta[user][item_name]['成绩'] = f'{score} {item[m_item][\"unit\"]}'\n",
"print(len(re_ta))\n",
"filename = 'data/result_北京农行.json'\n",
"\n",
"with open(filename,'w') as fl:\n",
" json.dump(re_ta, fl, ensure_ascii=False) \n",
"print(len(re_ta))"
]
},
{
"cell_type": "markdown",
"id": "928790e6-d8a4-4b2b-852a-3c323380a80f",
"metadata": {},
"source": [
"## 成绩导出"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b870bd6e-f972-4073-b13d-5fda8cc92bb7",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"import json\n",
"import openpyxl\n",
"\n",
"items = ['身高','体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']\n",
"title = ['编号','姓名','性别','单位','身高','体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']\n",
"\n",
"filename = 'data/result_北京农行.json'\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl)\n",
"\n",
"filename = 'data/北京农行人员名单.json'\n",
"with open(filename,'r') as fl:\n",
" dict2 = json.load(fl)\n",
" \n",
"list1 = []\n",
"for k, v in dict1.items():\n",
" list2 = []\n",
" list2.append(str(k).rjust(5,'0'))\n",
" list2.append(v['name']) \n",
" list2.append(dict2[k]['sex'])\n",
" list2.append(dict2[k]['unit'])\n",
" for item in items:\n",
" if item in v.keys():\n",
" list2.append(v[item]['成绩']) \n",
" elif item =='name':\n",
" list2.append(v[item])\n",
" else:\n",
" list2.append('') \n",
" list1.append(list2)\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": "dd2034ca-fe8b-4322-b06d-8c5eaf96373d",
"metadata": {},
"source": [
"## 报告按部门分类更名"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "04967ec6-b9a0-4097-9e1f-8beaf8a9e75f",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"import os,sys,shutil\n",
"import json\n",
"import math\n",
"import glob\n",
"from pathlib import Path\n",
"\n",
"fi_path = 'file/2023-05-23'\n",
"old = []\n",
"dict2 = {}\n",
"\n",
"filename = 'data/result_北京农行.json'\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl)\n",
"\n",
"for k, v in dict1.items():\n",
" m_name = v['name']\n",
" m_depart = v['unit'] \n",
" dict2[int(k)] = [m_name,m_depart]\n",
"\n",
"fls = glob.glob(f'{fi_path}/*.pdf')\n",
"\n",
"for fn in fls:\n",
" old.append(os.path.basename(fn).split('.')[0])\n",
"\n",
"for n in old: \n",
" o_name = f'{fi_path}/{n}.pdf'\n",
" new_path = Path(fi_path,'new',dict1[n]['unit'])\n",
" new_path.mkdir(parents = True, exist_ok = True)\n",
" n_name = Path(new_path,f'{str(n).rjust(5,\"0\")}-{dict2[int(n)][0]}.pdf')\n",
" if not os.path.exists(n_name):\n",
" shutil.copyfile(o_name,n_name)\n",
" print(n_name)\n",
" \n",
"print('ok')"
]
},
{
"cell_type": "markdown",
"id": "515bc854-5745-4c38-8633-f56a078ea9a8",
"metadata": {
"execution": {
"iopub.execute_input": "2023-05-25T09:28:28.615647Z",
"iopub.status.busy": "2023-05-25T09:28:28.614774Z",
"iopub.status.idle": "2023-05-25T09:28:28.619865Z",
"shell.execute_reply": "2023-05-25T09:28:28.618821Z",
"shell.execute_reply.started": "2023-05-25T09:28:28.615607Z"
}
},
"source": [
"## 生成人员电话信息表"
]
},
{
"cell_type": "code",
"execution_count": 53,
"id": "c925d850-ff06-4be5-bf9f-31f4385c37c0",
"metadata": {
"execution": {
"iopub.execute_input": "2023-05-31T05:19:14.796522Z",
"iopub.status.busy": "2023-05-31T05:19:14.795763Z",
"iopub.status.idle": "2023-05-31T05:19:14.859923Z",
"shell.execute_reply": "2023-05-31T05:19:14.858869Z",
"shell.execute_reply.started": "2023-05-31T05:19:14.796492Z"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"163\n"
]
}
],
"source": [
"import json\n",
"import openpyxl\n",
"wb = openpyxl.load_workbook('data/农业银行测试手机号码统计表.xlsx')\n",
"sheet = wb.active\n",
"# sheets = wb.sheetnames\n",
"dict1 = {}\n",
"\n",
"for n in range(2, sheet.max_row+1):\n",
" if sheet.cell(n,5).value is not None:\n",
" phone = str(sheet.cell(n, 5).value)\n",
" dict1.setdefault(phone,{})\n",
" code = str(sheet.cell(n, 2).value)\n",
" unit = sheet.cell(n, 1).value\n",
" name = sheet.cell(n, 3).value\n",
" sex = sheet.cell(n, 4).value\n",
" dict1[phone]['code'] = code\n",
" dict1[phone]['name'] = name\n",
" #dict1[phone]['unit'] = unit\n",
" #dict1[phone]['sex'] = sex\n",
"filename = 'data/农业银行测试手机号码.json'\n",
"\n",
"with open(filename,'w') as fl:\n",
" json.dump(dict1, fl, ensure_ascii=False) \n",
"print(len(dict1))\n"
]
},
{
"cell_type": "markdown",
"id": "0f13e837-15d9-4dc6-b356-78b79bbb5b17",
"metadata": {},
"source": [
"## 生成验证码"
]
},
{
"cell_type": "code",
"execution_count": 54,
"id": "a87384c6-dc46-4d09-b757-b42462ed818d",
"metadata": {
"execution": {
"iopub.execute_input": "2023-05-31T05:19:18.950211Z",
"iopub.status.busy": "2023-05-31T05:19:18.949352Z",
"iopub.status.idle": "2023-05-31T05:19:18.965945Z",
"shell.execute_reply": "2023-05-31T05:19:18.964916Z",
"shell.execute_reply.started": "2023-05-31T05:19:18.950168Z"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"164\n",
"['659821', '079384', '876923', '387406', '694158', '563974', '628540', '281407', '798056', '274185', '705316', '571698', '693240', '650329', '481397', '610492', '250746', '619873', '675018', '619204', '984351', '279548', '027154', '856432', '296138', '290486', '218396', '973605', '269043', '653487', '528397', '031947', '370415', '872591', '018592', '251794', '718203', '869254', '408517', '071948', '536729', '259430', '867310', '285413', '805216', '405192', '630721', '386219', '504216', '418752', '402398', '231947', '850743', '901378', '394175', '431092', '157489', '961378', '305921', '620417', '352906', '629380', '417086', '086149', '804693', '342580', '310827', '637102', '128635', '346780', '325076', '643917', '710548', '046732', '762390', '350712', '368419', '342701', '245107', '087136', '023185', '759846', '346758', '514976', '570482', '781935', '210987', '340615', '075891', '810596', '430689', '920785', '815347', '917562', '295817', '765238', '058479', '674159', '567894', '109842', '851943', '703918', '073489', '403958', '578492', '798046', '502876', '943180', '498306', '835760', '726305', '490867', '709413', '275683', '256934', '721830', '973841', '729685', '021349', '265413', '321597', '064187', '136794', '708352', '710928', '657129', '962105', '905436', '513749', '257361', '420691', '941567', '839574', '906358', '218095', '364152', '562149', '109823', '560942', '293561', '194053', '509246', '026951', '243561', '093154', '654083', '519048', '459136', '914362', '605834', '508693', '823906', '349725', '572390', '541236', '419570', '513467', '724063', '164823', '890712', '529840', '641958', '678590', '648951']\n"
]
}
],
"source": [
"import random\n",
"import json\n",
"\n",
"code_list = []\n",
"for i in range(10): # 0~9\n",
" code_list.append(str(i))\n",
" \n",
"list1 = []\n",
"#print(code_num)\n",
"i = 1\n",
"while i < 165:\n",
" code = random.sample(code_list,6) #随机取6位数\n",
" code_num = ''.join(code)\n",
" if code_num not in list1:\n",
" list1.append(code_num)\n",
" i +=1\n",
"print(len(list1))\n",
"print(list1)\n",
"i = 0\n",
"filename = 'data/农业银行测试手机号码.json'\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl)\n",
"for k, v in dict1.items():\n",
" dict1[k]['yzm'] = list1[i]\n",
" i +=1\n",
"with open(filename,'w') as fl:\n",
" json.dump(dict1, fl, ensure_ascii=False) "
]
},
{
"cell_type": "markdown",
"id": "6efc1c2b-7af1-49ec-9b48-8930a8dd2801",
"metadata": {},
"source": [
"## 生成下载链接"
]
},
{
"cell_type": "code",
"execution_count": 55,
"id": "10845b90-48b4-4418-9dac-dd4a6f0147c0",
"metadata": {
"execution": {
"iopub.execute_input": "2023-05-31T05:19:22.535432Z",
"iopub.status.busy": "2023-05-31T05:19:22.534590Z",
"iopub.status.idle": "2023-05-31T05:19:22.546728Z",
"shell.execute_reply": "2023-05-31T05:19:22.545447Z",
"shell.execute_reply.started": "2023-05-31T05:19:22.535392Z"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"163\n"
]
}
],
"source": [
"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",
" dict2.setdefault(v['yzm'],{})\n",
" dict2[v['yzm']]['code'] = v['code']\n",
" dict2[v['yzm']]['name'] = v['name']\n",
"print(len(dict2))\n",
"filename = 'data/yzm.json'\n",
"with open(filename,'w') as fl:\n",
" json.dump(dict2, fl, ensure_ascii=False) \n"
]
},
{
"cell_type": "markdown",
"id": "fba0a0c4-edf2-45c2-9199-c6a86919f191",
"metadata": {},
"source": [
"## 发送短信"
]
},
{
"cell_type": "code",
"execution_count": 37,
"id": "62733f52-62c1-43aa-964a-232eab8b5251",
"metadata": {
"execution": {
"iopub.execute_input": "2023-05-25T10:18:47.776482Z",
"iopub.status.busy": "2023-05-25T10:18:47.776048Z",
"iopub.status.idle": "2023-05-25T10:18:48.066702Z",
"shell.execute_reply": "2023-05-25T10:18:48.065832Z",
"shell.execute_reply.started": "2023-05-25T10:18:47.776444Z"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{\n",
" \"SendStatusSet\": [\n",
" {\n",
" \"SerialNo\": \"2640:135690281916850099280618075\",\n",
" \"PhoneNumber\": \"+8613793180751\",\n",
" \"Fee\": 1,\n",
" \"SessionContext\": \"\",\n",
" \"Code\": \"Ok\",\n",
" \"Message\": \"send success\",\n",
" \"IsoCode\": \"CN\"\n",
" }\n",
" ],\n",
" \"RequestId\": \"7601194b-56e4-45a8-9543-6fcc76ce16a6\"\n",
"}\n"
]
}
],
"source": [
"from tencentcloud.common import credential\n",
"from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException\n",
"from tencentcloud.sms.v20210111 import sms_client, models\n",
"from tencentcloud.common.profile.client_profile import ClientProfile\n",
"from tencentcloud.common.profile.http_profile import HttpProfile\n",
"try: \n",
" secretId = \"AKID22rVyvSqbikXFFvav31ykc9YmqjN6KYc\"\n",
" secretKey = \"51XVL1YxDKI6mJh8au6DDuTskS1RhwJX\"\n",
" cred = credential.Credential(secretId, secretKey) \n",
" httpProfile = HttpProfile()\n",
" httpProfile.reqMethod = \"POST\" # post请求(默认为post请求)\n",
" httpProfile.reqTimeout = 30 # 请求超时时间,单位为秒(默认60秒)\n",
" httpProfile.endpoint = \"sms.tencentcloudapi.com\" # 指定接入地域域名(默认就近接入)\n",
" clientProfile = ClientProfile()\n",
" clientProfile.signMethod = \"TC3-HMAC-SHA256\" # 指定签名算法\n",
" clientProfile.language = \"en-US\"\n",
" clientProfile.httpProfile = httpProfile\n",
" client = sms_client.SmsClient(cred, \"ap-guangzhou\", clientProfile)\n",
" req = models.SendSmsRequest()\n",
" req.SmsSdkAppId = \"1400140089\"\n",
" req.SignName = \"坤铭教育\"\n",
" req.TemplateId = \"1808914\" \n",
" req.TemplateParamSet = [\"1234\"]\n",
" req.PhoneNumberSet = [\"+8613793180751\"]\n",
" req.SessionContext = \"\"\n",
" req.ExtendCode = \"\"\n",
" req.SenderId = \"\"\n",
" resp = client.SendSms(req)\n",
" print(resp.to_json_string(indent=2))\n",
"except TencentCloudSDKException as err:\n",
" print(err)"
]
},
{
"cell_type": "code",
"execution_count": 41,
"id": "e924a0a9-65a5-49c4-bdf2-b9152d278ad5",
"metadata": {
"execution": {
"iopub.execute_input": "2023-05-25T11:05:39.390622Z",
"iopub.status.busy": "2023-05-25T11:05:39.389793Z",
"iopub.status.idle": "2023-05-25T11:05:39.396312Z",
"shell.execute_reply": "2023-05-25T11:05:39.395239Z",
"shell.execute_reply.started": "2023-05-25T11:05:39.390580Z"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"send success\n"
]
}
],
"source": [
"dict1 = json.loads(resp.to_json_string(indent=2))\n",
"print(dict1['SendStatusSet'][0][\"Message\"])"
]
},
{
"cell_type": "markdown",
"id": "c55a8af0-4e4d-4bd4-b5b1-0a7d9170958c",
"metadata": {},
"source": [
"## 批量发送短信(测试)"
]
},
{
"cell_type": "code",
"execution_count": 57,
"id": "910d1881-d090-48dc-ac87-685ccaaf9553",
"metadata": {
"execution": {
"iopub.execute_input": "2023-06-07T02:57:09.482569Z",
"iopub.status.busy": "2023-06-07T02:57:09.481698Z",
"iopub.status.idle": "2023-06-07T02:57:10.568979Z",
"shell.execute_reply": "2023-06-07T02:57:10.567913Z",
"shell.execute_reply.started": "2023-06-07T02:57:09.482528Z"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"亓宇航 send success\n",
"李伟丽 send success\n",
"高松 send success\n",
"张树伟 send success\n"
]
}
],
"source": [
"\n",
"from tencentcloud.common import credential\n",
"from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException\n",
"from tencentcloud.sms.v20210111 import sms_client, models\n",
"from tencentcloud.common.profile.client_profile import ClientProfile\n",
"from tencentcloud.common.profile.http_profile import HttpProfile\n",
"import json\n",
"\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 = '+86'+str(k)\n",
" yzm = v['yzm']\n",
" try: \n",
" secretId = \"AKID22rVyvSqbikXFFvav31ykc9YmqjN6KYc\"\n",
" secretKey = \"51XVL1YxDKI6mJh8au6DDuTskS1RhwJX\"\n",
" cred = credential.Credential(secretId, secretKey) \n",
" httpProfile = HttpProfile()\n",
" httpProfile.reqMethod = \"POST\" # post请求(默认为post请求)\n",
" httpProfile.reqTimeout = 30 # 请求超时时间,单位为秒(默认60秒)\n",
" httpProfile.endpoint = \"sms.tencentcloudapi.com\" # 指定接入地域域名(默认就近接入)\n",
" clientProfile = ClientProfile()\n",
" clientProfile.signMethod = \"TC3-HMAC-SHA256\" # 指定签名算法\n",
" clientProfile.language = \"en-US\"\n",
" clientProfile.httpProfile = httpProfile\n",
" client = sms_client.SmsClient(cred, \"ap-guangzhou\", clientProfile)\n",
" req = models.SendSmsRequest()\n",
" req.SmsSdkAppId = \"1400140089\"\n",
" req.SignName = \"坤铭教育\"\n",
" req.TemplateId = \"1808914\" \n",
" req.TemplateParamSet = [yzm]\n",
" req.PhoneNumberSet = [phone]\n",
" req.SessionContext = \"\"\n",
" req.ExtendCode = \"\"\n",
" req.SenderId = \"\"\n",
" resp = client.SendSms(req)\n",
" dict2 = json.loads(resp.to_json_string(indent=2))\n",
"\n",
" print(v['name'],dict2['SendStatusSet'][0][\"Message\"])\n",
" except TencentCloudSDKException as err:\n",
" print(v['name'],err)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "759cad53-8745-4862-8874-cf35f13ab0b3",
"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.10.6"
}
},
"nbformat": 4,
"nbformat_minor": 5
}