I have made a program called 'tLapse', here's the code:
import subprocess
import time
import os
print("Welcome to tLapse...")
time.sleep(3)
os.system('cls')
try:
com=open("action.txt",'r').read()
condition=True
except:
print("File error")
raw_input("<Any key to quit>")
condition=False
if(condition):
clock=raw_input("Enter time duration after which\nuser-specifiedaction will be\npeformed.\n\nFormat- [hh:mm][24- hour format]: ")
def app(path):
ext=path[-3:]
try:
if(ext=='exe'):
subprocess.call([path])
elif(ext=='mp3'):
subprocess.call(["C:\Program Files\Windows Media Player\wmplayer.exe",path])
except:
print("Unexpected error occured")
raw_input("<Any key to quit>")
def shutdown():
os.system("shutdows -s")
def determine(com):
for x in com:
if(x==' '):
ind=com.index(x)
type=com[:ind]
path=com[ind+1:]
if(type=='open'):
return path
elif(type=='shutdown'):
shutdown()
path=determine(com)
if(condition):
print("Waiting till "+clock+"...")
while(clock!=str(time.asctime()[11:16])):
if(clock==str(time.asctime()[11:16])):
os.system('cls')
app(path)
What it does is, it basically asks at what time the specified action has to be performed(action specified in 'action.txt' file).
But the problem is, even though I give thoroughly valid commands, it abruptly quits without reporting any errors, and sometimes it magically works(like, after running it a few dozen times with the same commands specified in the .txt file).
Most likely your while loop is the problem. You are telling while to loop as long as clock does not match the time, but inside the loop you have if with a condition to match clock and time.