-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestclient.py
44 lines (37 loc) · 992 Bytes
/
testclient.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
import sys
sys.path.insert(0, 'interop/client')
import time
import zmq
import interop
import concurrent.futures
import json
def toJSON(mission):
lst = list()
for el in mission:
lst.append(json.dumps(el, default=lambda o: o.__dict__, sort_keys=True, indent = 4))
return json.dumps(lst)
def main():
if (len(sys.argv) < 3):
print("Usage: testclient.py username password")
exit()
user = sys.argv[1]
password = sys.argv[2]
client = interop.AsyncClient("http://localhost:8000", \
user, password, \
timeout=10, workers = 8)
context = zmq.Context()
publisher = context.socket(zmq.PUSH)
publisher.bind("tcp://*:5563")
futures = list()
futures.append(client.get_missions())
for future in concurrent.futures.as_completed(futures):
try:
while True:
mission = toJSON(future.result())
publisher.send_json(mission)
print
time.sleep(1)
except Exception as exc:
print('generated exception %s' %(exc))
if __name__ == "__main__":
main()