Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time, datetime, subprocess, math, sys, os
- def say(s, cmd):
- """
- Runs a command with the specified string s. 'cmd' should be a
- command line to be run in the default shell using a string template
- to specify where the string to speak should be placed and can
- include pipes if necessary (i.e. for the festival command line
- utility).
- """
- nullfile = open(os.devnull, 'w') # null file to suppress stdout
- subprocess.Popen(cmd % s, stdout=nullfile, shell=True)
- def seconds_until(dt):
- return time.mktime(dt.timetuple()) - time.time()
- def countdown_to(target_time, only_if_below=10, end_statement=None, say_cmd='say "%s"'):
- said = set()
- while True:
- i = int(math.ceil(seconds_until(target_time)))
- if i < 0:
- if end_statement:
- say(end_statement, say_cmd)
- break
- if i <= only_if_below and i not in said:
- said.add(i)
- say(i, say_cmd)
- sys.stdout.write('%s. ' % i)
- sys.stdout.flush()
- time.sleep(0.1)
- if __name__ == '__main__':
- countdown_to(
- datetime.datetime(2010, 1, 1, 0, 0, 0),
- 10,
- 'Happy new year!',
- 'echo "%s" | festival --tts'
- )
Add Comment
Please, Sign In to add comment