mqtt
This commit is contained in:
parent
9142a1bce3
commit
62451abf0c
4
MQTT.py
4
MQTT.py
|
@ -2,7 +2,7 @@ import json
|
|||
|
||||
import paho.mqtt.client as mqtt
|
||||
|
||||
from tool import push_stream, close_stream, update, exec_sh
|
||||
from tool import push_stream, close_stream, update, exec_sh, get_record
|
||||
|
||||
|
||||
class MQTT:
|
||||
|
@ -30,7 +30,7 @@ class MQTT:
|
|||
update()
|
||||
client.publish('success', payload='update success', qos=0)
|
||||
elif data == "record":
|
||||
get_record(msg)
|
||||
get_record(msg, self.client)
|
||||
else:
|
||||
client.publish('error', payload='No Such Type', qos=0)
|
||||
|
||||
|
|
35
tool.py
35
tool.py
|
@ -1,6 +1,9 @@
|
|||
import datetime
|
||||
import json
|
||||
import subprocess
|
||||
|
||||
from fastapi import FastAPI
|
||||
|
||||
|
||||
def push_stream():
|
||||
subprocess.Popen(['/bin/bash start_push.sh'], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
|
@ -19,5 +22,33 @@ def update():
|
|||
subprocess.Popen(['/bin/bash update.sh'], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
|
||||
|
||||
def get_record(msg):
|
||||
time = json.loads(msg.payload.decode('utf-8'))["data"]
|
||||
def get_record(msg, client):
|
||||
import requests
|
||||
create_time = json.loads(msg.payload.decode('utf-8'))["data"]
|
||||
# create_time = '2023-12-01 19-07-58'
|
||||
import os
|
||||
create_time_date_str = create_time.split(' ')[0]
|
||||
create_time_time_str = create_time.split(' ')[1]
|
||||
create_time_ = datetime.datetime(int(create_time_date_str[:4]), int(create_time_date_str[5:7]),
|
||||
int(create_time_date_str[8:10]), int(create_time_time_str[:2]),
|
||||
int(create_time_time_str[3:5]), int(create_time_time_str[6:8]))
|
||||
file_name_ = ''
|
||||
for filename in os.listdir('mp4'):
|
||||
# 检查文件名是否符合格式 %Y-%m-%d_%H-%M-%S
|
||||
if filename.startswith('2') and '-' in filename and '_' in filename:
|
||||
# 提取日期和时间
|
||||
date_str = filename.split('_')[0] # 例如 '2023-06-23'
|
||||
time_str = filename.split('_')[1] # 例如 '06'
|
||||
|
||||
# 将日期和时间字符串转换为 datetime 对象
|
||||
file_time = datetime.datetime(int(date_str[:4]), int(date_str[5:7]),
|
||||
int(date_str[8:10]), int(time_str[:2]),
|
||||
int(time_str[3:5]), int(time_str[6:8]))
|
||||
# 比较文件时间和创建时间
|
||||
if file_time > create_time_:
|
||||
file_name_ = filename
|
||||
if file_name_ == '':
|
||||
client.publish('error', payload='没有该文件', qos=0)
|
||||
return
|
||||
files = {"file": open(file_name_, 'rb'), "Content-Type": "application/octet-stream"}
|
||||
requests.post("http://127.0.0.1:8000/testfile", files=files)
|
||||
|
|
Loading…
Reference in New Issue