-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathget_run_setups.py
More file actions
77 lines (60 loc) · 2.5 KB
/
Copy pathget_run_setups.py
File metadata and controls
77 lines (60 loc) · 2.5 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
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_run_setups demo.')
championships_result = await client.get_all_championships(account_id, hh.ApiGetOptions([
'*',
'Events.*',
'Events.Cars.*',
'Events.Cars.Car.*',
'Events.Sessions.*',
]))
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: ')
session = get_named_input(event['Sessions'], 'Select a session: ')
cars = []
for c in event['Cars']:
car_id = c['Parameters']['CarId']
car_num = c['Parameters']['Car']['Parameters']['Number']
result = await client.get_all_run_sheets_for_session_car(account_id, session['Id'], car_id, hh.ApiGetOptions(['*', 'Setup.*']))
if not result.success:
print(f"Failed to get run information for car {car_num}: {result.message}")
cars.append({
"Id": car_id,
"Number": car_num,
"Errored": True,
"Runs": []
})
else:
cars.append({
"Id": car_id,
"Number": car_num,
"Runs": result.return_value
})
car = get_named_input(cars, 'Select a car: ', lambda x: f"{x['Number']} ({str(len(x['Runs'])) + ' runs' if 'Errored' not in x else 'Errored'})")
run_setups = []
for run in car['Runs']:
run_setups.append(run['Parameters']['Setup'])
print(json.dumps(run_setups, indent=2))
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())