Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import json
- import websocket
- # connect to websocket
- socket = "ws://127.0.0.1:9000/ws"
- ws = websocket.WebSocket()
- ws.connect(socket)
- # receive data from websocket until a number is reached
- i, iterations = 0, 100
- # open a file in append mode
- with open("data.txt", "a") as f:
- for i in range(iterations):
- f.write(f"{json.loads(ws.recv())} \n")
- # close the file
- ws.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement