24 KiB
24 KiB
In [23]:
import pymongo
myclient = pymongo.MongoClient('mongodb://localhost:27017/')
mydb = myclient["baogao"]
mycol = mydb["place"]
place_id = 25032001
place_code = "20"
dw_name = "2025级油田老年大学体质康健基础班"
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 [24]:
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 = 25032001
place_code = "20"
dw_name = "2025级油田老年大学体质康健基础班"
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') 31 ok
In [25]:
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 = "2025级油田老年大学体质康健基础班"
filename = 'data/2025级油田老年大学体质康健基础班.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
dict2 = {}
place_id = 25032001
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 18654628632 0028-张红丽.pdf 206138 2 13589980155 0032-马建辉.pdf 208451 3 13963394816 0029-张凤魁.pdf 205879 4 13905462350 0034-张晓云.pdf 203015 5 13562280825 0016-李爱云.pdf 200689 6 15318339058 0007-韩金秀.pdf 203970 7 13589956960 0026-严新杰.pdf 200467 8 13906478916 0003-曹春梅.pdf 205019 9 13706476046 0023-王维卿.pdf 208975 10 13561090015 0022-王金文.pdf 204916 11 13013569039 0006-耿红霞.pdf 209158 12 13954622371 0019-王国臣.pdf 204637 13 18905466915 0017-梁秀荣.pdf 208243 14 13012902582 0030-张明霞.pdf 203281 15 13954626181 0013-李佐东.pdf 202568 16 13287350839 0020-王秀娟.pdf 200195 17 13954654611 0035-单丽荣.pdf 205740 18 13792079628 0031-马羚.pdf 201534 19 13563378335 0027-赵芳霞.pdf 205462 20 15105461296 0001-丛霞.pdf 203872 21 18653699898 0025-杨江萍.pdf 204830 22 13082601667 0021-王静.pdf 207801 23 13954606669 0033-朱莲女.pdf 207605 24 13864757610 0036-赵萍.pdf 208520 25 13287336162 0012-鲁兴湘.pdf 200654 26 13325052019 0010-刘敏.pdf 200635 27 13589965775 0011-李梅.pdf 206794 28 13864739068 0018-孙杰.pdf 203096 29 15105461298 0002-陈秀华.pdf 205248 30 15550503986 0005-丁元花.pdf 201624 31 15005463621 0037-高学晖.pdf 206374
In [26]:
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/2025级油田老年大学体质康健基础班.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
dict2 = {}
place_id = 25032001
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(5)
except TencentCloudSDKException as err:
print(v['phone'],err)18654628632 206138 send success 13589980155 208451 send success 13963394816 205879 send success 13905462350 203015 send success 13562280825 200689 send success 15318339058 203970 send success 13589956960 200467 send success 13906478916 205019 send success 13706476046 208975 send success 13561090015 204916 send success 13013569039 209158 send success 13954622371 204637 send success 18905466915 208243 send success 13012902582 203281 send success 13954626181 202568 send success 13287350839 200195 send success 13954654611 205740 send success 13792079628 201534 send success 13563378335 205462 send success 15105461296 203872 send success 18653699898 204830 send success 13082601667 207801 send success 13954606669 207605 send success 13864757610 208520 send success 13287336162 200654 send success 13325052019 200635 send success 13589965775 206794 send success 13864739068 203096 send success 15105461298 205248 send success 15550503986 201624 send success 15005463621 206374 send success
In [ ]:
dict1 = json.loads(resp.to_json_string(indent=2))
print(dict1['SendStatusSet'][0]["Message"])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"]
dw_jc = "海淀区老干部大学"
filename = 'data/海淀区老干部大学第一期.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
dict2 = {}
place_id = 250319
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 = '185679'
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)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 [ ]: