A Simple Python Alarm Clock

Posted by jun auza On 4/11/2008
Problem: You are all alone in a far away land and needed to wake up early the next day. The problem is, you forgot to bring any alarm clock. But, you brought a Linux-powered laptop computer with you. Say for example an Asus Eee PC.


Solution
: Most Linux distributions have Python installed out-of-the-box. All you need is this very simple Python alarm clock script:




import time
import os

not_executed = 1

while(not_executed):
dt = list(time.localtime())
hour = dt[3]
minute = dt[4]
if hour == 5 and minute == 45:
os.popen2("open /Users/jun/shout.mp3")
not_executed = 0


Happy Hacking! :)

Bookmark and Share

Related Posts:



6 Response to "A Simple Python Alarm Clock"

  1. leigh Said,

    do you input this in terminal?

     

  2. CoffeeMug Said,

    I would put a time.sleep(1) in the loop to give the processor a little breathing time :)

     

  3. attica Said,

    What about using the command "crontab -e"?

     

  4. I'd say:

    executed = 0
    while not executed:
    ...

     

  5. david Said,

    popen2 no longer works! deprecated! how do I use subprocess module to do the same thing?? http://docs.python.org/library/subprocess.html

    also would like to be able to time shutting down and turning on of my comp???


    soz i is a nube

     

  6. Anonymous Said,

    I am new in programming, I want a code that would sound alarms at specific times. I tried this code using the 3.3.0 version but it gave the message "invalid version"

    Can anyone please help? Below is the code:
    >>> import time
    >>> import os
    >>>
    >>> not_executed=1
    >>> while(not_executed):
    dt=list(time.localtime())
    hour=dt[3]
    minute=dt[4]
    if hour == 10 and minute ==3:
    os.popen2("open/users/Libraries/Music/Public Music/Sample Music/kalimba.mp3")
    not_executed = 0

     

Post a Comment

Archive


"Action is the real measure of intelligence" ~Napoleon Hill

Twitter

Tumblr

Google +