23 KiB
23 KiB
In [ ]:
import pymongo
myclient = pymongo.MongoClient('mongodb://localhost:27017/')
mydb = myclient["baogao"]
mycol = mydb["place"]
place_id = 345321
place_code = "14"
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 [7]:
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 = 496534
place_code = "12"
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,3) #随机取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('ok') ok
In [10]:
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/天宫院社区240922.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 13488820384 0014-舒浩轩.pdf 12429 2 18612703139 0025-李嘉睿.pdf 12637 3 13522895654 0003-杨宾.pdf 12432 4 13718367043 0012-杨玉芬.pdf 12896 5 15210713283 0005-王红柳.pdf 12628 6 15101087817 0024-茅晴晴.pdf 12489 7 18810111978 0008-段丽阳.pdf 12073 8 15224991657 0026-郑慧敏.pdf 12467 9 15210713283 0006-高天蕴.pdf 12748 10 15010699019 0021-董润华.pdf 12609 11 13671026339 0013-王柱明.pdf 12749 12 15551006319 0029-林景平.pdf 12324 13 13522895654 0004-武馨怡.pdf 12762 14 18660799298 0023-程军妮.pdf 12745 15 18233207289 0019-张傲楠.pdf 12672 16 13910932179 0017-朱芷祁.pdf 12621 17 18210661187 0011-张耀聪.pdf 12728 18 18232370815 0020-尹晓晴.pdf 12890 19 13426267482 0018-卢浥尘.pdf 12951 20 13552494958 0031-魏丽.pdf 12267 21 13681380585 0007-刘颖.pdf 12532 22 13311183808 0016-张玉后.pdf 12681 23 18210661187 0001-李雪莉.pdf 12531 24 17665174761 0027-郑文结.pdf 12502 25 15588818169 0022-刘小云.pdf 12758 26 13011189787 0028-潘妍.pdf 12314 27 13770726975 0030-宋元宵.pdf 12634 28 18210661187 0002-张进刚.pdf 12419 29 13671271202 0010-范文兰.pdf 12132 30 18810111978 0009-段宇辰.pdf 12901 31 13581907290 0015-罗靖卓.pdf 12130
In [11]:
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/天宫院社区240922.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
dict2 = {}
place_id = 496534
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)13488820384 12429 send success 18612703139 12637 send success 13522895654 12432 send success 13718367043 12896 send success 15210713283 12628 send success 15101087817 12489 send success 18810111978 12073 send success 15224991657 12467 send success 15210713283 12748 send success 15010699019 12609 send success 13671026339 12749 send success 15551006319 12324 send success 13522895654 12762 send success 18660799298 12745 send success 18233207289 12672 send success 13910932179 12621 send success 18210661187 12728 send success 18232370815 12890 send success 13426267482 12951 send success 13552494958 12267 send success 13681380585 12532 send success 13311183808 12681 send success 18210661187 12531 send success 17665174761 12502 send success 15588818169 12758 send success 13011189787 12314 send success 13770726975 12634 send success 18210661187 12419 send success 13671271202 12132 send success 18810111978 12901 send success 13581907290 12130 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/天宫院社区240922.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
dict2 = {}
place_id = 496534
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'+'18854609676'
yzm = '13306'
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 [ ]: