Add analog clock faces
This commit is contained in:
parent
ed5ea4c2ab
commit
717b208a94
1 changed files with 46 additions and 42 deletions
|
@ -6,58 +6,62 @@ import time
|
||||||
import pytz
|
import pytz
|
||||||
|
|
||||||
|
|
||||||
if len(sys.argv) < 3:
|
|
||||||
print("Usage: {scriptname} timezone_left timezone_right".format(scriptname=sys.argv[0]), file=sys.stderr)
|
|
||||||
exit(1)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
tzleft = pytz.timezone(sys.argv[1])
|
if len(sys.argv) < 3:
|
||||||
tzright = pytz.timezone(sys.argv[2])
|
print("Usage: {scriptname} timezone_left timezone_right".format(scriptname=sys.argv[0]), file=sys.stderr)
|
||||||
except pytz.exceptions.UnknownTimeZoneError as e:
|
exit(1)
|
||||||
print('Unknown time zone "{}"'.format(e.args[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)
|
||||||
|
|
||||||
|
|
||||||
faces = "🕛🕧🕐🕜🕑🕝🕒🕞🕓🕟🕔🕠🕕🕡🕖🕢🕗🕣🕘🕤🕙🕥🕚🕦"
|
faces = "🕛🕧🕐🕜🕑🕝🕒🕞🕓🕟🕔🕠🕕🕡🕖🕢🕗🕣🕘🕤🕙🕥🕚🕦🕛"
|
||||||
|
|
||||||
def face_for(t):
|
def face_for(t):
|
||||||
minute = (t.minute + 15) // 30
|
minute = (t.minute + 15) // 30
|
||||||
hour = (t.hour + 0 if minute < 45 else 1) % 12
|
hour = (t.hour + 0 if minute < 45 else 1) % 12
|
||||||
|
|
||||||
return faces[2*hour + minute]
|
return faces[2*hour + minute]
|
||||||
|
|
||||||
|
|
||||||
def color_for(t):
|
def color_for(t):
|
||||||
if t.hour < 5 or t.hour > 22:
|
if t.hour < 5 or t.hour > 22:
|
||||||
return "888"
|
return "888"
|
||||||
elif t.hour < 10:
|
elif t.hour < 10:
|
||||||
return "DB9"
|
return "DB9"
|
||||||
elif t.hour < 14:
|
elif t.hour < 14:
|
||||||
return "DDB"
|
return "DDB"
|
||||||
elif t.hour < 19:
|
elif t.hour < 19:
|
||||||
return "DDD"
|
return "DDD"
|
||||||
else:
|
else:
|
||||||
return "D9B"
|
return "D9B"
|
||||||
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
utcnow = datetime.now(tz=pytz.utc)
|
utcnow = datetime.now(tz=pytz.utc)
|
||||||
localnow = datetime.now()
|
localnow = datetime.now()
|
||||||
leftnow = utcnow.astimezone(tzleft )
|
leftnow = utcnow.astimezone(tzleft )
|
||||||
rightnow = utcnow.astimezone(tzright)
|
rightnow = utcnow.astimezone(tzright)
|
||||||
print(
|
print(
|
||||||
"%{T2}%{F#" + color_for(leftnow) + "}" +
|
"%{T2}%{F#" + color_for(leftnow) + "}" +
|
||||||
face_for(leftnow) +
|
face_for(leftnow) +
|
||||||
"%{F}%{T-} " +
|
"%{F}%{T-} " +
|
||||||
|
|
||||||
localnow.strftime("%A %%{T4}%%{F"+color_for(localnow)+"}%H:%M%%{F}%%{T-} %d %b") +
|
localnow.strftime("%A %%{T4}%%{F"+color_for(localnow)+"}%H:%M%%{F}%%{T-} %d %b") +
|
||||||
|
|
||||||
" %{T2}%{F#" + color_for(rightnow) + "}" +
|
" %{T2}%{F#" + color_for(rightnow) + "}" +
|
||||||
face_for(rightnow) +
|
face_for(rightnow) +
|
||||||
"%{F}%{T-}",
|
"%{F}%{T-}",
|
||||||
|
|
||||||
flush = True
|
flush = True
|
||||||
)
|
)
|
||||||
|
|
||||||
delay = 60 - localnow.second - (localnow.microsecond * 10e-7)
|
delay = 60 - localnow.second - (localnow.microsecond * 10e-7)
|
||||||
time.sleep(delay)
|
time.sleep(delay)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(e, file=sys.stderr)
|
||||||
|
|
Loading…
Reference in a new issue