20230311
This commit is contained in:
1 parent
a3e959f6f2
commit
4342ad8e57
1 file changed
+190
-23
+190
-23
@@ -305,11 +305,196 @@
|
||||
" m_mongo['wei'] = m_xx[12]\n",
|
||||
" mycol.insert_one(m_mongo) \n",
|
||||
" #print(m_mongo)\n",
|
||||
"print('ok!')\n",
|
||||
"print('ok!')\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## YALM文件操作"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### YALM文件读取"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import yaml\n",
|
||||
"filename = 'data/体质指标问卷.yaml'\n",
|
||||
"with open(filename, 'r', encoding='utf-8') as f:\n",
|
||||
" result = yaml.load(f.read(), Loader=yaml.FullLoader)\n",
|
||||
"i = 1\n",
|
||||
"print(result['pages'])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### 按照年龄分组生成心理问卷"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 43,
|
||||
"metadata": {
|
||||
"execution": {
|
||||
"iopub.execute_input": "2023-03-11T10:45:13.254808Z",
|
||||
"iopub.status.busy": "2023-03-11T10:45:13.254221Z",
|
||||
"iopub.status.idle": "2023-03-11T10:45:13.364497Z",
|
||||
"shell.execute_reply": "2023-03-11T10:45:13.362986Z",
|
||||
"shell.execute_reply.started": "2023-03-11T10:45:13.254761Z"
|
||||
},
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"{1: ['完全不正确', '有点正确', '多数正确', '完全正确'], 2: ['从不', '极少', '偶尔', '经常', '频繁', '非常频繁', '每天'], 3: ['不符合', '有时符合', '常常符合', '总是符合'], 4: ['从不', '很少', '有时', '经常', '总是'], 5: ['非常不满意', '不满意', '一般', '满意', '非常满意'], 6: ['没有或很少时间(少于1天)', '一部分时间(1-2天)', '相当多时间(3-4天)', '绝大部分时间(5-7天)'], 7: ['从来没有这种感觉', '很少有这种感觉', '有时有这种感觉', '经常有这种感觉'], 8: ['完全不同意', '不同意', '同意', '完全同意'], 10: ['晚多了', '晚一点', '差不多', '早一点', '早多了']}\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"import json\n",
|
||||
"import os,sys,shutil\n",
|
||||
"import openpyxl\n",
|
||||
"\n",
|
||||
"list1 = [\n",
|
||||
" [1,'完全不正确','有点正确','多数正确','完全正确'],\n",
|
||||
" [2,'从不','极少','偶尔','经常','频繁','非常频繁','每天'],\n",
|
||||
" [3,'不符合','有时符合','常常符合','总是符合'],\n",
|
||||
" [4,'从不','很少','有时','经常','总是'],\n",
|
||||
" [5,'非常不满意','不满意','一般','满意','非常满意'],\n",
|
||||
" [6,'没有或很少时间(少于1天)','一部分时间(1-2天)','相当多时间(3-4天)','绝大部分时间(5-7天)'],\n",
|
||||
" [7,'从来没有这种感觉','很少有这种感觉','有时有这种感觉','经常有这种感觉'],\n",
|
||||
" [8,'完全不同意','不同意','同意','完全同意'], \n",
|
||||
" [10,'晚多了','晚一点','差不多','早一点','早多了']\n",
|
||||
"]\n",
|
||||
"dict1 = {}\n",
|
||||
"for item in list1:\n",
|
||||
" #dict1.setdefault(item[0],[])\n",
|
||||
" list2 =[]\n",
|
||||
" for i in range(1,len(item)):\n",
|
||||
" list2.append(item[i])\n",
|
||||
" dict1[item[0]] = list2\n",
|
||||
"dict_choiced = {}\n",
|
||||
"print(dict1)\n",
|
||||
"wj = {}\n",
|
||||
"wj[\"login\"] = \"phone\"\n",
|
||||
"wj[\"locale\"] = \"zh-cn\"\n",
|
||||
"wj[\"title\"] = '社区心理测评问卷'\n",
|
||||
"list2 =[]\n",
|
||||
"dict2 = {\n",
|
||||
" \"type\": \"radiogroup\",\n",
|
||||
" \"name\": \"Gender\",\n",
|
||||
" \"title\": {\n",
|
||||
" \"zh-cn\": \"您的性别\"\n",
|
||||
" },\n",
|
||||
" \"isRequired\": True,\n",
|
||||
" \"choices\": [\n",
|
||||
" {\n",
|
||||
" \"value\": \"m\",\n",
|
||||
" \"text\": \"男性\"\n",
|
||||
" },\n",
|
||||
" {\n",
|
||||
" \"value\": \"f\",\n",
|
||||
" \"text\": \"女性\"\n",
|
||||
" }\n",
|
||||
" ] \n",
|
||||
"}\n",
|
||||
"list2.append(dict2)\n",
|
||||
"dict2 = {}\n",
|
||||
"dict3 = {}\n",
|
||||
"dict2 = {\n",
|
||||
" \"type\": \"radiogroup\",\n",
|
||||
" \"name\": \"Age\",\n",
|
||||
" \"title\": {\n",
|
||||
" \"zh-cn\": \"您的年龄\"\n",
|
||||
" },\n",
|
||||
" \"isRequired\": True,\n",
|
||||
" \"choices\": [\n",
|
||||
" {\n",
|
||||
" \"value\": \"Y\",\n",
|
||||
" \"text\": \"8-17岁\"\n",
|
||||
" },\n",
|
||||
" {\n",
|
||||
" \"value\": \"M\",\n",
|
||||
" \"text\": \"15-59岁\"\n",
|
||||
" },\n",
|
||||
" {\n",
|
||||
" \"value\": \"O\",\n",
|
||||
" \"text\": \"60岁及以上\"\n",
|
||||
" }\n",
|
||||
" ] \n",
|
||||
"}\n",
|
||||
"list2.append(dict2)\n",
|
||||
"\n",
|
||||
"wb = openpyxl.load_workbook('data/心理问卷.xlsx')\n",
|
||||
"sheet = wb.active\n",
|
||||
"data1 =list(sheet.values)\n",
|
||||
"del data1[0]\n",
|
||||
"for item in data1:\n",
|
||||
" \n",
|
||||
" dict2 = {} \n",
|
||||
" dict2['type'] = item[4] \n",
|
||||
" dict2['name'] = 'q'+str(item[0])+item[3]\n",
|
||||
" dict2['visibleIf'] = '{Age}=\"'+item[3]+'\"'\n",
|
||||
" dict3 = {}\n",
|
||||
" dict3[\"zh-cn\"] = item[1]\n",
|
||||
" dict2['title'] =dict3 \n",
|
||||
" dict2['isRequired'] = True\n",
|
||||
" if item[4] == 'rating':\n",
|
||||
" dict2['rateMin'] = 0\n",
|
||||
" dict2['rateMax'] = 7\n",
|
||||
" dict2['minRateDescription'] = { 'zh-cn':'没有'}\n",
|
||||
" dict2['maxRateDescription'] = { 'zh-cn':'非常同意'}\n",
|
||||
" else:\n",
|
||||
" if int(item[2]) in dict_choiced.keys():\n",
|
||||
" dict2['choicesFromQuestion'] = dict_choiced[int(item[2])]\n",
|
||||
" else:\n",
|
||||
" list3 = []\n",
|
||||
" i = 1\n",
|
||||
" for xm in dict1[int(item[2])]:\n",
|
||||
" dict3 = {}\n",
|
||||
" dict3 = {'value': i,'text' : xm}\n",
|
||||
" list3.append(dict3)\n",
|
||||
" i+=1\n",
|
||||
" dict2['choices'] = list3\n",
|
||||
" dict_choiced[int(item[2])] = dict2['name']\n",
|
||||
" list2.append(dict2)\n",
|
||||
"dict3 = {}\n",
|
||||
"dict3[\"elements\"] = list2\n",
|
||||
"wj[\"pages\"] =[]\n",
|
||||
"\n",
|
||||
"\n"
|
||||
"wj[\"pages\"].append(dict3)\n",
|
||||
"#filename = 'data/心理问卷1.json'\n",
|
||||
"#with open(filename, 'w') as fl:\n",
|
||||
"# json.dump(wj, fl, ensure_ascii=False)\n",
|
||||
"#print('ok')\n",
|
||||
"with open('心理问卷.yml', 'w', encoding='utf-8') as f:\n",
|
||||
" yaml.dump(data=wj, stream=f, allow_unicode=True)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import yaml\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -386,37 +571,19 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"## 使用网易邮箱群发测试链接"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 6,
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"execution": {
|
||||
"iopub.execute_input": "2022-12-17T09:50:44.652147Z",
|
||||
"iopub.status.busy": "2022-12-17T09:50:44.651632Z",
|
||||
"iopub.status.idle": "2022-12-17T09:50:55.208581Z",
|
||||
"shell.execute_reply": "2022-12-17T09:50:55.206883Z",
|
||||
"shell.execute_reply.started": "2022-12-17T09:50:44.652098Z"
|
||||
},
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"邮件发送成功!\n",
|
||||
"邮件发送成功!\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from email.mime.text import MIMEText\n",
|
||||
"from email.mime.multipart import MIMEMultipart\n",
|
||||
|
||||
Reference in new issue
Block a user