47 lines
1.6 KiB
Python
47 lines
1.6 KiB
Python
import asyncio
|
|
import websockets
|
|
import json
|
|
from datetime import datetime, timedelta, timezone
|
|
from main import TelemetrySnapshot
|
|
|
|
|
|
async def main() -> None:
|
|
wait = 10
|
|
online_time = 24 * 3600 # start at 1 day
|
|
ew = 0.0
|
|
ns = 0.0
|
|
uri = "ws://localhost:8000/ws/position?secret=your_shared_secret"
|
|
async with websockets.connect(uri) as websocket:
|
|
print(f"Connected to {uri}")
|
|
while True:
|
|
snapshot = TelemetrySnapshot(
|
|
character_name="Test name",
|
|
char_tag="test_tag",
|
|
session_id="test_session_id",
|
|
timestamp=datetime.now(tz=timezone.utc),
|
|
ew=ew,
|
|
ns=ns,
|
|
z=0,
|
|
kills=0,
|
|
kills_per_hour="kph_str",
|
|
onlinetime=str(timedelta(seconds=online_time)),
|
|
deaths=0,
|
|
# rares_found removed from telemetry payload; tracked via rare events
|
|
prismatic_taper_count=0,
|
|
vt_state="test state",
|
|
)
|
|
# wrap in envelope with message type
|
|
# Serialize telemetry snapshot without telemetry.kind 'rares_found'
|
|
payload = snapshot.model_dump()
|
|
payload.pop("rares_found", None)
|
|
payload["type"] = "telemetry"
|
|
await websocket.send(json.dumps(payload, default=str))
|
|
print(f"Sent snapshot: EW={ew:.2f}, NS={ns:.2f}")
|
|
await asyncio.sleep(wait)
|
|
ew += 0.1
|
|
ns += 0.1
|
|
online_time += wait
|
|
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(main())
|