From 89fd0c84b5dd73d93eff2177a3abaa4c33152607 Mon Sep 17 00:00:00 2001 From: Noah Swerhun Date: Fri, 10 Feb 2023 18:46:56 -0600 Subject: [PATCH] basic module parsing and threading --- modules.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 modules.py diff --git a/modules.py b/modules.py new file mode 100644 index 0000000..430244d --- /dev/null +++ b/modules.py @@ -0,0 +1,24 @@ +from yaml import safe_load +from io import open +from threading import Thread +from subprocess import run +from time import sleep + +def module_thread(cmd, refresh, pre, post): + while True: + print(pre, end='') + cmd_output = run(cmd, shell=True, capture_output=True, text=True).stdout + print(cmd_output.strip(), end='') + print(post) + sleep(refresh/1000) + + +with open("./testing_config.yml", 'r', encoding='utf8') as file: + config_file = safe_load(file) + +modules = config_file['bar']['modules'] +for module in modules: + cmd = modules[module]['command'] + refresh = modules[module]['refresh'] + x = Thread(target=module_thread, args=(cmd, refresh, '', '')) + x.start()