import subprocess from cinput import ControlInput, Button from graphics import Graphics def execute(cinput: ControlInput, graphics: Graphics, _): while True: cmd = "ip --brief addr show dev wlan0 | awk '{print $3}' | sed -E 's/\/[0-9]+$//'" ip = subprocess.check_output(cmd, shell=True).decode("utf-8") cmd = "top -bn 2 |grep \"Cpu(s)\" | awk '{print $2+$4+$6+$10+$12+$14+$16 \"%\"}' | tail -n1" cpu = subprocess.check_output(cmd, shell=True).decode("utf-8") cmd = "free | grep Mem | awk '{print int($3/$2 * 100.0 +0.5) \"%\"}'" mem = subprocess.check_output(cmd, shell=True).decode("utf-8") cmd = "df -h | awk '$NF==\"/\"{printf \"Disk: %d/%d GB %s\", $3,$2,$5}'" disk = subprocess.check_output(cmd, shell=True).decode("utf-8") cmd = "uptime | awk '{print $3}' | sed 's/,$//'" up = subprocess.check_output(cmd, shell=True).decode("utf-8") graphics.clear() graphics.text("IP: " + ip, 0, 0, 1) graphics.text("CPU: " + cpu, 0, 1, 1) graphics.text("Memory: " + mem, 0, 2, 1) graphics.text(disk, 0, 3, 1) graphics.text("Uptime: " + up, 0, 4, 1) graphics.show() key = cinput.get_one_shot(5) if key == Button.BTN_A: return