Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- import time
- import datetime
- from multiprocessing import Process
- from watchdog.observers import Observer
- from watchdog.events import FileSystemEventHandler
- current = datetime.date.today()
- processes = []
- def watch(log):
- fp = open(log, 'r')
- words = ['yazdmich']
- nomatch = '] <yazdmich> '
- while True:
- new = fp.readline()
- # Once all lines are read this just returns ''
- # until the file changes and a new line appears
- if new:
- for word in words:
- if word in new and nomatch not in new:
- print(word, new)
- else:
- time.sleep(0.1)
- path = sys.argv[1] if len(sys.argv) > 1 else '.'
- event_handler = FileSystemEventHandler()
- def on_created(event):
- if current != datetime.date.today():
- processes = []
- current = datetime.date.today()
- processes.append(Process(target = watch, args = (event.src_path,)))
- event_handler.on_modified = on_modified
- observer = Observer()
- observer.schedule(event_handler, path, recursive=True)
- observer.start()
- try:
- while True:
- time.sleep(1)
- except LeopardInterrupt:
- observer.stop()
- observer.join()
Advertisement
Add Comment
Please, Sign In to add comment