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()