-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi_client.py
122 lines (113 loc) · 3.46 KB
/
api_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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
from gql import gql, Client
from gql.transport.requests import RequestsHTTPTransport
class BigBotherAPIClient(object):
def __init__(self):
http_transport = RequestsHTTPTransport(
'https://bigbother.oliviervg.com/graphql', use_json=True
)
self.client = Client(
transport=http_transport, fetch_schema_from_transport=True
)
def list_people(self):
query = gql('''
query {
allPeople {
edges {
node {
fullName
}
}
}
}
''')
response = self.client.execute(query)
return [
edge['node']["fullName"] for edge in response["allPeople"]["edges"]
]
def list_rooms(self):
query = gql('''
query {
allRooms {
edges {
node {
name
city
}
}
}
}
''')
response = self.client.execute(query)
return [
edge['node'] for edge in response["allRooms"]["edges"]
]
def find_person_by_name(self, full_name):
query = gql('''
query {{
findPersonByName(name: "{full_name}") {{
fullName
lastSeen
rekognitionFaceId
room {{
name
city
}}
}}
}}
'''.format(full_name=full_name))
response = self.client.execute(query)
assert len(response['findPersonByName']) == 1, 'Person not found...'
return response['findPersonByName'][0]
def find_person_by_face_id(self, face_id):
query = gql('''
query {{
findPersonByFaceId(rekognitionFaceId: "{face_id}") {{
fullName
lastSeen
rekognitionFaceId
room {{
name
city
}}
}}
}}
'''.format(face_id=face_id))
response = self.client.execute(query)
return response['findPersonByFaceId']
def list_people_in_room(self, room_name, room_city):
query = gql('''
query {{
findRoom(room: {{name: "{name}", city: "{city}"}}) {{
people {{
edges {{
node {{
fullName
lastSeen
}}
}}
}}
}}
}}
'''.format(name=room_name, city=room_city))
response = self.client.execute(query)
return [
edge['node']['fullName']
for edge in response['findRoom']['people']['edges']
]
def update_person_location(self, full_name, room_name, room_city):
mutation = gql('''
mutation {{
updatePerson(input: {{fullName: "{full_name}", roomName: "{room_name}", roomCity: "{room_city}"}}) {{
person {{
fullName
lastSeen
room {{
name
city
}}
}}
}}
}}
'''.format(full_name=full_name, room_name=room_name, room_city=room_city))
response = self.client.execute(mutation)
return response["updatePerson"]["person"]