-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.py
61 lines (50 loc) · 1.33 KB
/
client.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import unter_pb2 as pb
import unter_pb2_grpc as rpc
import grpc
from time import sleep
def start():
req = pb.StartRideRequest(
id='red5',
kind=pb.KIND_SHARED,
driver_id='C3-PO',
)
req.time.GetCurrentTime()
with grpc.insecure_channel('localhost:9876') as ch:
client = rpc.UnterStub(ch)
try:
# resp = client.StartRide(req)
resp = client.StartRide(
req,
metadata=(
('token', 'C-3PO'),
),
)
except grpc.RpcError as err:
code = err.code().name
details = err.details()
print(f'error: {details} ({code})')
# state = err.args[0]
# print(state.target, state.method)
# print(err.code())
return
print(resp.id)
def iter_locs():
lat, lng = 28.5244425,-16.38491
for _ in range(5):
lat -= 0.0001
lng += 0.0001
loc = pb.Location(
ride_id='red5',
lat=lat,
lng=lng,
)
yield loc
sleep(0.7) # Simulate work
def track():
with grpc.insecure_channel('localhost:9876') as ch:
client = rpc.UnterStub(ch)
resp = client.Track(iter_locs())
print(resp)
if __name__ == '__main__':
start()
track()