-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathget_setups.py
More file actions
54 lines (39 loc) · 1.79 KB
/
Copy pathget_setups.py
File metadata and controls
54 lines (39 loc) · 1.79 KB
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
import asyncio
import json
import hhdm_apiclient_wrapper as hh
async def main():
api_key = 'YOUR_API_KEY'
account_id = 'YOUR_ACCOUNT_ID'
auth_settings = hh.AuthenticationSettings(
api_key=api_key,
authentication_mode=hh.AuthenticationMode.API_KEY,
)
client = hh.ApiClient(authentication_manager=hh.AuthenticationManager(auth_settings))
print(f'Api client wrapper v{client.get_version()}. Running get_setups demo.')
championships_result = await client.get_all_championships(account_id, hh.ApiGetOptions([
'*',
'Events.*',
'Events.Cars.*',
'Events.Cars.Car.*'
]))
if not championships_result.success:
print(f'Failed to get championship information: {championships_result.message}')
return
championship = get_named_input(championships_result.return_value, 'Select a championship: ')
event = get_named_input(championship['Events'], 'Select an event: ')
car = get_named_input(event['Cars'], 'Select a car: ', lambda x: x['Parameters']['Car']['Parameters']['Number'])
car_id = car['Parameters']['CarId']
setups_result = await client.get_all_setups_for_event_car(account_id, event['Id'], car_id, hh.ApiGetOptions(['*']))
print(f'get_all_setups_for_event_car result: {setups_result.success}')
print(json.dumps(setups_result.return_value, indent=4))
await client.close()
def get_named_input(items, prompt, name_accessor=lambda x: x['Parameters']['Name']):
if len(items) == 0:
print('No entities were found.')
return None
print('\n'.join([f"{i+1}) {name_accessor(item)}" for (i, item) in enumerate(items)]))
idx = int(input(prompt)) - 1
print(f'You selected "{name_accessor(items[idx])}"\n')
return items[idx]
if __name__ == '__main__':
asyncio.run(main())