-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprev_recieve.py
More file actions
32 lines (27 loc) · 876 Bytes
/
prev_recieve.py
File metadata and controls
32 lines (27 loc) · 876 Bytes
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
import time
import zmq
import pickle
"""
The reciever must already be running before the sender is started
"""
#the function that recieves data
#saves incoming dictionary as "data"
def consumer():
print("Reciever is operational")
context = zmq.Context()
# recieve work
consumer_receiver = context.socket(zmq.PULL)
consumer_receiver.connect("tcp://129.118.107.227:5559")
data = consumer_receiver.recv_json()
print("Recieved data from weather station {} at time {}:{}".format(data['idnum'],data['timestamp'][4],data['timestamp'][5]))
return data
#initialize a list of dictonaries
datalist = []
#set the number of data collections before saving
#run the collections
for i in range(2):
data = consumer()
datalist.append(data)
#pickle the data list
with open('weather.pkl', 'wb') as savefile:
pickle.dump(datalist, savefile)