-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
33 lines (27 loc) · 977 Bytes
/
app.py
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
import os
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
import time
import logging
LOGGER = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
class ChangeHandler(FileSystemEventHandler):
def on_created(self, event):
LOGGER.info(f'File {event.src_path} has been created')
def on_modified(self, event):
LOGGER.info(f'File {event.src_path} has been modified')
def on_deleted(self, event):
LOGGER.info(f'File {event.src_path} has been deleted')
if __name__ == "__main__":
LOGGER.info("Starting file monitor ...")
path = os.getenv('MONITOR_DIR')
event_handler = ChangeHandler()
observer = Observer()
observer.schedule(event_handler, path, recursive=True)
observer.start()
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
observer.stop()
observer.join()