Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help with programming an alarm in Python

Status
Not open for further replies.

Yester

Programmer
Feb 26, 2007
2
US
My problem is i can not get it to open the file when the alarm goes off. Any help would be greatly appreciated.


Here is the script:

#Alarm where you can set the timer.
#AlarmclockworksV.01

import os, time

print "The current time is:"
print time.strftime("%H:%M:%S")

alarminfo_1 = raw_input("Enter the Hour:")
alarminfo_2 = raw_input("Enter the Minute:")
alarminfo_3 = raw_input("Enter the Second:")

def alarm_exec():

a_1 = alarminfo_1
a_2 = alarminfo_2
a_3 = alarminfo_3
running = True
running1 = True
running2 = True
running3 = True
running4 = True

while running:
print "The timer was set at:"
print time.strftime("%H:%M:%S")
running = False

while running1:

if len(alarminfo_1) == 1:
a_1 = ("0" + alarminfo_1)
running1 = False

if len(alarminfo_1) == 2:
a_1 = alarminfo_1
running1 = False

while running2:

if len(alarminfo_2) == 1:
a_2 = ("0" + alarminfo_2)
running2 = False

if len(alarminfo_2) == 2:
a_2 = alarminfo_2
running2 = False

while running3:

if len(alarminfo_3) == 1:
a_3 = ("0" + alarminfo_3)
running3 = False

if len(alarminfo_3) == 2:
a_3 = alarminfo_3
running3 = False

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
#my problem is i can not get it to open that file, i have tried many different ways to get this to work, but im all out of ideas.

while running4:
if time.strftime("%H:%M:%S") == ("%s:%s:%s" % (a_1, a_2, a_3)):

print "Alarm has gone off."
os.open(r'C:\Documents and Settings\Zack\My Documents\My Music\Unknown Artist\Unknown Album (8-9-2006 3-32-51 PM)\01 Track 01.wma')
time.sleep(30)
running4 = False

alarm_exec()

print 'finished'

raw_input("Press Enter to quit.")
 
Nevermind, i figured it out... instead of:

os.open(r'C:\Documents and Settings\Zack\My Documents\My Music\Unknown Artist\Unknown Album (8-9-2006 3-32-51 PM)\01 Track 01.wma')

#i used:

os.startfile(r'C:\Documents and Settings\Zack\My Documents\My Music\Unknown Artist\Unknown Album (8-9-2006 3-32-51 PM)\01 Track 01.wma')

and it worked great
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top