- 新增websocket客户端和服务端实现 - 添加图片压缩工具和快速压缩脚本 - 实现学生信息处理相关API - 添加MQTT客户端和消息处理功能 - 更新.gitignore忽略更多文件类型 - 添加数据库操作工具和示例 - 实现多个测试脚本和工具类
9.8 KiB
9.8 KiB
In [8]:
import pymysql
import snowflake
from faker import Faker
import random
import datetime
fake = Faker('zh_CN')
import random
# 创建数据库连接
connection = pymysql.connect(
host='192.168.0.244',
port=3306,
user='root',
password='Abcd@123456',
database='hongxx',
charset='utf8'
)
# 创建游标对象
cursor = connection.cursor()In [9]:
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 dataIn [10]:
fake.catch_phrase()Out [10]:
'Open-architected analyzing portal'
In [16]:
# 3. 循环生成10条数据并插入
for _ in range(10):
# 生成随机parent_id(1-4)
random_parent_id = random.randint(1, 4)
# 生成随机名称(faker的word/name方法,这里用catch_phrase生成更贴合“页面名称”的随机词)
random_name = fake.catch_phrase()[:4] # 限制长度避免超出字段长度
sql = insert_sql.format(random_parent_id, random_name)
insert_sql = f"""
INSERT INTO `sys_custom_open_page`
(`parent_id`, `name`, `description`, `page_level`, `biz_type`, `page_type`,
`section_code`, `page_path`, `page_url`, `dept_id`, `del_flag`, `create_by`,
`create_time`, `create_person_id`, `create_person_name`, `update_by`,
`update_time`, `update_person_name`, `update_person_id`)
VALUES ({random_parent_id}, '{random_name}', NULL, '0', 'video', '1', '1245', 'http://www.baidu.com',
NULL, 0, '0', 'xtl', '2026-01-14 17:04:49', 0, 'xtl', 'xtl',
'2026-01-14 17:05:10', 'xtl', 0);
"""
print(insert_sql)
# 执行插入
# cursor.execute(insert_sql, (random_parent_id, random_name))
# 4. 提交事务(必须提交才会写入数据库)
# connection.commit()
print("10条数据插入成功!")INSERT INTO `sys_custom_open_page` (`parent_id`, `name`, `description`, `page_level`, `biz_type`, `page_type`, `section_code`, `page_path`, `page_url`, `dept_id`, `del_flag`, `create_by`, `create_time`, `create_person_id`, `create_person_name`, `update_by`, `update_time`, `update_person_name`, `update_person_id`) VALUES (3, 'Phas', NULL, '0', 'video', '1', '1245', 'http://www.baidu.com', NULL, 0, '0', 'xtl', '2026-01-14 17:04:49', 0, 'xtl', 'xtl', '2026-01-14 17:05:10', 'xtl', 0); INSERT INTO `sys_custom_open_page` (`parent_id`, `name`, `description`, `page_level`, `biz_type`, `page_type`, `section_code`, `page_path`, `page_url`, `dept_id`, `del_flag`, `create_by`, `create_time`, `create_person_id`, `create_person_name`, `update_by`, `update_time`, `update_person_name`, `update_person_id`) VALUES (3, 'Bala', NULL, '0', 'video', '1', '1245', 'http://www.baidu.com', NULL, 0, '0', 'xtl', '2026-01-14 17:04:49', 0, 'xtl', 'xtl', '2026-01-14 17:05:10', 'xtl', 0); INSERT INTO `sys_custom_open_page` (`parent_id`, `name`, `description`, `page_level`, `biz_type`, `page_type`, `section_code`, `page_path`, `page_url`, `dept_id`, `del_flag`, `create_by`, `create_time`, `create_person_id`, `create_person_name`, `update_by`, `update_time`, `update_person_name`, `update_person_id`) VALUES (4, 'Syne', NULL, '0', 'video', '1', '1245', 'http://www.baidu.com', NULL, 0, '0', 'xtl', '2026-01-14 17:04:49', 0, 'xtl', 'xtl', '2026-01-14 17:05:10', 'xtl', 0); INSERT INTO `sys_custom_open_page` (`parent_id`, `name`, `description`, `page_level`, `biz_type`, `page_type`, `section_code`, `page_path`, `page_url`, `dept_id`, `del_flag`, `create_by`, `create_time`, `create_person_id`, `create_person_name`, `update_by`, `update_time`, `update_person_name`, `update_person_id`) VALUES (2, 'Cust', NULL, '0', 'video', '1', '1245', 'http://www.baidu.com', NULL, 0, '0', 'xtl', '2026-01-14 17:04:49', 0, 'xtl', 'xtl', '2026-01-14 17:05:10', 'xtl', 0); INSERT INTO `sys_custom_open_page` (`parent_id`, `name`, `description`, `page_level`, `biz_type`, `page_type`, `section_code`, `page_path`, `page_url`, `dept_id`, `del_flag`, `create_by`, `create_time`, `create_person_id`, `create_person_name`, `update_by`, `update_time`, `update_person_name`, `update_person_id`) VALUES (2, 'Stre', NULL, '0', 'video', '1', '1245', 'http://www.baidu.com', NULL, 0, '0', 'xtl', '2026-01-14 17:04:49', 0, 'xtl', 'xtl', '2026-01-14 17:05:10', 'xtl', 0); INSERT INTO `sys_custom_open_page` (`parent_id`, `name`, `description`, `page_level`, `biz_type`, `page_type`, `section_code`, `page_path`, `page_url`, `dept_id`, `del_flag`, `create_by`, `create_time`, `create_person_id`, `create_person_name`, `update_by`, `update_time`, `update_person_name`, `update_person_id`) VALUES (2, 'Orga', NULL, '0', 'video', '1', '1245', 'http://www.baidu.com', NULL, 0, '0', 'xtl', '2026-01-14 17:04:49', 0, 'xtl', 'xtl', '2026-01-14 17:05:10', 'xtl', 0); INSERT INTO `sys_custom_open_page` (`parent_id`, `name`, `description`, `page_level`, `biz_type`, `page_type`, `section_code`, `page_path`, `page_url`, `dept_id`, `del_flag`, `create_by`, `create_time`, `create_person_id`, `create_person_name`, `update_by`, `update_time`, `update_person_name`, `update_person_id`) VALUES (2, 'Ergo', NULL, '0', 'video', '1', '1245', 'http://www.baidu.com', NULL, 0, '0', 'xtl', '2026-01-14 17:04:49', 0, 'xtl', 'xtl', '2026-01-14 17:05:10', 'xtl', 0); INSERT INTO `sys_custom_open_page` (`parent_id`, `name`, `description`, `page_level`, `biz_type`, `page_type`, `section_code`, `page_path`, `page_url`, `dept_id`, `del_flag`, `create_by`, `create_time`, `create_person_id`, `create_person_name`, `update_by`, `update_time`, `update_person_name`, `update_person_id`) VALUES (2, 'Clon', NULL, '0', 'video', '1', '1245', 'http://www.baidu.com', NULL, 0, '0', 'xtl', '2026-01-14 17:04:49', 0, 'xtl', 'xtl', '2026-01-14 17:05:10', 'xtl', 0); INSERT INTO `sys_custom_open_page` (`parent_id`, `name`, `description`, `page_level`, `biz_type`, `page_type`, `section_code`, `page_path`, `page_url`, `dept_id`, `del_flag`, `create_by`, `create_time`, `create_person_id`, `create_person_name`, `update_by`, `update_time`, `update_person_name`, `update_person_id`) VALUES (2, 'Pola', NULL, '0', 'video', '1', '1245', 'http://www.baidu.com', NULL, 0, '0', 'xtl', '2026-01-14 17:04:49', 0, 'xtl', 'xtl', '2026-01-14 17:05:10', 'xtl', 0); INSERT INTO `sys_custom_open_page` (`parent_id`, `name`, `description`, `page_level`, `biz_type`, `page_type`, `section_code`, `page_path`, `page_url`, `dept_id`, `del_flag`, `create_by`, `create_time`, `create_person_id`, `create_person_name`, `update_by`, `update_time`, `update_person_name`, `update_person_id`) VALUES (1, 'Opti', NULL, '0', 'video', '1', '1245', 'http://www.baidu.com', NULL, 0, '0', 'xtl', '2026-01-14 17:04:49', 0, 'xtl', 'xtl', '2026-01-14 17:05:10', 'xtl', 0); 10条数据插入成功!
In [ ]: