-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_ship.py
51 lines (40 loc) · 1.25 KB
/
check_ship.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
import json
import time
from src.client import ApiError, SpaceTradersClient
def print_response(response):
print(json.dumps(response, indent=2))
try:
client = SpaceTradersClient()
ship_symbol = "TRADER-BOT-001-1"
target = "X1-MY38-ZB5Z"
# Put ship in orbit
print("\nPutting ship in orbit...")
orbit_result = client.orbit_ship(ship_symbol)
print("Orbit response:")
print_response(orbit_result)
# Wait a moment for status to update
time.sleep(1)
# Set flight mode to CRUISE
print("\nSetting flight mode to CRUISE...")
nav_update = client._make_request(
"PATCH", f"my/ships/{ship_symbol}/nav", {"flightMode": "CRUISE"}
)
print("Flight mode response:")
print_response(nav_update)
# Wait a moment for status to update
time.sleep(1)
# Navigate to asteroid
print(f"\nNavigating to {target}...")
nav_result = client.navigate_ship(ship_symbol, target)
print("Navigation response:")
print_response(nav_result)
except ApiError as e:
print(f"\nAPI Error: {str(e)}")
try:
error_data = json.loads(str(e))
print("Error details:")
print_response(error_data)
except:
pass
except Exception as e:
print(f"\nUnexpected error: {str(e)}")