243 lines
7.1 KiB
Plaintext
243 lines
7.1 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "e6dcc663-e0ed-4ea3-b442-11f229f4af94",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 新增体测单位"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 8,
|
|
"id": "360f0a97-d73d-43f3-9f7a-0f9582103c82",
|
|
"metadata": {
|
|
"execution": {
|
|
"iopub.execute_input": "2023-09-15T03:53:47.937290Z",
|
|
"iopub.status.busy": "2023-09-15T03:53:47.936825Z",
|
|
"iopub.status.idle": "2023-09-15T03:53:47.950180Z",
|
|
"shell.execute_reply": "2023-09-15T03:53:47.949521Z",
|
|
"shell.execute_reply.started": "2023-09-15T03:53:47.937254Z"
|
|
},
|
|
"tags": []
|
|
},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"1\n"
|
|
]
|
|
}
|
|
],
|
|
"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": "b68302b4-8fc1-4060-a10d-7f059f006f3c",
|
|
"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",
|
|
"wb = openpyxl.load_workbook('data/北京石油分公司报告明细.xlsx')\n",
|
|
"place_id = 419309\n",
|
|
"place_code = '01'\n",
|
|
"dw_name = '北京石油分公司'\n",
|
|
"fi_path = 'file/2023-06-15'\n",
|
|
"fls = glob.glob(f'{fi_path}/*.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,6) #随机取6位数\n",
|
|
" code_num = ''.join(code) \n",
|
|
" if code_num not in list1:\n",
|
|
" list1.append(place_code+code_num)\n",
|
|
" i +=1\n",
|
|
"print(len(list1))\n",
|
|
"sheet = wb.active\n",
|
|
"# sheets = wb.sheetnames\n",
|
|
"list2 = []\n",
|
|
"i = 0\n",
|
|
"dict2 = {}\n",
|
|
"for n in range(2, sheet.max_row+1):\n",
|
|
" if sheet.cell(n,1).value is not None:\n",
|
|
" dict1 = {}\n",
|
|
" phone = str(sheet.cell(n, 3).value)\n",
|
|
" code = int(sheet.cell(n, 1).value)\n",
|
|
" yzm = list1[i]\n",
|
|
" i+=1\n",
|
|
" dict1 = {'place_id':place_id,'code':yzm,'fn':str(code)+'.pdf'}\n",
|
|
" list2.append(dict1)\n",
|
|
" dict2[code]={'phone':phone,'code':yzm}\n",
|
|
"mycol = mydb[\"pdf\"]\n",
|
|
"x = mycol.insert_many(list2)\n",
|
|
"filename = 'data/01.json'\n",
|
|
"with open(filename, 'w') as fl:\n",
|
|
" json.dump(dict2, fl, ensure_ascii=False)\n",
|
|
"print('ok')\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "b9a157f4-4772-413e-82f4-ecb7d2af8529",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 批量发送短信"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "4b2b5d76-665f-4dfe-bbd3-5c80abd8c3e3",
|
|
"metadata": {},
|
|
"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",
|
|
"\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",
|
|
" 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",
|
|
" dict2 = json.loads(resp.to_json_string(indent=2))\n",
|
|
"\n",
|
|
" print(v['phone'],dict2['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
|
|
}
|