dimanche 26 juin 2016

leave program running in the background and continuously check on the value of the clock

My goal is to create a program which continuously checks on the value of time,compares it to variable values (static for now: one or two or three), it will open a specific page, if it matches the value one, I still want the program to stay running till it matches two, perform the same action, same for the value of three.

1- How do I let my program run continuously while checking the clock value ?

2- How do I let the program alive to run for the second and third value ?

The program only works when I run it specifically at the exact time of one of the values...

import time
import webbrowser
print(" This started on " + time.strftime("%H:%M"))
count = 0
clock = time.strftime("%H:%M")
#values i want to assign for breaks
one = "17:15"
two = "21:15"
three = "23:00"
#continous loop
while True:
   if (clock == one ):
    time.sleep(2)
    webbrowser.open("https://www.youtube.com/watch?v=QZbuj3RJcjI")
    break
elif (clock == two):
    time.sleep(2)
    webbrowser.open("https://www.youtube.com/watch?v=QZbuj3RJcjI")
    break
elif (clock == three):
    time.sleep(2)
    webbrowser.open("https://www.youtube.com/watch?v=QZbuj3RJcjI")
    break
else:
    print "finished"
break  

Aucun commentaire:

Enregistrer un commentaire