daily pastebin goal
73%
SHARE
TWEET

Untitled

a guest Feb 23rd, 2019 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python
  2. import pika
  3. import pyinotify
  4. import sys
  5.  
  6. conn = pika.BlockingConnection(pika.ConnectionParameters(host='192.168.1.100',credentials=pika.PlainCredentials('user', 'password')))
  7. wm = pyinotify.WatchManager()
  8. mask = pyinotify.IN_CLOSE_WRITE
  9. channel = conn.channel()
  10.  
  11. print ' [*] Watching for files. To exit press CTRL+C'
  12.  
  13. class EventHandler(pyinotify.ProcessEvent):
  14.     def process_IN_CLOSE_WRITE(self, event):
  15.         f = open(event.pathname, 'r')
  16.         m = f.read()
  17.         f.close()
  18.         h = {'name': event.name}
  19.         channel.basic_publish(exchange='test_fanout',routing_key='',body=m,properties=pika.BasicProperties(headers=h))
  20.  
  21. handler = EventHandler()
  22. notifier = pyinotify.Notifier(wm, handler)
  23. wdd = wm.add_watch('/home/test_source', mask, rec=True)
  24.  
  25. notifier.loop()
  26. conn.close()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top