From a611f67f49f5ba586120105894d94597621d513c Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Wed, 28 Jun 2023 02:47:23 +0100 Subject: [PATCH] add debug example --- examples/debug/README.md | 9 +++++++ examples/debug/__main__.py | 50 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 examples/debug/README.md create mode 100644 examples/debug/__main__.py diff --git a/examples/debug/README.md b/examples/debug/README.md new file mode 100644 index 0000000..60a8ce6 --- /dev/null +++ b/examples/debug/README.md @@ -0,0 +1,9 @@ +## About + +The underlying socketio and engineio packages emit a lot of logs so it may be useful to filter out streamlabsio logs. + +This example prints raw messages whenever Client.event_handler() receives data. + +## Use + +Run the script and trigger any of the events with `Test Widgets` in the Streamlabs GUI. \ No newline at end of file diff --git a/examples/debug/__main__.py b/examples/debug/__main__.py new file mode 100644 index 0000000..ad13d74 --- /dev/null +++ b/examples/debug/__main__.py @@ -0,0 +1,50 @@ +from logging import config + +import streamlabsio + +config.dictConfig( + { + "version": 1, + "formatters": { + "standard": { + "format": "%(asctime)s,%(msecs)d %(name)s %(levelname)s %(message)s" + } + }, + "handlers": { + "stream": { + "level": "DEBUG", + "class": "logging.StreamHandler", + "formatter": "standard", + } + }, + "loggers": {"streamlabsio.client": {"handlers": ["stream"], "level": "DEBUG"}}, + } +) + + +def on_youtube_event(event, data): + print(f"{event}: {data.attrs()}") + + +def on_twitch_event(event, data): + if event == "follow": + print(f"Received follow from {data.name}") + elif event == "bits": + print(f"{data.name} donated {data.amount} bits! With message: {data.message}") + elif event == "donation": + print( + f"{data.name} donated {data.formatted_amount}! With message: {data.message}" + ) + + +def main(): + with streamlabsio.connect() as client: + client.obs.on("streamlabs", on_twitch_event) + client.obs.on("twitch_account", on_twitch_event) + client.obs.on("youtube_account", on_youtube_event) + + client.sio.sleep(30) + + +if __name__ == "__main__": + main()