lot_manager/tool.py

43 lines
1.1 KiB
Python
Raw Normal View History

2023-12-02 10:53:31 +08:00
import json
2023-12-04 13:22:54 +08:00
import os
2023-12-02 10:53:31 +08:00
import subprocess
2023-12-04 13:22:54 +08:00
import requests
2023-12-02 19:24:31 +08:00
2023-12-04 13:22:54 +08:00
mp4_path = '/home/pi/mp4'
2023-12-02 10:53:31 +08:00
def push_stream():
2023-12-04 10:08:22 +08:00
subprocess.Popen(['/bin/bash start_push.sh'], shell=True)
2023-12-02 10:53:31 +08:00
def close_stream():
2023-12-04 10:08:22 +08:00
subprocess.Popen(['/bin/bash stop_push.sh'], shell=True)
2023-12-02 10:53:31 +08:00
def exec_sh(msg):
cmd = json.loads(msg.payload.decode('utf-8'))["data"]
2023-12-04 10:05:04 +08:00
if cmd == "supervisorctl stop __mqtt__":
return
2023-12-02 10:53:31 +08:00
subprocess.Popen([cmd], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
def update():
2023-12-04 10:08:22 +08:00
subprocess.Popen(['/bin/bash update.sh'], shell=True)
2023-12-02 18:32:17 +08:00
2023-12-04 13:22:54 +08:00
def get_list_record():
data = {
"data": os.listdir(mp4_path)
}
requests.post("http://shop.lihaink.cn/api/index/file_list", json=data)
2023-12-02 20:00:27 +08:00
2023-12-02 19:24:31 +08:00
def get_record(msg, client):
2023-12-04 13:22:54 +08:00
filename = json.loads(msg.payload.decode('utf-8'))["data"]
if filename is None or filename == '':
client.publish('error', payload='没有该文件', qos=1)
2023-12-02 19:24:31 +08:00
return
2023-12-04 13:22:54 +08:00
files = {filename: open(os.path.join(mp4_path, filename), 'rb'), "Content-Type": "application/octet-stream"}
requests.post("https://shop.lihaink.cn/api/index/upload", files=files)