Last active
May 3, 2022 09:07
-
-
Save chrische/054a06f66731fe4942fe42b5f93d3982 to your computer and use it in GitHub Desktop.
Swaybar Status Line Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# A status line script | |
# Works well with Swaybar | |
# | |
# Created by chrische (https://github.com/chrische) | |
# Inspired by: https://unix.stackexchange.com/questions/473788/simple-swaybar-example#520995 | |
from datetime import datetime | |
from psutil import sensors_battery | |
from socket import gethostname, gethostbyname | |
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(): | |
ip = gethostbyname(gethostname()) | |
try: | |
ssid = check_output("iw dev wlp0s20f3 link | awk '/SSID/{print $2}'", shell=True).strip().decode("utf-8") | |
ssid = "(%s)" % ssid | |
except Exception: | |
ssid = "None" | |
battery = int(sensors_battery().percent) | |
status = "Charging" if sensors_battery().power_plugged else "Discharging" | |
date = datetime.now().strftime('%A - %d.%m.%Y - %H:%M') | |
format = "WiFi: %s %s | Battery: %s%% %s | %s" | |
write(format % (ip, ssid, battery, status, date)) | |
while True: | |
refresh() | |
sleep(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment