user8838477
user8838477

Reputation: 47

python-alarm clock suggestions

I am new to python programming and I am trying to apply the concepts I learned recently. I am reading other's code and found an example and tweaked it little bit as seen below. The problem is when the current time equals the wake time, the elif block never gets triggered. I have tested that in a small if-else statement, it works fine but never gets triggered inside the while loop.

Please advise.

import time

import subprocess

wake_hour = int(raw_input("Wake hour: "))

wake_minute = int(raw_input("Wake minute: "))

wake_time = [wake_hour, wake_minute]

current_hour = int(time.strftime("%H"))

current_minute = int(time.strftime("%M"))

current_time = [current_hour, current_minute]

while True:

     if current_time != wake_time:
        current_hour = int(time.strftime("%H"))
        current_minute = int(time.strftime("%M"))
        print current_hour, current_minute
        print wake_hour, wake_minute

     elif current_time == wake_time:
        audio_file = "/Users/dcasteli/Documents/emergency018.mp3"
        play = subprocess.call(["afplay", audio_file])
        print "Wake up!"

Upvotes: 1

Views: 92

Answers (1)

nyvokub
nyvokub

Reputation: 569

You are only updating the current_hour and current_minute but in the elif statement you are comparing current_time == wake_time. The current_time value is never updated and will forever remain whatever the user input. In the first if statement you should update the current_time so the conditional makes sense.

Upvotes: 3

Related Questions