Files
jupyter/体测单位/体测数据管理.ipynb
T
2024-12-24 22:56:49 +08:00

28 KiB

新增体测单位

In [1]:
import pymongo

myclient = pymongo.MongoClient('mongodb://localhost:27017/')
mydb = myclient["baogao"]
mycol = mydb["place"]

place_id = 141002
place_code = "15"
dw_name =  "北体体质康健班"
dw_jc = "北体体质康健班"
myquery = { "id": place_id }
num = mycol.count_documents(myquery)
if num>0:
    print(num)
else:
    mydict = { "id":place_id,"name": dw_name, "code": place_code }
    x = mycol.insert_one(mydict) 

生成手机验证码

In [3]:
import openpyxl
import os,sys,shutil
import json
import math
import glob
import random
from pathlib import Path
import pymongo

myclient = pymongo.MongoClient('mongodb://localhost:27017/')
mydb = myclient["baogao"]

place_id = 141002
place_code = "15"
dw_name =  "北体体质康健班"
dw_jc = "北体体质康健班"
fi_path = '/home/songyi/python/mycrm/flask/pdf/files'
fls = glob.glob(f'{fi_path}/{str(place_id)}/*.pdf')

code_list = []
for i in range(10):   # 0~9
    code_list.append(str(i))
list1 = []
mycol = mydb["pdf"]
query1 = { "place_id": place_id }
list2 = []
mydoc = mycol.find(query1,{ "code": 1, "_id": 0 })

for x in mydoc:
    list2.append(x['code'])

i = 0
while i < len(fls):
    code = random.sample(code_list,4)   #随机取3位数
    code_num = ''.join(code)    
    if place_code+code_num not in list1 and place_code+code_num not in list2:
        list1.append(place_code+code_num)
        i +=1
i = 0
list2= []
for fn in fls:
    dict2 = {}
    fi_name =Path(fn).stem.split('-')[0]
    #fi_name =Path(fn).stem
    code = int(fi_name)
    dxm = list1[i]
    dict2 = {'place_id':place_id,'code':dxm,'fn':Path(fn).name}
    list2.append(dict2)
    i +=1
x = mycol.insert_many(list2)
print(len(list2),'ok') 
71 ok

批量发送短信(测试)

In [6]:
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
import json
import pymongo
import time

myclient = pymongo.MongoClient('mongodb://localhost:27017/')
mydb = myclient["baogao"]
mycol = mydb["pdf"]

dw_jc = "北体体质康健班学员"
filename = 'data/北体体质康健班202412.json'
with open(filename,'r') as fl:
    dict1 = json.load(fl) 
dict2 = {}
#place_id = 571315
myquery = { "place_id": place_id}
for x in mycol.find(myquery,{ "_id": 0, "place_id": 0}):
    code = int(x['fn'].split('-')[0])
    if str(code) in dict1.keys() and 'phone' in dict1[str(code)].keys():
        dict2[code] = {'phone':str(dict1[str(code)]['phone']),'code':x['code'],'name':x['fn']}
    else:
        print(code,'no phone')
#print(dict2)
i=1
#dict2 = {375: {'phone': '13793180751', 'code': '0379208'}}
for k, v in dict2.items():
    phone = '+86'+v['phone']
    yzm = v['code']
    try:    
        secretId = "AKID22rVyvSqbikXFFvav31ykc9YmqjN6KYc"
        secretKey = "51XVL1YxDKI6mJh8au6DDuTskS1RhwJX"
        cred = credential.Credential(secretId, secretKey) 
        httpProfile = HttpProfile()
        httpProfile.reqMethod = "POST"  # post请求(默认为post请求)
        httpProfile.reqTimeout = 60    # 请求超时时间,单位为秒(默认60秒)
        httpProfile.endpoint = "sms.tencentcloudapi.com"  # 指定接入地域域名(默认就近接入)
        clientProfile = ClientProfile()
        clientProfile.signMethod = "TC3-HMAC-SHA256"  # 指定签名算法
        clientProfile.language = "en-US"
        clientProfile.httpProfile = httpProfile
        client = sms_client.SmsClient(cred, "ap-guangzhou", clientProfile)
        req = models.SendSmsRequest()
        req.SmsSdkAppId = "1400140089"
        req.SignName = "坤铭教育"
        req.TemplateId = "1875765"    
        req.TemplateParamSet = [dw_jc,yzm]
        req.PhoneNumberSet = [phone]
        req.SessionContext = ""
        req.ExtendCode = ""
        req.SenderId = ""
        #resp = client.SendSms(req)
        #dict3 = json.loads(resp.to_json_string(indent=2))

        #print(v['phone'],dict3['SendStatusSet'][0]["Message"])
        print(i,v['phone'],v['name'], v['code'])
        i+=1
    except TencentCloudSDKException as err:
        print(v['phone'],err)
1 15552778879 87-韩秋春.pdf 157481
2 13176607576 40-聂秋香.pdf 150269
3 13515466253 20-成桂艳.pdf 154130
4 13356838977 45-齐立红.pdf 159017
5 15505463267 6-刘来珍.pdf 151957
6 15618032716 72-林娟.pdf 153582
7 13001564985 23-李慧珠.pdf 153760
8 13854609739 85-连海燕.pdf 156827
9 13605461196 50-刘瑛.pdf 159238
10 13697833655 48-刘其英.pdf 157409
11 18654608681 68-张桂芝.pdf 157534
12 13561099637 9-吕建国.pdf 157281
13 13589970661 30-王争华.pdf 151934
14 15666215813 5-刘晓红.pdf 152476
15 15954638716 41-胡桂凤.pdf 153278
16 13793983616 80-董希娥.pdf 150362
17 18661395568 56-娄金华.pdf 153028
18 15006966879 38-耿宏勋.pdf 154872
19 13006548397 15-宋立君.pdf 155673
20 13054610560 88-马国丽.pdf 153905
21 13864711691 11-吴晓燕.pdf 156580
22 13013569039 39-耿红霞.pdf 155263
23 13356615748 17-张桂荣.pdf 150152
24 13589961337 35-王霞.pdf 152574
25 13678611392 34-王金美.pdf 152549
26 13963356165 31-王春爱.pdf 156502
27 13589986778 26-杨素华.pdf 158590
28 13361512362 77-秦春霞.pdf 154059
29 13054658622 86-郗桂红.pdf 157145
30 18661378656 54-周春萍.pdf 154763
31 15154636366 25-李红霞.pdf 156873
32 18654698789 37-罗秀艳.pdf 150825
33 13054652092 8-卢霞.pdf 159367
34 15610063229 7-刘英.pdf 159386
35 13963359769 1-万秀香.pdf 156540
36 18554659267 47-任大华.pdf 156039
37 18661376637 18-张秀玉.pdf 157206
38 18611391991 71-朱兰生.pdf 153617
39 13563399566 67-张伟.pdf 158436
40 15263888916 36-生月华.pdf 150476
41 13210319979 33-王海燕.pdf 155632
42 13561020118 84-赵立静.pdf 156825
43 13371503039 53-吕鸿义.pdf 159602
44 13864791829 75-王翠云.pdf 151079
45 18705469686 42-范晓英.pdf 157035
46 13706366656 57-孙家祥.pdf 153718
47 18554718350 63-宋秀娟.pdf 152087
48 13792060709 76-盖荣.pdf 153519
49 18860629985 46-于瑞先.pdf 154058
50 15314347726 55-姜英.pdf 151762
51 13854650187 32-王毅.pdf 159436
52 15020597108 78-程茂霞.pdf 153264
53 15606470366 73-温建华.pdf 155470
54 13945664258 49-刘桂君.pdf 150794
55 18554660557 65-巴建云.pdf 154836
56 15105468997 14-宋清贤.pdf 151746
57 13963370053 16-张德芳.pdf 158790
58 13864707888 60-宁振莹.pdf 151487
59 13906472659 64-尚国勋.pdf 150875
60 13963350118 12-唐慧芳.pdf 152738
61 13356645705 29-牛春芳.pdf 153915
62 13054625519 89-黄启江.pdf 150912
63 15666210207 81-袁庆敏.pdf 157248
64 15954620216 44-雒云秀.pdf 156738
65 13562277856 22-朱振峰.pdf 155413
66 13181996942 70-曹玉英.pdf 151820
67 18653699788 27-林乐武.pdf 151893
68 13589432668 83-赵福珍.pdf 156124
69 13563376888 3-伊茂胜.pdf 156285
70 13375466356 13-孟凡业.pdf 150571
71 13854664965 4-刘学农.pdf 151763

批量发送短信

In [7]:
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
import json
import pymongo
import time

myclient = pymongo.MongoClient('mongodb://localhost:27017/')
mydb = myclient["baogao"]
mycol = mydb["pdf"]

dw_jc = "北体体质康健班学员"
filename = 'data/北体体质康健班202412.json'
with open(filename,'r') as fl:
    dict1 = json.load(fl) 
dict2 = {}
place_id = 141002
myquery = { "place_id": place_id }
for x in mycol.find(myquery,{ "_id": 0, "place_id": 0}):
    code = int(x['fn'].split('-')[0])
    if str(code) in dict1.keys() and 'phone' in dict1[str(code)].keys():
        dict2[code] = {'phone':str(dict1[str(code)]['phone']),'code':x['code'],'name':x['fn']}
    else:
        print('no phone')
#print(dict2)
#dw_jc = "北体体质康健班测试者"
#dict2 = {375: {'phone': '13793180751', 'code': '0379208'}}
for k, v in dict2.items():
    phone = '+86'+v['phone']
    yzm = v['code']
    try:    
        secretId = "AKID22rVyvSqbikXFFvav31ykc9YmqjN6KYc"
        secretKey = "51XVL1YxDKI6mJh8au6DDuTskS1RhwJX"
        cred = credential.Credential(secretId, secretKey) 
        httpProfile = HttpProfile()
        httpProfile.reqMethod = "POST"  # post请求(默认为post请求)
        httpProfile.reqTimeout = 60    # 请求超时时间,单位为秒(默认60秒)
        httpProfile.endpoint = "sms.tencentcloudapi.com"  # 指定接入地域域名(默认就近接入)
        clientProfile = ClientProfile()
        clientProfile.signMethod = "TC3-HMAC-SHA256"  # 指定签名算法
        clientProfile.language = "en-US"
        clientProfile.httpProfile = httpProfile
        client = sms_client.SmsClient(cred, "ap-guangzhou", clientProfile)
        req = models.SendSmsRequest()
        req.SmsSdkAppId = "1400140089"
        req.SignName = "坤铭教育"
        req.TemplateId = "1875765"    
        req.TemplateParamSet = [dw_jc,yzm]
        req.PhoneNumberSet = [phone]
        req.SessionContext = ""
        req.ExtendCode = ""
        req.SenderId = ""
        resp = client.SendSms(req)
        dict3 = json.loads(resp.to_json_string(indent=2))
        print(v['phone'], v['code'],dict3['SendStatusSet'][0]["Message"])
        time.sleep(15)
    except TencentCloudSDKException as err:
        print(v['phone'],err)
15552778879 157481 send success
13176607576 150269 send success
13515466253 154130 send success
13356838977 159017 send success
15505463267 151957 send success
15618032716 153582 send success
13001564985 153760 send success
13854609739 156827 send success
13605461196 159238 send success
13697833655 157409 send success
18654608681 157534 send success
13561099637 157281 send success
13589970661 151934 send success
15666215813 152476 send success
15954638716 153278 send success
13793983616 150362 send success
18661395568 153028 send success
15006966879 154872 send success
13006548397 155673 send success
13054610560 153905 send success
13864711691 156580 send success
13013569039 155263 send success
13356615748 150152 send success
13589961337 152574 send success
13678611392 152549 send success
13963356165 156502 send success
13589986778 158590 send success
13361512362 154059 send success
13054658622 157145 send success
18661378656 154763 send success
15154636366 156873 send success
18654698789 150825 send success
13054652092 159367 send success
15610063229 159386 send success
13963359769 156540 send success
18554659267 156039 send success
18661376637 157206 send success
18611391991 153617 send success
13563399566 158436 send success
15263888916 150476 send success
13210319979 155632 send success
13561020118 156825 send success
13371503039 159602 send success
13864791829 151079 send success
18705469686 157035 send success
13706366656 153718 send success
18554718350 152087 send success
13792060709 153519 send success
18860629985 154058 send success
15314347726 151762 send success
13854650187 159436 send success
15020597108 153264 send success
15606470366 155470 send success
13945664258 150794 send success
18554660557 154836 send success
15105468997 151746 send success
13963370053 158790 send success
13864707888 151487 send success
13906472659 150875 send success
13963350118 152738 send success
13356645705 153915 send success
13054625519 150912 send success
15666210207 157248 send success
15954620216 156738 send success
13562277856 155413 send success
13181996942 151820 send success
18653699788 151893 send success
13589432668 156124 send success
13563376888 156285 send success
13375466356 150571 send success
13854664965 151763 send success
In [ ]:
dict1 = json.loads(resp.to_json_string(indent=2))
print(dict1['SendStatusSet'][0]["Message"])

单个发送短信

In [5]:
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
import json
import pymongo

myclient = pymongo.MongoClient('mongodb://localhost:27017/')
mydb = myclient["baogao"]
mycol = mydb["pdf"]

dw_jc = "北体体质康健班学员"
filename = 'data/北体体质康健班202412.json'
with open(filename,'r') as fl:
    dict1 = json.load(fl) 
dict2 = {}
place_id = 141002
myquery = { "place_id": place_id }
for x in mycol.find(myquery,{ "_id": 0, "place_id": 0}):
    code = int(x['fn'].split('-')[0])
    if str(code) in dict1.keys() and 'phone' in dict1[str(code)].keys():
        dict2[code] = {'phone':str(dict1[str(code)]['phone']),'code':x['code'],'name':x['fn']}
    else:
        print('no phone')

phone = '+86'+'13793180751'
yzm = '155673'
try:    
    secretId = "AKID22rVyvSqbikXFFvav31ykc9YmqjN6KYc"
    secretKey = "51XVL1YxDKI6mJh8au6DDuTskS1RhwJX"
    cred = credential.Credential(secretId, secretKey) 
    httpProfile = HttpProfile()
    httpProfile.reqMethod = "POST"  # post请求(默认为post请求)
    httpProfile.reqTimeout = 60    # 请求超时时间,单位为秒(默认60秒)
    httpProfile.endpoint = "sms.tencentcloudapi.com"  # 指定接入地域域名(默认就近接入)
    clientProfile = ClientProfile()
    clientProfile.signMethod = "TC3-HMAC-SHA256"  # 指定签名算法
    clientProfile.language = "en-US"
    clientProfile.httpProfile = httpProfile
    client = sms_client.SmsClient(cred, "ap-guangzhou", clientProfile)
    req = models.SendSmsRequest()
    req.SmsSdkAppId = "1400140089"
    req.SignName = "坤铭教育"
    req.TemplateId = "1875765"    
    req.TemplateParamSet = [dw_jc,yzm]
    req.PhoneNumberSet = [phone]
    req.SessionContext = ""
    req.ExtendCode = ""
    req.SenderId = ""
    resp = client.SendSms(req)
    dict3 = json.loads(resp.to_json_string(indent=2))

    print(phone,dict3['SendStatusSet'][0]["Message"])
except TencentCloudSDKException as err:
    print(v['phone'],err)
+8613793180751 send success
In [ ]:
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
import json
import pymongo

myclient = pymongo.MongoClient('mongodb://localhost:27017/')
mydb = myclient["baogao"]
mycol = mydb["pdf"]

filename = 'data/中安联合.json'
with open(filename,'r') as fl:
    dict1 = json.load(fl) 
dict2 = {}
place_id = 624770
myquery = { "place_id": place_id,"code":"051067" }
for x in mycol.find(myquery,{ "_id": 0, "place_id": 0}):
    code = int(x['fn'].split('-')[0])
    if str(code) in dict1.keys():
        dict2[code] = {'phone':str(dict1[str(code)]['phone']),'code':x['code']}
    else:
        print('no phone')
print(dict2)

统计短信发送状态

In [ ]:
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
import json
import pymongo


try:    
    secretId = "AKID22rVyvSqbikXFFvav31ykc9YmqjN6KYc"
    secretKey = "51XVL1YxDKI6mJh8au6DDuTskS1RhwJX"
    cred = credential.Credential(secretId, secretKey) 
    httpProfile = HttpProfile()
    httpProfile.reqMethod = "POST"  # post请求(默认为post请求)
    httpProfile.reqTimeout = 60    # 请求超时时间,单位为秒(默认60秒)
    httpProfile.endpoint = "sms.tencentcloudapi.com"  # 指定接入地域域名(默认就近接入)
    clientProfile = ClientProfile()
    clientProfile.signMethod = "TC3-HMAC-SHA256"  # 指定签名算法
    clientProfile.language = "en-US"
    clientProfile.httpProfile = httpProfile
    client = sms_client.SmsClient(cred, "ap-guangzhou", clientProfile)
    req = models.SendStatusStatisticsRequest()
    req.SmsSdkAppId = "1400140089"
    
    # 拉取最大条数,最多100条
    req.Limit = 100
    # 偏移量 注:目前固定设置为0
    req.Offset = 0
    # 开始时间,yyyymmddhh 需要拉取的起始时间,精确到小时
    req.BeginTime = "2023112700"
    # 结束时间,yyyymmddhh 需要拉取的截止时间,精确到小时
    # 注:EndTime 必须大于 BeginTime
    req.EndTime = "2023112723"


    # 通过client对象调用SendStatusStatistics方法发起请求。注意请求方法名与请求对象是对应的。
    # 返回的resp是一个SendStatusStatisticsResponse类的实例,与请求对象对应。
    resp = client.SendStatusStatistics(req)


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


except TencentCloudSDKException as err:
    print(err)

拉取短信下发状态

In [ ]:
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) 
    httpProfile = HttpProfile()
    httpProfile.reqMethod = "POST"  # post请求(默认为post请求)
    httpProfile.reqTimeout = 60    # 请求超时时间,单位为秒(默认60秒)
    httpProfile.endpoint = "sms.tencentcloudapi.com"  # 指定接入地域域名(默认就近接入)
    clientProfile = ClientProfile()
    clientProfile.signMethod = "TC3-HMAC-SHA256"  # 指定签名算法
    clientProfile.language = "en-US"
    clientProfile.httpProfile = httpProfile
    client = sms_client.SmsClient(cred, "ap-guangzhou", clientProfile)
    req = models.PullSmsSendStatusRequest()
    req.SmsSdkAppId = "1400140089"
    req.Limit = 100
    resp = client.PullSmsSendStatus(req)
    # 输出json格式的字符串回包
    print(resp.to_json_string(indent=2))


except TencentCloudSDKException as err:
    print(err)
In [ ]:
In [ ]: