32 lines
845 B
Python
Executable File
32 lines
845 B
Python
Executable File
#!/usr/bin/env python
|
|
|
|
import os
|
|
from os.path import expanduser
|
|
import psutil
|
|
|
|
os.chdir(os.path.expanduser('~/.config/dotfiles/hypr'))
|
|
|
|
bars = "_▂▃▄▅▆▇█"
|
|
cpu_values = [0] * 10
|
|
mem_values = [0] * 10
|
|
|
|
def to_bar(x):
|
|
return bars[round((len(bars) - 1) * x / 100)]
|
|
|
|
while True:
|
|
cpu_percent = psutil.cpu_percent(interval=2)
|
|
mem_percent = psutil.virtual_memory().percent
|
|
|
|
for i in range(len(cpu_values) - 1):
|
|
cpu_values[i] = cpu_values[i+1]
|
|
mem_values[i] = mem_values[i+1]
|
|
|
|
cpu_values[-1] = cpu_percent
|
|
mem_values[-1] = mem_percent
|
|
|
|
with open('.stat.txt', 'w') as f:
|
|
f.write(
|
|
' ' + ''.join([to_bar(x) for x in cpu_values]) + ' ' + "% 5.1f"%cpu_percent + '%\n' +
|
|
' ' + ''.join([to_bar(x) for x in mem_values]) + ' ' + "% 5.1f"%mem_percent + '%'
|
|
)
|