From 1b8690bc2ed3e73d686799bc7530db1fe3ffef6e Mon Sep 17 00:00:00 2001 From: xyj <10908227994@qq.com> Date: Mon, 18 Dec 2023 11:28:45 +0800 Subject: [PATCH] update --- MQTT.py | 2 +- tool.py | 30 ++++++++++++++++++------------ 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/MQTT.py b/MQTT.py index c4f215e..099ffd0 100644 --- a/MQTT.py +++ b/MQTT.py @@ -1,4 +1,4 @@ -import json + import time import paho.mqtt.client as mqtt diff --git a/tool.py b/tool.py index fc00d5e..14fe518 100755 --- a/tool.py +++ b/tool.py @@ -92,19 +92,25 @@ def reload(client): def get_list_record(client): - data = { - "data": os.listdir(mp4_path) - } - r = requests.post(post_record_list_url, json=data) - client.publish(info_topic, payload=publish_payload(code=200, msg=str(r)), qos=0) + try: + data = { + "data": os.listdir(mp4_path) + } + r = requests.post(post_record_list_url, json=data) + client.publish(info_topic, payload=publish_payload(code=200, msg=str(r)), qos=0) + except: + pass def get_record(msg, client): - filename = json.loads(msg.payload.decode('utf-8'))["data"] - if filename is None or filename == '': - client.publish(info_topic, payload=publish_payload(code=404, msg='没有该文件'), qos=0) - return + try: + filename = json.loads(msg.payload.decode('utf-8'))["data"] + if filename is None or filename == '': + client.publish(info_topic, payload=publish_payload(code=404, msg='没有该文件'), qos=0) + return - files = {filename: open(os.path.join(mp4_path, filename), 'rb'), "Content-Type": "application/octet-stream"} - r = requests.post(post_record_url, files=files) - client.publish(info_topic, payload=publish_payload(code=200, msg=str(r)), qos=0) + files = {filename: open(os.path.join(mp4_path, filename), 'rb'), "Content-Type": "application/octet-stream"} + r = requests.post(post_record_url, files=files) + client.publish(info_topic, payload=publish_payload(code=200, msg=str(r)), qos=0) + except: + pass