update
This commit is contained in:
parent
955cfa3e2a
commit
e6aecf807a
|
@ -3,7 +3,7 @@
|
||||||
host=mqtt.lihaink.cn
|
host=mqtt.lihaink.cn
|
||||||
port=1883
|
port=1883
|
||||||
[record]
|
[record]
|
||||||
post_record_list_url=https://shop.lihaink.cn/api/index/file_list
|
post_record_list_url=https://ceshi-iot.lihaink.cn/api/index/file_list
|
||||||
post_record_url=https://shop.lihaink.cn/api/index/upload
|
post_record_url=https://ceshi-iot.lihaink.cn/api/index/upload
|
||||||
[publish_pwd]
|
[publish_pwd]
|
||||||
value=123456
|
value=123456
|
|
@ -3,9 +3,8 @@ import time
|
||||||
from api import add
|
from api import add
|
||||||
from db.base import Base, engine
|
from db.base import Base, engine
|
||||||
from db.models.lot_data_model import LOT_DATA
|
from db.models.lot_data_model import LOT_DATA
|
||||||
|
|
||||||
Base.metadata.create_all(bind=engine)
|
|
||||||
try:
|
try:
|
||||||
|
Base.metadata.create_all(bind=engine)
|
||||||
data = {'ambient_temperature': -1,
|
data = {'ambient_temperature': -1,
|
||||||
'ambient_humidity': -1,
|
'ambient_humidity': -1,
|
||||||
'carbon_dioxide': -1,
|
'carbon_dioxide': -1,
|
||||||
|
|
|
@ -8,17 +8,20 @@ folder_path = '/home/pi/mp4'
|
||||||
size = 20
|
size = 20
|
||||||
# 检查文件夹大小,如果超过20G,则开始删除文件
|
# 检查文件夹大小,如果超过20G,则开始删除文件
|
||||||
# 获取当前文件夹的大小
|
# 获取当前文件夹的大小
|
||||||
while True:
|
try:
|
||||||
folder_size = sum(os.path.getsize(f) for f in glob.glob(os.path.join(folder_path, '*')))
|
while True:
|
||||||
if folder_size > size * 1024 * 1024 * 1024: # 检查是否超过20G
|
folder_size = sum(os.path.getsize(f) for f in glob.glob(os.path.join(folder_path, '*')))
|
||||||
# 获取所有文件的时间戳和文件名
|
if folder_size > size * 1024 * 1024 * 1024: # 检查是否超过20G
|
||||||
files_info = [(os.path.getmtime(os.path.join(folder_path, f)), f) for f in os.listdir(folder_path)]
|
# 获取所有文件的时间戳和文件名
|
||||||
# 按时间戳排序,取最旧的文件
|
files_info = [(os.path.getmtime(os.path.join(folder_path, f)), f) for f in os.listdir(folder_path)]
|
||||||
oldest_file = min(files_info, key=lambda x: x[0])[1]
|
# 按时间戳排序,取最旧的文件
|
||||||
# 删除最旧的文件
|
oldest_file = min(files_info, key=lambda x: x[0])[1]
|
||||||
os.remove(os.path.join(folder_path, oldest_file))
|
# 删除最旧的文件
|
||||||
# print("删除文件" + oldest_file)
|
os.remove(os.path.join(folder_path, oldest_file))
|
||||||
else:
|
# print("删除文件" + oldest_file)
|
||||||
# print("文件夹小于20G")
|
else:
|
||||||
break
|
# print("文件夹小于20G")
|
||||||
time.sleep(2)
|
break
|
||||||
|
time.sleep(2)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
12
tool.py
12
tool.py
|
@ -6,7 +6,14 @@ import requests
|
||||||
|
|
||||||
from config import mp4_path, post_record_list_url, post_record_url
|
from config import mp4_path, post_record_list_url, post_record_url
|
||||||
|
|
||||||
|
def exception_handler(func):
|
||||||
|
def wrapper(*args, **kwargs):
|
||||||
|
try:
|
||||||
|
return func(*args, **kwargs)
|
||||||
|
except Exception as e:
|
||||||
|
print(f"函数{func.__name__}中发生了异常:{e}")
|
||||||
|
|
||||||
|
return wrapper
|
||||||
def push_stream(client):
|
def push_stream(client):
|
||||||
p = subprocess.Popen(['/bin/bash /home/pi/lot_manager/bash/start_push_stream.sh'],
|
p = subprocess.Popen(['/bin/bash /home/pi/lot_manager/bash/start_push_stream.sh'],
|
||||||
shell=True,
|
shell=True,
|
||||||
|
@ -76,7 +83,7 @@ def get_list_record(client):
|
||||||
data = {
|
data = {
|
||||||
"data": os.listdir(mp4_path)
|
"data": os.listdir(mp4_path)
|
||||||
}
|
}
|
||||||
r = requests.post(post_record_list_url, data=data)
|
r = requests.post(post_record_list_url, json=data)
|
||||||
client.publish('success', payload=str(r), qos=0)
|
client.publish('success', payload=str(r), qos=0)
|
||||||
|
|
||||||
|
|
||||||
|
@ -89,3 +96,6 @@ def get_record(msg, client):
|
||||||
files = {filename: open(os.path.join(mp4_path, filename), 'rb'), "Content-Type": "application/octet-stream"}
|
files = {filename: open(os.path.join(mp4_path, filename), 'rb'), "Content-Type": "application/octet-stream"}
|
||||||
r = requests.post(post_record_url, files=files)
|
r = requests.post(post_record_url, files=files)
|
||||||
client.publish('success', payload=str(r), qos=0)
|
client.publish('success', payload=str(r), qos=0)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue