-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_client.py
More file actions
41 lines (35 loc) · 874 Bytes
/
test_client.py
File metadata and controls
41 lines (35 loc) · 874 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
33
34
35
36
37
38
39
40
41
import time
import numpy as np
import datetime
import requests
import json
i = 0
while(1):
i += 1
all_updates = {
"time": str(datetime.datetime.now()),
"field1": "test",
"iteration": i,
"random number": np.random.random(),
"sine": np.cos(2*np.pi*i/2)
}
if (i % 2 == 0):
del all_updates["field1"]
request = []
now = datetime.datetime.now()
for k, v in all_updates.items():
request.append({
"id": k,
"value": v,
"timestamp": now.timestamp(),
})
try:
print(request)
r = requests.post(
"http://localhost:5000/update",
data=json.dumps(request, default=str))
print(r.status_code)
print(r.json())
except BaseException:
print("no server")
time.sleep(4*np.random.random())