-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstats_keyb.py
executable file
·37 lines (28 loc) · 918 Bytes
/
stats_keyb.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/python3
import psutil
import subprocess
import sys
interval = 2
def get_lines():
global interval
line1 = f"CPU: {psutil.cpu_percent(interval):.0f}% "
line1 += f"MEM: {psutil.virtual_memory().percent:.0f}% "
line2 = f"DSK: {psutil.disk_usage('/').percent:.0f}%"
battery = psutil.sensors_battery()
line2 = f"BAT: {battery.percent:.0f}%"
line2 += " (C)" if battery.power_plugged else ""
nmcli_cmd = ["nmcli", "c", "show", "--active"]
line3 = "VPN Status: "
if ("vpn0" in subprocess.run(nmcli_cmd, stdout=subprocess.PIPE).stdout.decode('utf-8')):
line3 += "ON"
else:
line3 += "OFF"
return ("-1", line1, "-2", line2, "-3", line3)
while True:
keyb_update = ["apex7tkl", "text"]
keyb_update.extend(get_lines())
try:
subprocess.check_call(keyb_update)
except:
print("No keyb, so dying...")
sys.exit(1)