lot_manager/tool.py

72 lines
2.9 KiB
Python
Raw Normal View History

2023-12-02 19:24:31 +08:00
import datetime
2023-12-02 10:53:31 +08:00
import json
import subprocess
2023-12-02 19:24:31 +08:00
from fastapi import FastAPI
2023-12-02 10:53:31 +08:00
def push_stream():
subprocess.Popen(['/bin/bash start_push.sh'], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
def close_stream():
subprocess.Popen(['/bin/bash stop_push.sh'], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
def exec_sh(msg):
cmd = json.loads(msg.payload.decode('utf-8'))["data"]
subprocess.Popen([cmd], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
def update():
subprocess.Popen(['/bin/bash update.sh'], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
2023-12-02 18:32:17 +08:00
2023-12-02 20:00:27 +08:00
def get_list_record(msg, client):
import os
files = []
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]))
files.append(file_time)
2023-12-02 19:24:31 +08:00
def get_record(msg, client):
import requests
create_time = json.loads(msg.payload.decode('utf-8'))["data"]
2023-12-02 20:00:27 +08:00
# create_time = '2023-12-01_19-07-58'
2023-12-02 19:24:31 +08:00
import os
2023-12-02 20:00:27 +08:00
create_time_date_str = create_time.split('_')[0]
create_time_time_str = create_time.split('_')[1]
2023-12-02 19:24:31 +08:00
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]),
2023-12-02 19:51:55 +08:00
int(create_time_time_str[3:5]))
2023-12-02 19:24:31 +08:00
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]),
2023-12-02 19:51:55 +08:00
int(time_str[3:5]))
2023-12-02 19:24:31 +08:00
# 比较文件时间和创建时间
2023-12-02 19:52:06 +08:00
if file_time == create_time_:
2023-12-02 19:24:31 +08:00
file_name_ = filename
if file_name_ == '':
client.publish('error', payload='没有该文件', qos=0)
return
files = {"file": open(file_name_, 'rb'), "Content-Type": "application/octet-stream"}
2023-12-02 19:46:53 +08:00
requests.post("https://shop.lihaink.cn/api/upload/image/field", files=files)