feat: 添加多个功能模块和工具脚本
- 新增websocket客户端和服务端实现 - 添加图片压缩工具和快速压缩脚本 - 实现学生信息处理相关API - 添加MQTT客户端和消息处理功能 - 更新.gitignore忽略更多文件类型 - 添加数据库操作工具和示例 - 实现多个测试脚本和工具类
This commit is contained in:
@@ -0,0 +1,212 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 18,
|
||||
"id": "d9c14718",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from requests import get,post\n",
|
||||
"import time\n",
|
||||
"ip = \"http://band.hxzhxy.cn\"\n",
|
||||
"# ip = \"http://192.168.0.209:8100\"\n",
|
||||
"param = {\n",
|
||||
" \"username\": \"tw_xiatianle\",\n",
|
||||
" \"password\": \"xia123456\",\n",
|
||||
" \"client_id\": \"client\",\n",
|
||||
" \"grant_type\": \"password\",\n",
|
||||
" \"client_secret\": \"123456\",\n",
|
||||
"}\n",
|
||||
"data = get(url=f\"{ip}/oauth/token\",params=param).json()\n",
|
||||
"token = data[\"access_token\"]\n",
|
||||
"header = {\n",
|
||||
" \"content-type\": \"application/json\",\n",
|
||||
" \"authorization\": f\"Bearer {token}\",\n",
|
||||
"}\n",
|
||||
"teamId=\"119\""
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 19,
|
||||
"id": "1673af54",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"data = get(f\"{ip}/workforce/classTeamMachine/list\",headers=header,params={\n",
|
||||
" \"page\": \"0\",\n",
|
||||
" \"size\": \"100\",\n",
|
||||
" \"teamId\": teamId\n",
|
||||
"}).json()[\"data\"][\"content\"]\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 20,
|
||||
"id": "4cf83c82",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"tem = []\n",
|
||||
"for item in data:\n",
|
||||
" if item[\"classroom\"] != \"鸿兴测试分组\":\n",
|
||||
" tem.append(item)\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 21,
|
||||
"id": "1790800e",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"data = tem"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 22,
|
||||
"id": "34f18ca5",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from paho.mqtt import client as mqtt\n",
|
||||
"import json"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 23,
|
||||
"id": "7cf83679",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"0"
|
||||
]
|
||||
},
|
||||
"execution_count": 23,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"broker = 'band.hxzhxy.cn'\n",
|
||||
"# broker = '192.168.0.111'\n",
|
||||
"port = 1883\n",
|
||||
"topic = \"/python/mqtt\"\n",
|
||||
"client_id = f'python-mqtt-demo'\n",
|
||||
"# MQTT客户端的回调函数\n",
|
||||
"def on_connect(client, userdata, flags, rc):\n",
|
||||
" print(\"Connected with result code \"+str(rc))\n",
|
||||
" # 连接成功后订阅主题\n",
|
||||
" # client.subscribe(\"#\")\n",
|
||||
"\n",
|
||||
"def on_message(client, userdata, msg):\n",
|
||||
" print(msg.topic+\" \"+str(msg.payload))\n",
|
||||
"\n",
|
||||
"# 创建MQTT客户端实例\n",
|
||||
"client = mqtt.Client(client_id=client_id)\n",
|
||||
"\n",
|
||||
"# 绑定回调函数\n",
|
||||
"client.on_connect = on_connect\n",
|
||||
"client.on_message = on_message\n",
|
||||
"\n",
|
||||
"# 连接到MQTT代理\n",
|
||||
"client.connect(broker, port, 60)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 24,
|
||||
"id": "e706bbb0",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"<paho.mqtt.client.MQTTMessageInfo at 0x1b6a5f5e0c0>"
|
||||
]
|
||||
},
|
||||
"execution_count": 24,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"client.publish(topic, \"hello world\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "72c9ff77",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"for item in data[0:1]:\n",
|
||||
" print(item)\n",
|
||||
" mac=item[\"mac\"]\n",
|
||||
" topic=f\"cmd/publicizeBanpai/08E60E75E09E/control\"\n",
|
||||
" message={\n",
|
||||
" \"type\":\"info\"\n",
|
||||
" }\n",
|
||||
" client.publish(topic, json.dumps(message,ensure_ascii=False))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 31,
|
||||
"id": "82403f63",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"<paho.mqtt.client.MQTTMessageInfo at 0x1b6a5c2bec0>"
|
||||
]
|
||||
},
|
||||
"execution_count": 31,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"topic=f\"cmd/publicizeBanpai/08E60E75E09E/control\"\n",
|
||||
"message={\"type\":\"info\"}\n",
|
||||
"client.publish(topic, json.dumps(message,ensure_ascii=True))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "8ff4367a",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
"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": "undefined.undefined.undefined"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
||||
Reference in New Issue
Block a user