feat: 添加多个功能模块和工具脚本
- 新增websocket客户端和服务端实现 - 添加图片压缩工具和快速压缩脚本 - 实现学生信息处理相关API - 添加MQTT客户端和消息处理功能 - 更新.gitignore忽略更多文件类型 - 添加数据库操作工具和示例 - 实现多个测试脚本和工具类
This commit is contained in:
+133
@@ -0,0 +1,133 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"id": "b82fd271",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import pymysql\n",
|
||||
"import snowflake\n",
|
||||
"from faker import Faker\n",
|
||||
"import random\n",
|
||||
"import datetime\n",
|
||||
"fake = Faker('zh_CN')\n",
|
||||
"import random\n",
|
||||
"# 创建数据库连接\n",
|
||||
"connection = pymysql.connect(\n",
|
||||
"host='192.168.0.244',\n",
|
||||
"port=3306,\n",
|
||||
"user='root',\n",
|
||||
"password='Abcd@123456',\n",
|
||||
"database='hongxx_video',\n",
|
||||
"charset='utf8'\n",
|
||||
")\n",
|
||||
"# 创建游标对象\n",
|
||||
"cursor = connection.cursor()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"id": "759c550a",
|
||||
"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": 4,
|
||||
"id": "b717043a",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"sql = 'select * from video_info'"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
"id": "b4b373b8",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"cursor.execute(sql)\n",
|
||||
"rows = cursor.fetchall()\n",
|
||||
"result = create_table(cursor,rows)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 8,
|
||||
"id": "84652b4b",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"result\n",
|
||||
"# http://192.168.0.244:88/record/original-files/video/522e4c55fc804decafdd0a62e5a1bf74.mp4\n",
|
||||
"for item in result:\n",
|
||||
" if item[\"video_url\"].startswith(\"http://192.168.0.244:88\"):\n",
|
||||
" video_url = item[\"video_url\"].replace(\"http://192.168.0.244:88\",\"/mp4\")\n",
|
||||
" sql = f\"update video_info set video_url='{video_url}' where id={item['id']}\"\n",
|
||||
" cursor.execute(sql)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "0b4381f4",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"ename": "",
|
||||
"evalue": "",
|
||||
"output_type": "error",
|
||||
"traceback": [
|
||||
"\u001b[1;31m在当前单元格或上一个单元格中执行代码时 Kernel 崩溃。\n",
|
||||
"\u001b[1;31m请查看单元格中的代码,以确定故障的可能原因。\n",
|
||||
"\u001b[1;31m单击<a href='https://aka.ms/vscodeJupyterKernelCrash'>此处</a>了解详细信息。\n",
|
||||
"\u001b[1;31m有关更多详细信息,请查看 Jupyter <a href='command:jupyter.viewOutput'>log</a>。"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"connection.commit()"
|
||||
]
|
||||
}
|
||||
],
|
||||
"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.4"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
||||
Reference in New Issue
Block a user