I'm not good with Python Classes. I know in this instance using a class would solve the problem of trying to call a function within a function but I'm not sure how to do it. This is a script that opens a website on a set time added in the variable introduced in the beginning. I want to call the openWebsite() function in setTime() function. I'm sure a class would solve my problems but I'm a bit new to Python.
import webbrowser
import time
specify a website, local time and desired time
page = "https://www.twitter.com"
today = time.strftime('%X %x')
timeToOpen = "09:53:36 02/06/22"
a function to open a website and print opened
def openWebsite():
webbrowser.open_new(page)
print("website opened")
print(today)
compares real live time with a specified time in a variable in the beginning
def setTime():
while time.strftime('%X %x') != timeToOpen:
timeNow = time.strftime('%X %x')
if timeNow >= timeToOpen:
print("It's A Match")
I want to call openWebsite() here
break
print("waiting!")
print (timeNow + " vs " + timeToOpen)
time.sleep(3)
call a function
setTime()
PS: If you have any other suggestions to improve the code I would be very grateful
Thanks, Magz