Skip to content

Instantly share code, notes, and snippets.

@nst
Created March 5, 2014 15:00
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 nst/9368877 to your computer and use it in GitHub Desktop.
Save nst/9368877 to your computer and use it in GitHub Desktop.
Starts a timer. Useful for tea or cooking.
#!/usr/bin/python
# -*- coding: iso-8859-1 -*-
__version__ = "$Revision: 0.1$"
__author__ = "Nicolas Seriot"
__date__ = "2005-01-16"
""""
Her: Would you count 2 minutes and a half plase?
Me : $ timer 2 30
Starts a timer. Useful for tea or cooking.
Uses the curses library. Lets you set the meal. With Mac OS X >= 10.4, the script pronounces a vocal alert.
""""
import sys
import curses
import time
import os
if len(sys.argv) < 3:
script_name = str(sys.argv[0].split(os.sep)[-1:])[2:-2]
print "usage : " + script_name + " <minutes> <seconds> [meal]"
sys.exit()
def main(stdscr):
rootwin = stdscr.derwin(0, 0, 0, 0)
stdscr.nodelay(1) # don't wait for input
delay = int(sys.argv[1]) * 60 + int(sys.argv[2])
meal = " ".join(sys.argv[3:])
if meal == "":
meal = "Tea"
while delay > 0:
m = delay / 60
s = delay % 60
chaine = meal + " will be ready in " + \
str(m).zfill(2) + ":" + str(s).zfill(2)
stdscr.addstr(0,0,str(chaine))
stdscr.refresh()
time.sleep(1)
delay -= 1
c = stdscr.getch()
if c == ord('q'):
sys.exit()
stdscr.clear()
chaine = meal + " is ready!"
stdscr.addstr(0,0,str(chaine), curses.A_BOLD)
stdscr.refresh()
if sys.platform == "darwin":
os.system("say \"" + meal + " is ready!\"")
else:
curses.beep()
stdscr.nodelay(0)
c = stdscr.getch()
curses.wrapper(main)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment