Advertisement
elsheikh21

Untitled

May 11th, 2023
453
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.39 KB | Software | 0 0
  1. import json
  2.  
  3. import websocket
  4.  
  5. # connect to websocket
  6. socket = "ws://127.0.0.1:9000/ws"
  7. ws = websocket.WebSocket()
  8. ws.connect(socket)
  9.  
  10. # receive data from websocket until a number is reached
  11. i, iterations = 0, 100
  12.  
  13. # open a file in append mode
  14. with open("data.txt", "a") as f:
  15.     for i in range(iterations):
  16.         f.write(f"{json.loads(ws.recv())} \n")
  17.  
  18. # close the file
  19. ws.close()
  20.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement