37 lines
709 B
Python
37 lines
709 B
Python
import jsonlines
|
|
import zmq
|
|
import tqdm
|
|
import random
|
|
import sys
|
|
import time
|
|
import json
|
|
|
|
port = "99174"
|
|
if len(sys.argv) > 1:
|
|
port = sys.argv[1]
|
|
int(port)
|
|
|
|
if len(sys.argv) > 2:
|
|
fn = sys.argv[2]
|
|
else:
|
|
fn = "messages.jsonl"
|
|
|
|
context = zmq.Context()
|
|
socket = context.socket(zmq.PUB)
|
|
socket.bind("tcp://*:%s" % port)
|
|
|
|
topic = ''
|
|
|
|
first = True
|
|
|
|
with jsonlines.open(fn) as reader:
|
|
for obj in tqdm.tqdm(reader):
|
|
# skip delay for first
|
|
offset = 0 if first else obj['offset']
|
|
first = False
|
|
|
|
time.sleep(offset)
|
|
msg = obj['data']
|
|
# print(f"{topic} {json.dumps(msg)}")
|
|
socket.send_string(f"{topic} {json.dumps(msg)}")
|
|
# time.sleep(1)
|