base software

This commit is contained in:
ovosimpatico
2023-10-09 16:02:41 -03:00
parent 8c543e105a
commit cd8cdf7f0d
2 changed files with 36 additions and 0 deletions

3
.gitignore vendored
View File

@@ -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
View 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()