Files
jupyter/体测单位/北京农行.ipynb
T
2023-05-25 19:17:38 +08:00

19 KiB

人员信息导入

In [ ]:
import openpyxl
import json


wb = openpyxl.load_workbook('data/农业银行测试名单.xlsx')
sheet = wb.active
# sheets = wb.sheetnames
person = {}

for n in range(2, sheet.max_row+1):
    if sheet.cell(n,1).value is not None:
        code = int(sheet.cell(n, 2).value)
        person.setdefault(code, {})
        dict1 = {}
        dict1['name'] = sheet.cell(n, 3).value
        if sheet.cell(n, 4).value ==1:
            sex = '男'
        else:
            sex = '女'
        dict1['sex'] = sex
        birth = str(sheet.cell(n, 5).value).split()[0]
        dict1['birth'] = birth
        dict1['unit'] = sheet.cell(n, 1).value
        if sheet.cell(n,10).value is not None:
            dict1['phone'] = sheet.cell(n, 10).value        
        person[code] = dict1

filename = 'data/北京农行人员名单.json'
with open(filename, 'w') as fl:
    json.dump(person, fl, ensure_ascii=False)
print('ok')

成绩导入

In [ ]:
import json
import time
import csv

filename = '../item.json'
item = {}
unit = {}
with open(filename,'r') as fl:
    dict1 = json.load(fl) 
for k,v in dict1.items():
    item[k] = v
re_ta = {}
dict1 = {}
list1 = []
filename = 'data/北京农行人员名单.json'
with open(filename,'r') as fl:
    dict1 = json.load(fl) 

filename = 'data/places_result_20230521.csv'
with open(filename,'r',newline='') as csv_file:
    fl = csv.reader(csv_file,delimiter=',')
    header = next(fl)    
    for line in fl:
        #line = re.sub('[\r\n\f ]{1,}', '', line)
        list1.append(line)
#print(list1)
for result in list1:
    user = str(result[2])
    if user in dict1.keys():        
        m_item = str(result[3])    
        re_ta.setdefault(user,{})    
        re_ta[user]['name'] = dict1[user]['name']
        re_ta[user]['sex'] = dict1[user]['sex'] 
        re_ta[user]['unit'] = dict1[user]['unit']
        item_name = item[m_item]['name']
        re_ta[user].setdefault(item_name,{})  
        score = int(result[4])/item[m_item]['divisor']    
        re_ta[user][item_name]['成绩'] = f'{score} {item[m_item]["unit"]}'
print(len(re_ta))
filename = 'data/result_北京农行.json'

with open(filename,'w') as fl:
    json.dump(re_ta, fl, ensure_ascii=False) 
print(len(re_ta))

成绩导出

In [ ]:
import json
import openpyxl

items = ['身高','体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']
title = ['编号','姓名','性别','单位','身高','体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']

filename = 'data/result_北京农行.json'
with open(filename,'r') as fl:
    dict1 = json.load(fl)

filename = 'data/北京农行人员名单.json'
with open(filename,'r') as fl:
    dict2 = json.load(fl)
    
list1 = []
for k, v in dict1.items():
    list2 = []
    list2.append(str(k).rjust(5,'0'))
    list2.append(v['name'])    
    list2.append(dict2[k]['sex'])
    list2.append(dict2[k]['unit'])
    for item in items:
        if item in v.keys():
            list2.append(v[item]['成绩'])            
        elif item =='name':
            list2.append(v[item])
        else:
            list2.append('') 
    list1.append(list2)
filename = 'data/北京农行体测情况.xlsx'
wb = openpyxl.Workbook()
sheet = wb.active
sheet.append(title)
for row in list1:
    sheet.append(row)
    
wb.save(filename)

报告按部门分类更名

In [ ]:
import os,sys,shutil
import json
import math
import glob
from pathlib import Path

fi_path = 'file/2023-05-23'
old = []
dict2 = {}

filename = 'data/result_北京农行.json'
with open(filename,'r') as fl:
    dict1 = json.load(fl)

for k, v in dict1.items():
    m_name = v['name']
    m_depart = v['unit']    
    dict2[int(k)] = [m_name,m_depart]

fls = glob.glob(f'{fi_path}/*.pdf')

for fn in fls:
    old.append(os.path.basename(fn).split('.')[0])

for n in old:    
    o_name = f'{fi_path}/{n}.pdf'
    new_path = Path(fi_path,'new',dict1[n]['unit'])
    new_path.mkdir(parents = True, exist_ok = True)
    n_name = Path(new_path,f'{str(n).rjust(5,"0")}-{dict2[int(n)][0]}.pdf')
    if not os.path.exists(n_name):
        shutil.copyfile(o_name,n_name)
        print(n_name)
    
print('ok')

生成人员电话信息表

In [26]:
import json
import openpyxl
wb = openpyxl.load_workbook('data/农业银行测试手机号码统计表.xlsx')
sheet = wb.active
# sheets = wb.sheetnames
dict1 = {}

for n in range(2, sheet.max_row+1):
    if sheet.cell(n,5).value is not None:
        phone = str(sheet.cell(n, 5).value)
        dict1.setdefault(phone,{})
        code = str(sheet.cell(n, 2).value)
        unit = sheet.cell(n, 1).value
        name = sheet.cell(n, 3).value
        sex = sheet.cell(n, 4).value
        dict1[phone]['code'] = code
        dict1[phone]['name'] = name
        #dict1[phone]['unit'] = unit
        #dict1[phone]['sex'] = sex
filename = 'data/农业银行测试手机号码.json'

with open(filename,'w') as fl:
    json.dump(dict1, fl, ensure_ascii=False) 
print(len(dict1))
162

生成验证码

In [35]:
import random
import json

code_list = []
for i in range(10):   # 0~9
    code_list.append(str(i))
    
list1 = []
#print(code_num)
i = 1
while i < 163:
    code = random.sample(code_list,4)   #随机取6位数
    code_num = ''.join(code)
    if code_num not in list1:
        list1.append(code_num)
        i +=1
print(len(list1))
print(list1)
i = 0
filename = 'data/农业银行测试手机号码.json'
with open(filename,'r') as fl:
    dict1 = json.load(fl)
for k, v in dict1.items():
    dict1[k]['yzm'] = list1[i]
    i +=1
with open(filename,'w') as fl:
    json.dump(dict1, fl, ensure_ascii=False)     
162
['6085', '5304', '3071', '8954', '4051', '2348', '7629', '3607', '2095', '8107', '7905', '2791', '8460', '5096', '4062', '1978', '0976', '8492', '0197', '0287', '3764', '6589', '5439', '5607', '0541', '8629', '3275', '7620', '4795', '3025', '5862', '5410', '1438', '2408', '2167', '1094', '4026', '3184', '9104', '7694', '1862', '7286', '6170', '6578', '6587', '5179', '2043', '4813', '2597', '3207', '6859', '8920', '1268', '4860', '9627', '2918', '3841', '4193', '9281', '7961', '3510', '6912', '4921', '7520', '8930', '8271', '2163', '3457', '8713', '1962', '7480', '4138', '2504', '7490', '7285', '4029', '2496', '4920', '3572', '9305', '7512', '6324', '5731', '4719', '6895', '4591', '0679', '5287', '3817', '4063', '2108', '9153', '2401', '2897', '6782', '3875', '8014', '4753', '2146', '2483', '5012', '5803', '9425', '3578', '5628', '9245', '4835', '7052', '8654', '3586', '1693', '3086', '7609', '3021', '1794', '2865', '1739', '7435', '4135', '5240', '0374', '6583', '0856', '0812', '5837', '7106', '0268', '8376', '5346', '0753', '4158', '1756', '2473', '6139', '3178', '7824', '3201', '6304', '6109', '0735', '8573', '9857', '3240', '5340', '0438', '7415', '2783', '3127', '5497', '8542', '9764', '6107', '9016', '0248', '2195', '5149', '7982', '4750', '4023', '9684', '0823', '0692']

发送短信

In [37]:
from tencentcloud.common import credential
from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException
from tencentcloud.sms.v20210111 import sms_client, models

# 导入可选配置类
from tencentcloud.common.profile.client_profile import ClientProfile
from tencentcloud.common.profile.http_profile import HttpProfile
try:    
    secretId = "AKID22rVyvSqbikXFFvav31ykc9YmqjN6KYc"
    secretKey = "51XVL1YxDKI6mJh8au6DDuTskS1RhwJX"
    cred = credential.Credential(secretId, secretKey)
    

    # 实例化一个http选项,可选的,没有特殊需求可以跳过。
    httpProfile = HttpProfile()
    # 如果需要指定proxy访问接口,可以按照如下方式初始化hp(无需要直接忽略)
    # httpProfile = HttpProfile(proxy="http://用户名:密码@代理IP:代理端口")
    httpProfile.reqMethod = "POST"  # post请求(默认为post请求)
    httpProfile.reqTimeout = 30    # 请求超时时间,单位为秒(默认60秒)
    httpProfile.endpoint = "sms.tencentcloudapi.com"  # 指定接入地域域名(默认就近接入)

    # 非必要步骤:
    # 实例化一个客户端配置对象,可以指定超时时间等配置
    clientProfile = ClientProfile()
    clientProfile.signMethod = "TC3-HMAC-SHA256"  # 指定签名算法
    clientProfile.language = "en-US"
    clientProfile.httpProfile = httpProfile

    # 实例化要请求产品(以sms为例)的client对象
    # 第二个参数是地域信息,可以直接填写字符串ap-guangzhou,支持的地域列表参考 https://cloud.tencent.com/document/api/382/52071#.E5.9C.B0.E5.9F.9F.E5.88.97.E8.A1.A8
    client = sms_client.SmsClient(cred, "ap-guangzhou", clientProfile)
    req = models.SendSmsRequest()

    
    # 短信应用ID: 短信SdkAppId在 [短信控制台] 添加应用后生成的实际SdkAppId,示例如1400006666
    # 应用 ID 可前往 [短信控制台](https://console.cloud.tencent.com/smsv2/app-manage) 查看
    req.SmsSdkAppId = "1400140089"
    # 短信签名内容: 使用 UTF-8 编码,必须填写已审核通过的签名
    # 签名信息可前往 [国内短信](https://console.cloud.tencent.com/smsv2/csms-sign) 或 [国际/港澳台短信](https://console.cloud.tencent.com/smsv2/isms-sign) 的签名管理查看
    req.SignName = "坤铭教育"
    # 模板 ID: 必须填写已审核通过的模板 ID
    # 模板 ID 可前往 [国内短信](https://console.cloud.tencent.com/smsv2/csms-template) 或 [国际/港澳台短信](https://console.cloud.tencent.com/smsv2/isms-template) 的正文模板管理查看
    req.TemplateId = "1808914"
    # 模板参数: 模板参数的个数需要与 TemplateId 对应模板的变量个数保持一致,,若无模板参数,则设置为空
    req.TemplateParamSet = ["1234"]
    # 下发手机号码,采用 E.164 标准,+[国家或地区码][手机号]
    # 示例如:+8613711112222, 其中前面有一个+号 ,86为国家码,13711112222为手机号,最多不要超过200个手机号
    req.PhoneNumberSet = ["+8613793180751"]
    # 用户的 session 内容(无需要可忽略): 可以携带用户侧 ID 等上下文信息,server 会原样返回
    req.SessionContext = ""
    # 短信码号扩展号(无需要可忽略): 默认未开通,如需开通请联系 [腾讯云短信小助手]
    req.ExtendCode = ""
    # 国内短信无需填写该项;国际/港澳台短信已申请独立 SenderId 需要填写该字段,默认使用公共 SenderId,无需填写该字段。注:月度使用量达到指定量级可申请独立 SenderId 使用,详情请联系 [腾讯云短信小助手](https://cloud.tencent.com/document/product/382/3773#.E6.8A.80.E6.9C.AF.E4.BA.A4.E6.B5.81)。
    req.SenderId = ""

    resp = client.SendSms(req)

    # 输出json格式的字符串回包
    print(resp.to_json_string(indent=2))

except TencentCloudSDKException as err:
    print(err)
{
  "SendStatusSet": [
    {
      "SerialNo": "2640:135690281916850099280618075",
      "PhoneNumber": "+8613793180751",
      "Fee": 1,
      "SessionContext": "",
      "Code": "Ok",
      "Message": "send success",
      "IsoCode": "CN"
    }
  ],
  "RequestId": "7601194b-56e4-45a8-9543-6fcc76ce16a6"
}
In [41]:
dict1 = json.loads(resp.to_json_string(indent=2))
print(dict1['SendStatusSet'][0]["Message"])
send success
In [ ]: