bigchungusdata/zmq/consumer.py

30 lines
661 B
Python
Raw Normal View History

2021-04-25 12:16:11 +02:00
#!/usr/bin/env python3
from datetime import datetime
import zmq
DATETIMES=[]
context = zmq.Context()
socket = context.socket(zmq.SUB)
socket.connect("tcp://127.0.0.1:5559")
socket.setsockopt_string(zmq.SUBSCRIBE, "test")
try:
while True:
m = socket.recv_string()
DATETIMES.append(datetime.now())
2021-04-25 12:24:41 +02:00
except KeyboardInterrupt:
2021-04-25 12:16:11 +02:00
socket.close()
2021-04-25 13:02:15 +02:00
dt = {}
for datetime in DATETIMES:
dts = datetime.strftime("%m/%d/%Y, %H:%M:%S")
if dts not in dt:
dt[strftime("%m/%d/%Y, %H:%M:%S")] = 1
else:
dt[strftime("%m/%d/%Y, %H:%M:%S")] +=1
2021-04-25 13:03:26 +02:00
for key, value in dt:
print(key,",",value)