20220524
This commit is contained in:
1 parent
272d2ebbb3
commit
803a0c5690
2 files changed
+83
-56
No files matched your search
+81
-5
@@ -665,6 +665,66 @@
|
||||
"\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### 导入2021年一分一段表"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"metadata": {
|
||||
"execution": {
|
||||
"iopub.execute_input": "2022-05-24T10:20:31.546520Z",
|
||||
"iopub.status.busy": "2022-05-24T10:20:31.546005Z",
|
||||
"iopub.status.idle": "2022-05-24T10:20:31.760806Z",
|
||||
"shell.execute_reply": "2022-05-24T10:20:31.759535Z",
|
||||
"shell.execute_reply.started": "2022-05-24T10:20:31.546476Z"
|
||||
},
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"ok!\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"import openpyxl\n",
|
||||
"import pymysql\n",
|
||||
"import json\n",
|
||||
"\n",
|
||||
"m_xx = []\n",
|
||||
"db = pymysql.connect(host = \"localhost\",user = \"root\",password = \"songyi\",database = \"gaokao\" )\n",
|
||||
"cursor = db.cursor()\n",
|
||||
"wb = openpyxl.load_workbook('./data/2021年一分一段表.xlsx')\n",
|
||||
"sheet = wb.active\n",
|
||||
"i = 1\n",
|
||||
"for n in range(4,sheet.max_row):\n",
|
||||
" m_score = sheet.cell(n,1).value\n",
|
||||
" m_num = sheet.cell(n,2).value\n",
|
||||
" m_sum = sheet.cell(n,3).value\n",
|
||||
" m_max = m_sum - m_num + 1\n",
|
||||
" m_xx.append((m_score,m_num,m_max,m_sum,'z','2021'))\n",
|
||||
"#print(m_xx)\n",
|
||||
"sql = 'insert into fenduan(score,per_num,max_rank,min_rank,category,nian) values (%s,%s,%s,%s,%s,%s)'\n",
|
||||
"try:\n",
|
||||
" cursor.executemany(sql,m_xx)\n",
|
||||
" db.commit()\n",
|
||||
" print(\"ok!\")\n",
|
||||
"except:\n",
|
||||
" # 如果发生错误则回滚\n",
|
||||
" print(\"error!\")\n",
|
||||
" db.rollback() \n",
|
||||
"\n",
|
||||
"db.close()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
@@ -674,15 +734,31 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"execution_count": 3,
|
||||
"metadata": {
|
||||
"execution": {
|
||||
"iopub.execute_input": "2022-05-24T10:23:05.570230Z",
|
||||
"iopub.status.busy": "2022-05-24T10:23:05.569724Z",
|
||||
"iopub.status.idle": "2022-05-24T10:23:05.703267Z",
|
||||
"shell.execute_reply": "2022-05-24T10:23:05.702038Z",
|
||||
"shell.execute_reply.started": "2022-05-24T10:23:05.570184Z"
|
||||
}
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"ok!\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"import pymysql\n",
|
||||
"import json\n",
|
||||
"\n",
|
||||
"m_xx = {}\n",
|
||||
"db = pymysql.connect(\"localhost\",\"root\",\"songyi\",\"gaokao\" )\n",
|
||||
"db = pymysql.connect(host = \"localhost\",user = \"root\",password = \"songyi\",database = \"gaokao\" )\n",
|
||||
"cursor = db.cursor()\n",
|
||||
"sql = 'SELECT * FROM fenduan AS a ORDER BY nian,category'\n",
|
||||
"cursor.execute(sql)\n",
|
||||
@@ -695,7 +771,7 @@
|
||||
" m_xx[m_year][result[5]][result[1]]['num_person'] = result[2]\n",
|
||||
" m_xx[m_year][result[5]][result[1]]['max_rank'] = result[3]\n",
|
||||
" m_xx[m_year][result[5]][result[1]]['min_rank'] = result[4]\n",
|
||||
"fl_name = 'data/17-20年一分一段表.json'\n",
|
||||
"fl_name = 'data/17-21年一分一段表.json'\n",
|
||||
"with open(fl_name,'w') as fl:\n",
|
||||
" json.dump(m_xx,fl,ensure_ascii=False)\n",
|
||||
"print('ok!')\n"
|
||||
|
||||
Reference in new issue
Block a user