Skip to content

Instantly share code, notes, and snippets.

@danieljfarrell
Created January 11, 2012 05:33
Show Gist options
  • Save danieljfarrell/1593220 to your computer and use it in GitHub Desktop.
Save danieljfarrell/1593220 to your computer and use it in GitHub Desktop.
Intercontinental StarCraft 2 Happy Time Finder
from datetime import *
from clint.textui import colored, columns
#
# Using a module called Clint to take care of printing columns and text colour
#
# Examples: http://www.nicosphere.net/clint-command-line-library-for-python/
# Github: https://github.com/kennethreitz/clint
# Install: pip install clint
#
COLS = 20
print columns(['Chicago', COLS], ['London', COLS], ['Tokyo', COLS])
# Next Saturday evening in London
d = date(2012, 1, 14)
t = time(20, 01)
london_time = datetime.combine(d, t)
# Loop through 24 hours to find a happy StarCraft time
for dt in range(24):
chicago_time = london_time + timedelta(hours=-6)
tokyo_time = london_time + timedelta(hours=9)
time_row = []
# Is the time a happy time?
for location_time in (chicago_time, london_time, tokyo_time):
local_hour = int(location_time.strftime("%H"))
if local_hour > 1 and local_hour < 6:
# People need to sleep
time_row.append(colored.red(str(location_time)))
else:
# Happy time!
time_row.append(colored.green(str(location_time)))
# Print the results
coloured_row = [ columns([x, COLS]) for x in time_row ]
print "".join(coloured_row)
# Update the time in london
london_time = london_time + timedelta(hours=1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment