Now loads config from YAMl

This commit is contained in:
hornet 2021-11-09 15:14:06 -05:00
parent 4760930c4f
commit e8d230b31a
2 changed files with 13 additions and 2 deletions

View File

@ -2,6 +2,7 @@ import websocket
import _thread import _thread
import time import time
import ssl import ssl
import yaml
def on_message(ws, message): def on_message(ws, message):
print(f"<< {message}") print(f"<< {message}")
@ -24,11 +25,18 @@ def on_open(ws):
ws.close() ws.close()
_thread.start_new_thread(run, ()) _thread.start_new_thread(run, ())
if __name__ == "__main__": def open_socket(url, port):
websocket.enableTrace(True) websocket.enableTrace(True)
ws = websocket.WebSocketApp("ws://localhost:6873", ws = websocket.WebSocketApp(f"ws://{url}:{port}",
on_open=on_open, on_open=on_open,
on_message=on_message, on_message=on_message,
on_error=on_error, on_error=on_error,
on_close=on_close) on_close=on_close)
ws.run_forever(sslopt={"cert_reqs": ssl.CERT_NONE}) 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'])

View File

@ -0,0 +1,3 @@
ws:
url: localhost
port: 6873