Spaces:
Paused
Paused
Download scripts/ws_client.py from 3SCError404/nexus: direct link, hf CLI and curl.
- Browser
- Download file 874 Bytes
-
https://huggingface.co/spaces/3SCError404/nexus/resolve/main/scripts/ws_client.py
- Command line
-
hf download hf://spaces/3SCError404/nexus/scripts/ws_client.py
-
curl -L -o ws_client.py https://huggingface.co/spaces/3SCError404/nexus/resolve/main/scripts/ws_client.py
874 Bytes
| import asyncio | |
| import websockets | |
| import json | |
| import sys | |
| async def test_ws(url, token, expected_event): | |
| print(f"Connecting to {url}...") | |
| try: | |
| async with websockets.connect(url + f"?token={token}") as websocket: | |
| print("WS Connected. Waiting for event...") | |
| while True: | |
| message = await websocket.receive() | |
| data = json.loads(message) | |
| print(f"Received: {data}") | |
| if data.get("event") == expected_event: | |
| print("SUCCESS: Event received.") | |
| return | |
| except Exception as e: | |
| print(f"WS Error: {e}") | |
| sys.exit(1) | |
| if __name__ == "__main__": | |
| if len(sys.argv) < 4: | |
| print("Usage: python ws_client.py <url> <token> <expected_event>") | |
| sys.exit(1) | |
| asyncio.run(test_ws(sys.argv[1], sys.argv[2], sys.argv[3])) | |