You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

47 lines
984 B

import time
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
class MyHandler(FileSystemEventHandler):
def __init__(self, function):
self.function = function
def on_any_event(self, _event):
# Handle the event (e.g., file created, modified, deleted)
self.function()
class FileWatchdog:
def __init__(self, path):
self.path = path
self.time = 0
event_handler = MyHandler(lambda: self.event_handler())
self.observer = Observer()
self.observer.schedule(event_handler, path, recursive=True)
self.observer.start()
def event_handler(self):
#print("change detected")
self.time = time.time()
def stop(self):
self.observer.stop()
if __name__ == "__main__":
wdt = FileWatchdog("./web")
try:
while True:
time.sleep(1)
print(wdt.time)
except KeyboardInterrupt:
wdt.stop()