280 lines
8.2 KiB
Plaintext
280 lines
8.2 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "e6dcc663-e0ed-4ea3-b442-11f229f4af94",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 新增体测单位"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "360f0a97-d73d-43f3-9f7a-0f9582103c82",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"import pymongo\n",
|
|
"\n",
|
|
"myclient = pymongo.MongoClient('mongodb://localhost:27017/')\n",
|
|
"mydb = myclient[\"baogao\"]\n",
|
|
"mycol = mydb[\"place\"]\n",
|
|
"\n",
|
|
"id = 469849\n",
|
|
"name = \"长炼医院\"\n",
|
|
"myquery = { \"id\": id }\n",
|
|
"num = mycol.count_documents(myquery)\n",
|
|
"if num>0:\n",
|
|
" print(num)\n",
|
|
"else:\n",
|
|
" mydict = { \"id\":id,\"name\": name, }\n",
|
|
" x = mycol.insert_one(mydict) "
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "dcfbd41f-ca70-4f15-9153-60e6aaac27e8",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 生成手机验证码"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "63a87059-0a0d-43d3-8b89-0cad64d95ff3",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"import openpyxl\n",
|
|
"import os,sys,shutil\n",
|
|
"import json\n",
|
|
"import math\n",
|
|
"import glob\n",
|
|
"import random\n",
|
|
"from pathlib import Path\n",
|
|
"import pymongo\n",
|
|
"\n",
|
|
"myclient = pymongo.MongoClient('mongodb://localhost:27017/')\n",
|
|
"mydb = myclient[\"baogao\"]\n",
|
|
"\n",
|
|
"\n",
|
|
"filename = 'data/北京农行人员名单all.json'\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict1 = json.load(fl) \n",
|
|
"\n",
|
|
"place_id = 309118\n",
|
|
"place_code = '03'\n",
|
|
"dw_name = '中国农业银行股份有限公司北京市分行'\n",
|
|
"fi_path = '/home/songyi/python/mycrm/flask/pdf/files'\n",
|
|
"fls = glob.glob(f'{fi_path}/{str(place_id)}/*.pdf')\n",
|
|
"\n",
|
|
"code_list = []\n",
|
|
"for i in range(10): # 0~9\n",
|
|
" code_list.append(str(i))\n",
|
|
" \n",
|
|
"list1 = []\n",
|
|
"i = 0\n",
|
|
"while i < len(fls):\n",
|
|
" code = random.sample(code_list,5) #随机取6位数\n",
|
|
" code_num = ''.join(code) \n",
|
|
" if code_num not in list1:\n",
|
|
" list1.append(place_code+code_num)\n",
|
|
" i +=1\n",
|
|
"i = 0\n",
|
|
"list2= []\n",
|
|
"for fn in fls:\n",
|
|
" dict2 = {}\n",
|
|
" fi_name =Path(fn).stem.split('-')[0]\n",
|
|
" code = int(fi_name)\n",
|
|
" dxm = list1[i]\n",
|
|
" dict2 = {'place_id':place_id,'code':dxm,'fn':Path(fn).name}\n",
|
|
" list2.append(dict2)\n",
|
|
" i +=1\n",
|
|
"mycol = mydb[\"pdf\"]\n",
|
|
"x = mycol.insert_many(list2)\n",
|
|
"print('ok') \n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "767cdc9b-310e-4922-8b7d-3581a328cf45",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "5f665c0f-8d30-4759-b7f8-fb7e13b98efa",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"import json\n",
|
|
"import pymongo\n",
|
|
"\n",
|
|
"myclient = pymongo.MongoClient('mongodb://localhost:27017/')\n",
|
|
"mydb = myclient[\"baogao\"]\n",
|
|
"mycol = mydb[\"pdf\"]\n",
|
|
"\n",
|
|
"filename = 'data/北京农行人员名单all.json'\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict1 = json.load(fl) \n",
|
|
"dict2 = {}\n",
|
|
"place_id = 309118\n",
|
|
"myquery = { \"place_id\": place_id }\n",
|
|
"for x in mycol.find(myquery,{ \"_id\": 0, \"place_id\": 0}):\n",
|
|
" code = int(x['fn'].split('-')[0])\n",
|
|
" if str(code) in dict1.keys():\n",
|
|
" dict2[code] = {'phone':str(dict1[str(code)]['phone']),'code':x['code']}\n",
|
|
" else:\n",
|
|
" print('no phone')\n",
|
|
"print(dict2)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "b9a157f4-4772-413e-82f4-ecb7d2af8529",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 批量发送短信"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "4b2b5d76-665f-4dfe-bbd3-5c80abd8c3e3",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"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",
|
|
"import json\n",
|
|
"import pymongo\n",
|
|
"\n",
|
|
"myclient = pymongo.MongoClient('mongodb://localhost:27017/')\n",
|
|
"mydb = myclient[\"baogao\"]\n",
|
|
"mycol = mydb[\"pdf\"]\n",
|
|
"\n",
|
|
"filename = 'data/北京农行人员名单all.json'\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict1 = json.load(fl) \n",
|
|
"dict2 = {}\n",
|
|
"place_id = 309118\n",
|
|
"myquery = { \"place_id\": place_id }\n",
|
|
"for x in mycol.find(myquery,{ \"_id\": 0, \"place_id\": 0}):\n",
|
|
" code = int(x['fn'].split('-')[0])\n",
|
|
" if str(code) in dict1.keys():\n",
|
|
" dict2[code] = {'phone':str(dict1[str(code)]['phone']),'code':x['code']}\n",
|
|
" else:\n",
|
|
" print('no phone')\n",
|
|
"print(dict2)\n",
|
|
"\n",
|
|
"#dict2 = {375: {'phone': '13793180751', 'code': '0379208'}}\n",
|
|
"for k, v in dict2.items():\n",
|
|
" phone = '+86'+v['phone']\n",
|
|
" yzm = v['code']\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 = \"1875765\" \n",
|
|
" req.TemplateParamSet = [\"农行北京市分行体测者\",yzm]\n",
|
|
" req.PhoneNumberSet = [phone]\n",
|
|
" req.SessionContext = \"\"\n",
|
|
" req.ExtendCode = \"\"\n",
|
|
" req.SenderId = \"\"\n",
|
|
" resp = client.SendSms(req)\n",
|
|
" dict3 = json.loads(resp.to_json_string(indent=2))\n",
|
|
"\n",
|
|
" print(v['phone'],dict3['SendStatusSet'][0][\"Message\"])\n",
|
|
" except TencentCloudSDKException as err:\n",
|
|
" print(v['phone'],err)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "eefec974-c4b7-43c8-82c2-6ad6e5045aa0",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import json\n",
|
|
"\n",
|
|
"filename = 'data/01.json'\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict1 = json.load(fl)\n",
|
|
"for k, v in dict1.items():\n",
|
|
" phone = '+86'+v['phone']\n",
|
|
" yzm = v['code']\n",
|
|
" print(k,phone,yzm)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "df637ce6-7c35-404a-af43-2a5a66b49ba0",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"dict1 = json.loads(resp.to_json_string(indent=2))\n",
|
|
"print(dict1['SendStatusSet'][0][\"Message\"])"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "ba05bd1a-9f33-4df7-b15e-d110c19a5dea",
|
|
"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.12"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 5
|
|
}
|