Return a value from watchdog observer-python

Skip to first unread message

Aug 23, 2018, 11:57:05 AM8/23/18
to watchdog-python
I am using watchdog for watching a directory for any changes for instance when a new image is added to the directory I want to trigger a function on the main class.
import time
from watchdog.observers import Observer
from import FileSystemEventHandler, LoggingEventHandler

# from config import LOCAL_PATH_TO_WATCHER
import os 
LOCAL_PATH_TO_WATCHER = '/path/to/dir/'
class Watcher:
    def __init__(self): = Observer()

    def run(self):
        event_handler = Event(), path =LOCAL_PATH_TO_WATCHER, recursive=True)
            while True:
            print ("Error")

class Event(LoggingEventHandler):

  def dispatch(self, event):
      if event.is_directory:
          return None
      elif event.event_type == 'created':
          return event.src_path

Now i want to initialize a Watcher object and trigger the function in my main file.

from watcher import Watcher

def crop(img):
  # some implementation

if __name__ == '__main__':
    # This will run the pipeline file for the first time.
    w = Watcher()

I want to access the image from watcher object's dispatch function to run crop function in the main file

Reply all
Reply to author
0 new messages