Skip to content

Instantly share code, notes, and snippets.

@nuria
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nuria/e837d16b94c09a4df8a4 to your computer and use it in GitHub Desktop.
Save nuria/e837d16b94c09a4df8a4 to your computer and use it in GitHub Desktop.
Cats a file to a tcp endpoint line by line using streams and zeromq
#!/usr/local/bin
import zmq
import io
import time
import sys
import re
# reads line by line a file and sends it
# to a tcp endpoint using zeromq
# handy to cat big files to a listener
context = zmq.Context()
socket = context.socket(zmq.PUB)
socket.bind("tcp://127.0.0.1:8473")
fileName = sys.argv[1]
with io.open(fileName, 'r') as file:
l = file.readline()
while True and l !='':
l1 = l.replace('"','')
l2 = re.sub(r'\\t',' ', l1)
l3 = re.sub(r'\\n', '', l2)
time.sleep(0.01)
#print l3.rstrip('\n')
socket.send_unicode(l3.rstrip('\n'))
l = file.readline()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment