Initial commit
This commit is contained in:
40
waybar/waybar-clock.py
Executable file
40
waybar/waybar-clock.py
Executable file
@ -0,0 +1,40 @@
|
||||
#!/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()
|
||||
Reference in New Issue
Block a user