mardi 9 mars 2021

How do I stop an action in a loop?

I'm trying to create a script that opens my online classes automatically. I wrote this code:

import webbrowser
import datetime
import time

now = time.strftime("%D, %H:%M")

lesson1 = "03/09/21, 15:38"
lesson2 = "03/10/21, 15:39"
lesson3 = "03/10/21, 15:40"

while True:
    while now != lesson1 and now != lesson2 and now != lesson3:
        print ("Waiting, the current time is " + now)
        now = time.strftime("%D, %H:%M")
        time.sleep(1)

    if now == lesson1:
        print ("LESSON IS OPENING :D")
        webbrowser.open("https://google.com")

    if now == lesson2:
        print ("LESSON IS OPENING :D")
        webbrowser.open("https://google.com")

    if now == lesson3:
        print ("LESSON IS OPENING :D")
        webbrowser.open("https://google.com")

Now, the problem is that the first if-statement is executed endlessly, I want to make it execute only one time, than wait until now == lesson2 and execute the second if etc

Aucun commentaire:

Enregistrer un commentaire