Advertisement
BlastFM

garbage

Apr 26th, 2022
878
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.51 KB | None | 0 0
  1. import asyncio
  2. import websockets
  3.  
  4. URI = ""
  5. TOKEN = ""
  6. data = []
  7.  
  8. async def connect():
  9.     global socket
  10.     socket = await websockets.connect(URI)
  11.     msg = TOKEN
  12.     await socket.send(msg)
  13.    
  14.  
  15. async def listen():
  16.     msg = await socket.recv()
  17.     if msg["kind"]!="data":
  18.         output = {"root":data}
  19.         # save to a file
  20.         print(output)
  21.         await socket.stop()
  22.     else:
  23.         data.append(msg["payload"])
  24.  
  25.  
  26. asyncio.run(connect())
  27. asyncio.get_event_loop().run_forever(listen())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement