base software
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -160,3 +160,6 @@ cython_debug/
|
||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||
#.idea/
|
||||
|
||||
#project specific
|
||||
|
||||
websocket*
|
||||
33
main.py
Normal file
33
main.py
Normal file
@@ -0,0 +1,33 @@
|
||||
import websocket
|
||||
import datetime
|
||||
|
||||
def on_message(ws, message):
|
||||
print("Data received! Writing it to a file")
|
||||
# Generate a timestamp for the filename
|
||||
timestamp = datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
|
||||
filename = f"websocket_{timestamp}.dict"
|
||||
|
||||
with open(filename, "w") as file:
|
||||
file.write(message)
|
||||
print(f"Data written to file {filename}\n")
|
||||
|
||||
def on_error(ws, error):
|
||||
print(f"Error: {error}")
|
||||
|
||||
def on_close(ws, close_status_code, close_msg):
|
||||
print("Connection closed\n")
|
||||
|
||||
def on_open(ws):
|
||||
print("Connection established. Waiting for data...\n")
|
||||
|
||||
def main():
|
||||
websocket_url = "ws://localhost:1100" # Replace with the correct WebSocket URL
|
||||
ws = websocket.WebSocketApp(websocket_url,
|
||||
on_message=on_message,
|
||||
on_error=on_error,
|
||||
on_close=on_close)
|
||||
ws.on_open = on_open
|
||||
ws.run_forever()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user