1. 调整database.py批量处理记录数为400 2. 新增convert_available.py用于将available字段的JSON数组格式转换为逗号分隔字符串 3. 更新test.py为数据库查询导出脚本 4. 生成并更新SQL更新语句文件 5. 修正jupyter notebook中的数据库连接配置与代码逻辑
36 lines
1.0 KiB
Python
36 lines
1.0 KiB
Python
import pymysql
|
|
import json
|
|
# json
|
|
import random
|
|
# 创建数据库连接
|
|
connection = pymysql.connect(
|
|
host='11.1.1.5',
|
|
user='root',
|
|
password='@HXYD1109mysql',
|
|
database='school_server',
|
|
charset='utf8'
|
|
)
|
|
# 创建游标对象
|
|
cursor = connection.cursor()
|
|
sql="select * from temp_schoolwork_plan"
|
|
cursor.execute(sql)
|
|
result=cursor.fetchall()
|
|
def create_table(cursor,result):
|
|
|
|
data = []
|
|
for i in result:
|
|
list_list = list(i)
|
|
des=cursor.description # 获取表详情,字段名,长度,属性等
|
|
t = ",".join([item[0] for item in des])
|
|
table_head = t.split(',') # # 查询表列名 用,分割
|
|
|
|
dict_result = dict(zip(table_head, list_list)) # 打包为元组的列表 再转换为字典
|
|
data.append(dict_result) # 将字典添加到list_result中
|
|
return data
|
|
table = create_table(cursor,result)
|
|
|
|
for item in table:
|
|
item["create_time"]=''
|
|
item["update_time"]=''
|
|
with open("table.json","w") as f:
|
|
f.write(json.dumps(table,ensure_ascii=False,indent=4)) |