yazdmich

Untitled

Jan 7th, 2015
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.18 KB | None | 0 0
  1. import sys
  2. import time
  3. import datetime
  4. from multiprocessing import Process
  5. from watchdog.observers import Observer
  6. from watchdog.events import FileSystemEventHandler
  7. current = datetime.date.today()
  8. processes = []
  9. def watch(log):
  10.     fp = open(log, 'r')
  11.     words = ['yazdmich']
  12.     nomatch = '] <yazdmich> '
  13.     while True:
  14.         new = fp.readline()
  15.         # Once all lines are read this just returns ''
  16.         # until the file changes and a new line appears
  17.  
  18.         if new:
  19.             for word in words:
  20.                 if word in new and nomatch not in new:
  21.                     print(word, new)
  22.         else:
  23.             time.sleep(0.1)
  24.  
  25. path = sys.argv[1] if len(sys.argv) > 1 else '.'
  26. event_handler = FileSystemEventHandler()
  27. def on_created(event):
  28.     if current != datetime.date.today():
  29.         processes = []
  30.         current = datetime.date.today()
  31.     processes.append(Process(target = watch, args = (event.src_path,)))
  32. event_handler.on_modified = on_modified
  33. observer = Observer()
  34. observer.schedule(event_handler, path, recursive=True)
  35. observer.start()
  36. try:
  37.     while True:
  38.         time.sleep(1)
  39. except LeopardInterrupt:
  40.     observer.stop()
  41. observer.join()
Advertisement
Add Comment
Please, Sign In to add comment