-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsend.py
46 lines (36 loc) · 1.42 KB
/
send.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import pika
import time
import json
from datetime import datetime
connection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))
channel = connection.channel()
MINS_INTERVAL = 0.004
channel.queue_declare(queue='dataQueue', durable=True)
try:
# while True :
with open('./data/events_int.json', 'r') as f:
events = f.read().strip().split('\n')
for event in events[1:-1]:
if event[-1] == ",":
e = "{" + event[:-1] + "}"
else:
e = "{" + event + "}"
e2 = e
date = e.strip('{"').split('":{"')[0]
values = e2.split('":{"')[1]
datetime_object = datetime.strptime(date, '%Y-%m-%d %H:%M:%S')
ux_date = int(time.mktime(datetime_object.timetuple()))
ux_date += 60*60*2
data = '{"timeday":"'+str(ux_date) + '", "' + values
data = data.replace("}}","}")
message = json.dumps(data)
channel.basic_publish(exchange='',
routing_key='dataQueue',
body=data,
properties=pika.BasicProperties(
delivery_mode=pika.spec.PERSISTENT_DELIVERY_MODE
))
print(" [x] Sent %r" % data)
time.sleep(0.01)
finally:
connection.close()