ASPN ActiveState Programmer Network  
ActiveState, a division of Sophos
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups
Submit Recipe
My Recipes

All Recipes
All Cookbooks


View by Category

Title: alarm.py
Submitter: Stephen Chappell (other recipes)
Last Updated: 2006/03/04
Version no: 1.0
Category: Programs

 

3 stars 1 vote(s)


Description:

This recipe is a command line alarm. If not used correctly, usage information is printed. If an exception is thrown, details on the exception are printed out, though in a format most useful for a programmer. The program has no built-in way of being shutdown, so such actions must be executed externally.

Source: Text Source

import os, sys, time

def main():
    if len(sys.argv) != 4:
        print os.path.basename(sys.argv[0]),
        print '<hours> <minutes> <seconds>'
    else:
        try:
            timer(*[int(x) for x in sys.argv[1:]])
        except Exception, error:
            print error

def timer(hours, minutes, seconds):
    time.sleep(abs(hours * 3600 + minutes * 60 + seconds))
    while True:
        print '\x07',

if __name__ == '__main__':
    main()

Discussion:

This program was originally far simpler and was designed to wake the author up in three after (no alarm clock was available at the time). It is conceivable that more inventive uses of the recipe could be invented (such as a cooking time), but that is up to the readers to decide. The presentation here is made in the hopes that it might go on to serve in better capacities.



Add comment

No comments.



Highest rated recipes:

1. Implementation of sets ...

2. bag collection class

3. deque collection class

4. Floating Point Simulator

5. HTML colors to/from RGB ...

6. Select the nth smallest ...

7. Function Decorators by ...

8. MS SQL Server log monitor

9. Table objects with ...

10. wx twisted support using ...




Privacy Policy | Email Opt-out | Feedback | Syndication
© 2006 ActiveState Software Inc. All rights reserved.