-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwrite_weather_data.py
More file actions
64 lines (48 loc) · 2.25 KB
/
Copy pathwrite_weather_data.py
File metadata and controls
64 lines (48 loc) · 2.25 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
import asyncio
from datetime import datetime, timezone
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 write_weather_data demo.')
championships_result = await client.get_all_championships(account_id, hh.ApiGetOptions([
'Name',
'Events.Name',
]))
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: ')
# Enter your measurement data here
weather_data = [
hh.ParameterUpdateModel("MeasurementTime", datetime.now(timezone.utc).strftime('%Y-%m-%dT%H:%M:%S.%fZ')[:-4]+'Z'), # e.g. 2024-01-23T11:42:45.083193Z
hh.ParameterUpdateModel("AirTemperature", "13"),
hh.ParameterUpdateModel("TrackTemperature", "30"),
hh.ParameterUpdateModel("WindSpeed", "55"),
hh.ParameterUpdateModel("AmbientMeasurementDataSource", "2"), # 0 = Weather Station; 1 = Manual; 2 = Imported; 3 = Timing Feed
]
print('Writing ambient measurements to selected event...')
weather_result = await client.add_ambient_measurement(
account_id,
event['Id'],
hh.CreateModel(parameter_updates=weather_data))
print(f'add_ambient_measurement result: {weather_result.success}')
print(json.dumps(weather_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())