feat: add status script
Some checks are pending
Continuous Integration / Checks (push) Waiting to run

This commit is contained in:
Tim Schubert 2024-11-30 18:29:51 +01:00
parent cf26daecee
commit 429f906a1a
Signed by: dadada
SSH key fingerprint: SHA256:bFAjFH3hR8zRBaJjzQDjc3o4jqoq5EZ87l+KXEjxIz0
5 changed files with 120 additions and 2 deletions

View file

@ -215,7 +215,7 @@ bar {
# When the status_command prints a new line to stdout, swaybar updates.
# The default just shows the current date and time.
status_command while date +'%Y-%m-%d %X'; do sleep 1; done
status_command ~/.config/sway/status
colors {
statusline #ffffff

View file

@ -163,6 +163,7 @@ in
};
home.file.".config/sway/config".source = ./config;
home.file.".config/sway/status".source = ./status;
# Let Home Manager install and manage itself.
programs.home-manager.enable = true;

View file

@ -102,7 +102,10 @@ with pkgs; [
prusa-slicer
pv
pwgen
python3
(python3.withPackages (python-pkgs: with python-pkgs; [
pandas
requests
]))
ranger
recipemd
reptyr

113
home/status Executable file
View file

@ -0,0 +1,113 @@
#!/usr/bin/env python3
import json
import sys
import time
import requests
import logging
from datetime import datetime
logger = logging.getLogger(__name__)
class Status:
def status(self):
return None
class Cat(Status):
index = 0
def status(self):
cat_width = 200
index = self.index
catwalk = " " * (cat_width - index) + 1 * "🐈🏳️‍🌈" + " " * index
self.index = (index + 1) % cat_width
return catwalk
class Space(Status):
backoff = 0
c_status = None
def status(self):
backoff = self.backoff
if self.backoff == 0:
self.update()
return self.c_status
def update(self):
spacestatus_url = "https://status.stratum0.org/status.json"
resp = requests.get(url=spacestatus_url)
self.backoff = (self.backoff + 1) % 120
data = resp.json()
if data["isOpen"]:
since = datetime.strptime(data["since"], "%Y-%m-%dT%H:%M:%S.%f").strftime("%A at %H:%M")
spacestatus = f"Space is open since {since}"
else:
spacestatus = "Space is closed"
self.c_status = spacestatus
class Battery(Status):
capacity_file = open('/sys/class/power_supply/BAT0/capacity', 'r')
status_file = open('/sys/class/power_supply/BAT0/status', 'r')
def status(self):
self.status_file.seek(0)
status = self.status_file.read().rstrip()
self.capacity_file.seek(0)
capacity = self.capacity_file.read().rstrip()
battery = f"{status} {capacity}%"
return battery
class Time(Status):
def status(state):
return datetime.now().strftime("%Vth %A %H:%M")
def print_header():
header = {
"version": 1,
"click_events": False,
}
print(json.dumps(header))
print("[")
def run(interval, widgets):
print_header()
while True:
body = []
for widget in widgets:
try:
status = widget.status()
except Exception as e:
logger.error(e)
if status:
body += {"full_text": f"{status}"},
print(json.dumps(body), ",", flush=True)
ts = interval - (time.time() % interval)
time.sleep(ts)
if __name__ == "__main__":
logging.basicConfig(level=logging.INFO)
# Interval in seconds
interval = 1.0
widgets = [Cat(), Space(), Battery(), Time()]
run(interval, widgets)

View file

@ -128,6 +128,7 @@ in
ghostscript
smartmontools
dmenu
grim # screenshot functionality
slurp # screenshot functionality
mako # notification system developed by swaywm maintainer