easyconf-lemonbar/modules.py

35 lines
960 B
Python
Raw Normal View History

2023-02-11 00:46:56 +00:00
from yaml import safe_load
from io import open
from threading import Thread
from subprocess import run
from time import sleep
running_modules_dict = {}
def print_modules():
for module in running_modules_dict:
print(running_modules_dict[module] + " | ", end='')
print(flush=True)
def module_thread(name, cmd, refresh, pre, post):
2023-02-11 00:46:56 +00:00
while True:
result = pre
result += run(cmd, shell=True, capture_output=True, text=True).stdout.strip()
result += post
running_modules_dict[name] = result
print_modules()
2023-02-11 00:46:56 +00:00
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']
running_modules_dict[module] = ''
x = Thread(target=module_thread, args=(module, cmd, refresh, '', ''))
2023-02-11 00:46:56 +00:00
x.start()