76 lines
1.9 KiB
Python
Executable file
76 lines
1.9 KiB
Python
Executable file
#!/usr/bin/env python3
|
|
|
|
import sys
|
|
from datetime import datetime
|
|
import time
|
|
import pytz
|
|
|
|
|
|
try:
|
|
if len(sys.argv) < 3:
|
|
print("Usage: {scriptname} timezone_left timezone_right".format(scriptname=sys.argv[0]), file=sys.stderr)
|
|
exit(1)
|
|
|
|
try:
|
|
tzleft = pytz.timezone(sys.argv[1])
|
|
tzright = pytz.timezone(sys.argv[2])
|
|
except pytz.exceptions.UnknownTimeZoneError as e:
|
|
print('Unknown time zone "{}"'.format(e.args[0]), file=sys.stderr)
|
|
exit(1)
|
|
|
|
|
|
hourhands = ""
|
|
minutehands = ""
|
|
|
|
def face_for(t):
|
|
minute = minutehands[ t.minute // 5 ]
|
|
hour = hourhands [ t.hour % 12 ]
|
|
|
|
return color_for(t) + "%{T8}%{F#000}%{O-24}" + hour + "%{O-24}" + minute + "%{T-}%{F}"
|
|
|
|
|
|
def color_for(t):
|
|
if t.hour < 5 or t.hour > 22:
|
|
return "%{F#888}"
|
|
elif t.hour < 10:
|
|
return "%{F#DB9}"
|
|
elif t.hour < 14:
|
|
return "%{F#DDB}"
|
|
elif t.hour < 19:
|
|
return "%{F#DDD}"
|
|
else:
|
|
return "%{F#D9B}"
|
|
|
|
|
|
while True:
|
|
utcnow = datetime.now(tz=pytz.utc)
|
|
localnow = datetime.now()
|
|
leftnow = utcnow.astimezone(tzleft )
|
|
rightnow = utcnow.astimezone(tzright)
|
|
|
|
localcolor = color_for(localnow)
|
|
|
|
print(
|
|
localnow.strftime("%A") +
|
|
" " +
|
|
|
|
face_for(leftnow) +
|
|
|
|
" %{T4}" + localcolor + localnow.strftime("%H") +
|
|
"%{O2}%{T8}" + face_for(localnow) +
|
|
"%{O2}%{T4}" + localcolor + localnow.strftime("%M") + "%{T-}" +
|
|
" " +
|
|
|
|
face_for(rightnow) +
|
|
|
|
" " +
|
|
localnow.strftime("%d %b"),
|
|
|
|
flush = True
|
|
)
|
|
|
|
delay = 60 - localnow.second - (localnow.microsecond * 10e-7)
|
|
time.sleep(delay)
|
|
|
|
except Exception as e:
|
|
print(e, file=sys.stderr)
|