test
This commit is contained in:
parent
8745434d05
commit
66027be2b6
2
MQTT.py
2
MQTT.py
|
@ -35,7 +35,7 @@ class MQTT:
|
||||||
client.publish('error', payload='No Such Type', qos=0)
|
client.publish('error', payload='No Such Type', qos=0)
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.client = mqtt.Client()
|
self.client = mqtt.Client(client_id='')
|
||||||
self.client.username_pw_set("demo", "123456")
|
self.client.username_pw_set("demo", "123456")
|
||||||
# Specify callback function
|
# Specify callback function
|
||||||
self.client.on_connect = self.on_connect
|
self.client.on_connect = self.on_connect
|
||||||
|
|
6
ceshi.py
6
ceshi.py
|
@ -384,16 +384,14 @@ def on_connect(client, userdata, flags, rc):
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
if rc == 0:
|
if rc == 0:
|
||||||
# print("连接成功,执行数据推送和本地存储")
|
# print("连接成功,执行数据推送和本地存储")
|
||||||
nt1 = Thread(target=t1)
|
Thread(target=t1).start()
|
||||||
nt1.start()
|
|
||||||
else:
|
else:
|
||||||
if times != 0:
|
if times != 0:
|
||||||
times -= 1
|
times -= 1
|
||||||
client.reconnect()
|
client.reconnect()
|
||||||
else:
|
else:
|
||||||
# print("3次失败,执行本地存储")
|
# print("3次失败,执行本地存储")
|
||||||
nt2 = Thread(target=t2)
|
Thread(target=t2).start()
|
||||||
nt2.start()
|
|
||||||
|
|
||||||
|
|
||||||
def t2():
|
def t2():
|
||||||
|
|
58
tool.py
58
tool.py
|
@ -1,9 +1,13 @@
|
||||||
import datetime
|
import datetime
|
||||||
import json
|
import json
|
||||||
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
import requests
|
||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
|
|
||||||
|
mp4_path = '/home/pi/mp4'
|
||||||
|
|
||||||
|
|
||||||
def push_stream():
|
def push_stream():
|
||||||
subprocess.Popen(['/bin/bash start_push.sh'], shell=True)
|
subprocess.Popen(['/bin/bash start_push.sh'], shell=True)
|
||||||
|
@ -24,50 +28,18 @@ def update():
|
||||||
subprocess.Popen(['/bin/bash update.sh'], shell=True)
|
subprocess.Popen(['/bin/bash update.sh'], shell=True)
|
||||||
|
|
||||||
|
|
||||||
def get_list_record(msg, client):
|
def get_list_record():
|
||||||
import os
|
print(os.listdir(mp4_path))
|
||||||
files = []
|
data = {
|
||||||
for filename in os.listdir('mp4'):
|
"data": os.listdir(mp4_path)
|
||||||
# 检查文件名是否符合格式 %Y-%m-%d_%H-%M-%S
|
}
|
||||||
if filename.startswith('2') and '-' in filename and '_' in filename:
|
requests.post("http://shop.lihaink.cn/api/index/file_list", json=data)
|
||||||
# 提取日期和时间
|
|
||||||
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]))
|
|
||||||
files.append(file_time)
|
|
||||||
|
|
||||||
|
|
||||||
def get_record(msg, client):
|
def get_record(msg, client):
|
||||||
import requests
|
filename = json.loads(msg.payload.decode('utf-8'))["data"]
|
||||||
create_time = json.loads(msg.payload.decode('utf-8'))["data"]
|
if filename is None or filename == '':
|
||||||
# create_time = '2023-12-01_19-07-58'
|
client.publish('error', payload='没有该文件', qos=1)
|
||||||
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]))
|
|
||||||
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]))
|
|
||||||
# 比较文件时间和创建时间
|
|
||||||
if file_time == create_time_:
|
|
||||||
file_name_ = filename
|
|
||||||
if file_name_ == '':
|
|
||||||
client.publish('error', payload='没有该文件', qos=0)
|
|
||||||
return
|
return
|
||||||
files = {"file": open(file_name_, 'rb'), "Content-Type": "application/octet-stream"}
|
files = {filename: open(os.path.join(mp4_path, filename), 'rb'), "Content-Type": "application/octet-stream"}
|
||||||
requests.post("https://shop.lihaink.cn/api/upload/image/field", files=files)
|
requests.post("https://shop.lihaink.cn/api/index/upload", files=files)
|
||||||
|
|
Loading…
Reference in New Issue