dotfiles/files/home/.config/sway/status.py

26 lines
832 B
Python
Raw Normal View History

2023-10-14 22:38:03 +02:00
import socket
from datetime import datetime
from psutil import disk_usage, sensors_battery
from psutil._common import bytes2human
import socket
from subprocess import check_output
from sys import stdout
from time import sleep
def write(data):
stdout.write('%s\n' % data)
stdout.flush()
def refresh():
disk = f"{bytes2human(disk_usage('/').used)} / {bytes2human(disk_usage('/').total)} ({bytes2human(disk_usage('/').free)})"
hostname = socket.gethostname()
ip = socket.gethostbyname(hostname+".")
battery = int(sensors_battery().percent)
status = "Charging" if sensors_battery().power_plugged else "Discharging"
date = datetime.now().strftime('%h %d %A %H:%M:%S')
write(f"d: {disk} | n: {hostname} @ {ip} | b: {battery}% ({status.lower()[:3]}) | {date}")
while True:
refresh()
sleep(1)