Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import pika
- import pyinotify
- import sys
- conn = pika.BlockingConnection(pika.ConnectionParameters(host='192.168.1.100',credentials=pika.PlainCredentials('user', 'password')))
- wm = pyinotify.WatchManager()
- mask = pyinotify.IN_CLOSE_WRITE
- channel = conn.channel()
- print ' [*] Watching for files. To exit press CTRL+C'
- class EventHandler(pyinotify.ProcessEvent):
- def process_IN_CLOSE_WRITE(self, event):
- f = open(event.pathname, 'r')
- m = f.read()
- f.close()
- h = {'name': event.name}
- channel.basic_publish(exchange='test_fanout',routing_key='',body=m,properties=pika.BasicProperties(headers=h))
- handler = EventHandler()
- notifier = pyinotify.Notifier(wm, handler)
- wdd = wm.add_watch('/home/test_source', mask, rec=True)
- notifier.loop()
- conn.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement