From e8d230b31a705f630e05f72fff85e0ba97808728 Mon Sep 17 00:00:00 2001 From: hornet Date: Tue, 9 Nov 2021 15:14:06 -0500 Subject: [PATCH] Now loads config from YAMl --- src/client/cli.py | 12 ++++++++++-- src/client/test_config.yaml | 3 +++ 2 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 src/client/test_config.yaml diff --git a/src/client/cli.py b/src/client/cli.py index ae0d7ae..074ebe1 100644 --- a/src/client/cli.py +++ b/src/client/cli.py @@ -2,6 +2,7 @@ import websocket import _thread import time import ssl +import yaml def on_message(ws, message): print(f"<< {message}") @@ -24,11 +25,18 @@ def on_open(ws): ws.close() _thread.start_new_thread(run, ()) -if __name__ == "__main__": +def open_socket(url, port): websocket.enableTrace(True) - ws = websocket.WebSocketApp("ws://localhost:6873", + ws = websocket.WebSocketApp(f"ws://{url}:{port}", on_open=on_open, on_message=on_message, on_error=on_error, on_close=on_close) ws.run_forever(sslopt={"cert_reqs": ssl.CERT_NONE}) + + +if __name__ == "__main__": + with open('config.yaml', 'r') as f: + conf = yaml.safe_load(f) + open_socket(conf['ws']['url'], conf['ws']['port']) + diff --git a/src/client/test_config.yaml b/src/client/test_config.yaml new file mode 100644 index 0000000..23ac0a0 --- /dev/null +++ b/src/client/test_config.yaml @@ -0,0 +1,3 @@ +ws: + url: localhost + port: 6873