From e6aecf807ab5a84589648daaddc88f15edf642e0 Mon Sep 17 00:00:00 2001 From: xyj <10908227994@qq.com> Date: Thu, 14 Dec 2023 14:21:17 +0800 Subject: [PATCH] update --- conf/main/common.conf | 4 ++-- create_db.py | 3 +-- delete_than20G.py | 31 +++++++++++++++++-------------- tool.py | 12 +++++++++++- 4 files changed, 31 insertions(+), 19 deletions(-) diff --git a/conf/main/common.conf b/conf/main/common.conf index 891608f..c208843 100644 --- a/conf/main/common.conf +++ b/conf/main/common.conf @@ -3,7 +3,7 @@ host=mqtt.lihaink.cn port=1883 [record] -post_record_list_url=https://shop.lihaink.cn/api/index/file_list -post_record_url=https://shop.lihaink.cn/api/index/upload +post_record_list_url=https://ceshi-iot.lihaink.cn/api/index/file_list +post_record_url=https://ceshi-iot.lihaink.cn/api/index/upload [publish_pwd] value=123456 \ No newline at end of file diff --git a/create_db.py b/create_db.py index 34a50bd..9c37e61 100755 --- a/create_db.py +++ b/create_db.py @@ -3,9 +3,8 @@ import time from api import add from db.base import Base, engine from db.models.lot_data_model import LOT_DATA - -Base.metadata.create_all(bind=engine) try: + Base.metadata.create_all(bind=engine) data = {'ambient_temperature': -1, 'ambient_humidity': -1, 'carbon_dioxide': -1, diff --git a/delete_than20G.py b/delete_than20G.py index 4b3d483..7f8868e 100644 --- a/delete_than20G.py +++ b/delete_than20G.py @@ -8,17 +8,20 @@ folder_path = '/home/pi/mp4' size = 20 # 检查文件夹大小,如果超过20G,则开始删除文件 # 获取当前文件夹的大小 -while True: - 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)] - # 按时间戳排序,取最旧的文件 - oldest_file = min(files_info, key=lambda x: x[0])[1] - # 删除最旧的文件 - os.remove(os.path.join(folder_path, oldest_file)) - # print("删除文件" + oldest_file) - else: - # print("文件夹小于20G") - break - time.sleep(2) +try: + while True: + 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)] + # 按时间戳排序,取最旧的文件 + oldest_file = min(files_info, key=lambda x: x[0])[1] + # 删除最旧的文件 + os.remove(os.path.join(folder_path, oldest_file)) + # print("删除文件" + oldest_file) + else: + # print("文件夹小于20G") + break + time.sleep(2) +except: + pass diff --git a/tool.py b/tool.py index 0cdf696..63bec6f 100755 --- a/tool.py +++ b/tool.py @@ -6,7 +6,14 @@ import requests 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): p = subprocess.Popen(['/bin/bash /home/pi/lot_manager/bash/start_push_stream.sh'], shell=True, @@ -76,7 +83,7 @@ def get_list_record(client): data = { "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) @@ -89,3 +96,6 @@ def get_record(msg, client): files = {filename: open(os.path.join(mp4_path, filename), 'rb'), "Content-Type": "application/octet-stream"} r = requests.post(post_record_url, files=files) client.publish('success', payload=str(r), qos=0) + + +