2020-02-04 10:37:08 +01:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
#
|
2020-12-13 16:10:25 +01:00
|
|
|
# Requires the following packages on Arch Linux:
|
|
|
|
# - ttf-twemoji (and make sure there are no other emoji fonts like noto-fonts-emoji
|
|
|
|
# - networkmanager
|
|
|
|
# - pulsemixer
|
2020-02-04 10:37:08 +01:00
|
|
|
|
|
|
|
from datetime import datetime
|
|
|
|
from subprocess import check_output
|
|
|
|
from sys import stdout
|
|
|
|
|
|
|
|
from psutil import sensors_battery
|
|
|
|
|
|
|
|
|
|
|
|
def write(data):
|
|
|
|
stdout.write("%s\n" % data)
|
|
|
|
stdout.flush()
|
|
|
|
|
|
|
|
|
|
|
|
def refresh():
|
|
|
|
try:
|
|
|
|
ssid = (
|
2020-12-13 16:10:25 +01:00
|
|
|
check_output(
|
|
|
|
"iwctl station wlan0 show | grep 'Connected network' | awk '{print $3}'",
|
|
|
|
shell=True,
|
|
|
|
)
|
2020-02-04 10:37:08 +01:00
|
|
|
.strip()
|
|
|
|
.decode("utf-8")
|
|
|
|
)
|
|
|
|
except Exception:
|
|
|
|
ssid = "None"
|
|
|
|
|
|
|
|
wifi_status = f"{ssid} 📶"
|
|
|
|
|
|
|
|
battery_percent = int(sensors_battery().percent)
|
|
|
|
battery_icon = "🔋"
|
|
|
|
battery_status = f"{battery_percent} {battery_icon}"
|
|
|
|
power_status = "🔌" if sensors_battery().power_plugged else ""
|
|
|
|
|
|
|
|
try:
|
|
|
|
# pulsemixer returns "10 10" so we need to split the output to get "10"
|
|
|
|
volume_level = (
|
|
|
|
check_output("pulsemixer --get-volume", shell=True).strip().decode("utf-8")
|
|
|
|
)
|
|
|
|
volume_level = int(volume_level.split(" ")[0])
|
|
|
|
|
|
|
|
if volume_level >= 70:
|
|
|
|
volume_icon = "🔊"
|
|
|
|
elif volume_level >= 30 and volume_level < 70:
|
|
|
|
volume_icon = "🔉"
|
|
|
|
elif volume_level < 30 and volume_level >= 1:
|
|
|
|
volume_icon = "🔈"
|
|
|
|
else:
|
|
|
|
volume_icon = "🔇"
|
|
|
|
except Exception:
|
|
|
|
volume_level = ""
|
|
|
|
|
|
|
|
volume_status = f"{volume_level} {volume_icon}"
|
|
|
|
|
|
|
|
date = datetime.now().strftime("%Y-%m-%d %l:%M:%S %p")
|
|
|
|
|
|
|
|
write(f"{wifi_status} {volume_status} {battery_status} {power_status} {date}")
|
|
|
|
|
|
|
|
|
|
|
|
refresh()
|