ws version with nice DB select

This commit is contained in:
erik 2025-05-09 22:35:41 +00:00
parent a121d57a13
commit 73ae756e5c
6 changed files with 491 additions and 106 deletions

View file

@ -1,45 +1,45 @@
import httpx
import asyncio
import websockets
import json
from datetime import datetime, timedelta, timezone
from time import sleep
from main import TelemetrySnapshot
def main() -> None:
async def main() -> None:
wait = 10
online_time = 24 * 3600 # start at 1 day
ew = 0
ns = 0
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=0,
prismatic_taper_count=0,
vt_state="test state",
)
resp = httpx.post(
"http://localhost:8000/position/",
data=snapshot.model_dump_json(),
headers={
"Content-Type": "application/json",
"X-PLUGIN-SECRET": "your_shared_secret",
},
)
print(resp)
sleep(wait)
ew += 0.1
ns += 0.1
online_time += wait
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=0,
prismatic_taper_count=0,
vt_state="test state",
)
# wrap in envelope with message type
payload = snapshot.model_dump()
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__":
main()
asyncio.run(main())