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))