import os import subprocess import time from watchdog.observers import Observer from watchdog.events import FileSystemEventHandler WATCH_DIR = "/data" # Mount your host directory here class NewBookHandler(FileSystemEventHandler): def on_created(self, event): if event.is_directory: book_dir = event.src_path print(f"New directory detected: {book_dir}") # Run your main.py with the new book directory subprocess.run(["python3", "main.py", "-da", book_dir], check=True) if __name__ == "__main__": observer = Observer() event_handler = NewBookHandler() observer.schedule(event_handler, WATCH_DIR, recursive=True) observer.start() print(f"Watching for new folders in {WATCH_DIR} ...") try: while True: time.sleep(1) except KeyboardInterrupt: observer.stop() observer.join()