Files
river-config/waybar/waybar-clock.py
2025-11-28 16:44:06 -08:00

41 lines
932 B
Python
Executable File

#!/usr/bin/env python
from datetime import datetime
from zoneinfo import ZoneInfo
from itertools import batched
import json
import time
import sys
def format_output(zones):
# primary timezone
primary = datetime.now(zones[0][1]).strftime("%R")
tooltip = None
for label, zone in zones:
if not tooltip:
tooltip = "<tt>"
else:
tooltip += "\n"
tooltip += f"{label}: {datetime.now(zone).strftime('%R %a %b %d %Z')}"
tooltip += "</tt>"
json.dump({"text": primary, "tooltip": tooltip}, sys.stdout)
print(flush=True)
def main():
if len(sys.argv) == 1 or len(sys.argv) % 2 == 0:
print("usage: waybar-clock.py [<label> <zone>]...")
sys.exit(1)
zones = [
(label, ZoneInfo(zone_name))
for label, zone_name in batched(sys.argv[1:], 2)
]
while True:
format_output(zones)
time.sleep(0.5)
main()