Spaces:
Running
Running
File size: 1,058 Bytes
39f384e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
import sys
import os
import time
import threading
import shutil
import logging
now_dir = os.getcwd()
sys.path.append(now_dir)
logging.basicConfig(level=logging.DEBUG)
def clear_folders():
folders_to_clear = ["logs", "audios"]
for folder_name in folders_to_clear:
folder_path = os.path.join(os.getcwd(), folder_name)
try:
for item in os.listdir(folder_path):
item_path = os.path.join(folder_path, item)
if folder_name == "logs" and os.path.isdir(item_path):
shutil.rmtree(item_path)
elif os.path.isfile(item_path):
os.remove(item_path)
except OSError as e:
logging.error(f"Error clearing {folder_name}: {e}")
def infinite_loop():
while True:
clear_folders()
wait_time = 24 * 60 * 60
logging.info(f"Sleeping for {wait_time} seconds")
time.sleep(wait_time)
def start_infinite_loop():
bucle = threading.Thread(target=infinite_loop)
bucle.daemon = True
bucle.start() |