Last active
August 4, 2016 21:13
-
-
Save drdrang/c1c81ae19dac35acc861 to your computer and use it in GitHub Desktop.
Prints Emoji clockface of the given time rounded to the nearest half-hour. Uses current time if none given. After https://github.com/RobTrew/txtquery-tools/blob/master/utilities/emotime.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
from sys import argv | |
from time import strftime | |
clocks = {'12:00': 'π', '12:30': 'π§', '1:00': 'π', '1:30': 'π', | |
'2:00': 'π', '2:30': 'π', '3:00': 'π', '3:30': 'π', | |
'4:00': 'π', '4:30': 'π', '5:00': 'π', '5:30': 'π ', | |
'6:00': 'π', '6:30': 'π‘', '7:00': 'π', '7:30': 'π’', | |
'8:00': 'π', '8:30': 'π£', '9:00': 'π', '9:30': 'π€', | |
'10:00': 'π', '10:30': 'π₯', '11:00': 'π', '11:30': 'π¦'} | |
# Get the argument, which should be a time string, like "8:10." | |
# If there's no argument, use the current time. | |
try: | |
oclock = argv[1] | |
except IndexError: | |
oclock = strftime('%I:%M') | |
hour, minute = [ int(x) for x in oclock.split(':') ] | |
# Round to the nearest half-hour, because there are no | |
# emoji clockfaces for other times. | |
rminute = int(round(float(minute)/30)*30) | |
if rminute == 60: | |
rminute = 0 | |
hour = 1 if hour == 12 else hour + 1 | |
print clocks['%d:%02d' % (hour, rminute)] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment