CoolFace
Apppublic

121Mauricio/IO-AI

sourceHugging Faceapache-2.0updated 1y agoView on Hugging Face
0likes
io-watcher.py36 linesDownload Raw Back to root
1import time2from watchdog.observers import Observer3from watchdog.events import FileSystemEventHandler4 5# Le point '.' indique que l'on surveille le dossier actuel6PATH_TO_WATCH = "."7 8class IOEventHandler(FileSystemEventHandler):9    """10    Gère les événements de fichiers.11    """12    def on_modified(self, event):13        if not event.is_directory and event.src_path.endswith('.py'):14            print(f"\nIO > Je vois que tu as modifié le fichier : {event.src_path}. Laisse-moi y jeter un œil...")15            16            with open(event.src_path, 'r') as file:17                content = file.read()18                if 'print()' in content:19                    print("IO > Attention, un 'print()' vide ? C'est le genre d'erreur que j'aurais pu éviter...")20                if 'def ' in content and 'main' in content:21                    print("IO > Ah, une fonction 'main'. Classique. Faisons mieux la prochaine fois ?")22 23# Lancement de l'observateur24if __name__ == "__main__":25    observer = Observer()26    event_handler = IOEventHandler()27    observer.schedule(event_handler, PATH_TO_WATCH, recursive=True)28    print("IO > Je suis en veille. N'hésite pas à me faire travailler en modifiant un fichier Python...")29    observer.start()30    try:31        while True:32            time.sleep(1)33    except KeyboardInterrupt:34        observer.stop()35    observer.join()36