Skip to content

Instantly share code, notes, and snippets.

@mrtazz
Created April 10, 2010 21:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrtazz/362323 to your computer and use it in GitHub Desktop.
Save mrtazz/362323 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
#
# simple timer for pomodoro like counting
# Usage: pomodoro.py WORKTIME BREAKTIME
#
import sys
import os
from time import gmtime, strftime, sleep
def main(e,b):
""" main function """
end = float(e) * 60
print "Let's do %1.0f minutes of hard work." % (end/60)
countdown(end)
os.system('growlnotify -m "Time for a break" -t "pomodoro.py"')
breaktime = float(b) * 60
print "\nAllright, %1.0f minute break." % (breaktime/60)
countdown(breaktime)
os.system('growlnotify -m "Break is over, ready for another round?" \
-t "pomodoro.py"')
def countdown(t):
""" function to countdown the given time """
now = 0
while (now <= t):
s = "\b\b\b\b\b\b%s" % strftime("%M:%S", gmtime(now))
print s,
sys.stdout.flush()
now += 1
sleep(1)
if __name__ == '__main__':
e = 25
b = 5
if len(sys.argv) >= 2: e = sys.argv[1]
if len(sys.argv) >= 3: b = sys.argv[2]
main(e,b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment