2016-02-04 15:22:51 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
import zmq
|
|
|
|
import base64
|
|
|
|
import argparse
|
|
|
|
import os
|
2016-03-11 16:16:53 +01:00
|
|
|
import time
|
2016-02-04 15:22:51 +01:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
parser = argparse.ArgumentParser(description='Take files from a directory and push them into a 0MQ feed.')
|
|
|
|
parser.add_argument('-d', '--directory', type=str, required=True, help='Root directory to import')
|
|
|
|
parser.add_argument('-p', '--port', type=int, default=5556, help='Zero MQ port')
|
|
|
|
parser.add_argument('-c', '--channel', type=str, default='102', help='Zero MQ channel')
|
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
context = zmq.Context()
|
|
|
|
socket = context.socket(zmq.PUB)
|
|
|
|
socket.bind("tcp://*:{}".format(args.port))
|
2017-07-17 16:14:27 +02:00
|
|
|
time.sleep(1) #Important, avoid loosing the 1 message
|
2016-02-04 15:22:51 +01:00
|
|
|
|
|
|
|
for dirname, dirnames, filenames in os.walk(args.directory):
|
|
|
|
for filename in filenames:
|
|
|
|
messagedata = open(os.path.join(dirname, filename)).read()
|
|
|
|
print(os.path.join(dirname, filename))
|
2017-08-03 00:34:53 +02:00
|
|
|
socket.send('{} {} {}'.format(args.channel, os.path.join(dirname, filename), base64.b64encode(messagedata)))
|
2017-07-17 16:14:27 +02:00
|
|
|
time.sleep(.2)
|