Created
February 5, 2021 09:03
-
-
Save 8wgf3b/2d0e998503fa9e53a2507d172888f144 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import websockets | |
import json | |
import asyncio | |
uri = "ws://localhost:5511" | |
async def subscribe(*args): | |
async with websockets.connect(uri) as websocket: | |
# subcription | |
submsg = f"sub . (`gendata; `{'`'.join(args)})" | |
await websocket.send(submsg) | |
# updates | |
while True: | |
json_string = await websocket.recv() | |
data = json.loads(json_string) | |
print(data) | |
asyncio.get_event_loop().run_until_complete(subscribe("A", "B")) | |
# asyncio.run(subscribe("A", "B")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment