1. 调整database.py批量处理记录数为400 2. 新增convert_available.py用于将available字段的JSON数组格式转换为逗号分隔字符串 3. 更新test.py为数据库查询导出脚本 4. 生成并更新SQL更新语句文件 5. 修正jupyter notebook中的数据库连接配置与代码逻辑
85 lines
2.0 KiB
Plaintext
85 lines
2.0 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 2,
|
|
"id": "7538343f",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import pymysql\n",
|
|
"from faker import Faker\n",
|
|
"fake = Faker('zh_CN')\n",
|
|
"import random\n",
|
|
"# 创建数据库连接\n",
|
|
"connection = pymysql.connect(\n",
|
|
"host='11.1.1.5',\n",
|
|
"user='root',\n",
|
|
"password='@HXYD1109mysql',\n",
|
|
"database='school_server',\n",
|
|
"charset='utf8'\n",
|
|
")\n",
|
|
"# 创建游标对象\n",
|
|
"cursor = connection.cursor()\n",
|
|
"sql=\"select * from robot_knowledge\"\n",
|
|
"cursor.execute(sql)\n",
|
|
"result=cursor.fetchall()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 3,
|
|
"id": "8c88cbf4",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"def create_table(cursor,result):\n",
|
|
" \n",
|
|
" data = []\n",
|
|
" for i in result:\n",
|
|
" list_list = list(i)\n",
|
|
" des=cursor.description # 获取表详情,字段名,长度,属性等\n",
|
|
" t = \",\".join([item[0] for item in des])\n",
|
|
" table_head = t.split(',') # # 查询表列名 用,分割\n",
|
|
" \n",
|
|
" dict_result = dict(zip(table_head, list_list)) # 打包为元组的列表 再转换为字典\n",
|
|
" data.append(dict_result) # 将字典添加到list_result中\n",
|
|
" return data"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "2f6a3ad6",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"sql = '''\n",
|
|
"\n",
|
|
"'''"
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "base",
|
|
"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.12.1"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 5
|
|
}
|