The idea is to keep this script running from 9AM to 6PM.
I want to run the script 'once' 10 seconds before the end of every minute. Meaning 9:01:50,9:02:50,9:03:50 and so on ...till 5:59:50
Here is my code for that
from datetime import datetime, time, timedelta, date
import time
i = 0
while i <= 1:
t = datetime.now()
my_time = t.strftime("%H:%M:%S.%f")
if t.second >=50:
print("my local time is", my_time)
tt = datetime.now()
time.sleep(55)
print("after sleep print time is", tt)
Now during the middle of the day if I decide that I want to run this script only one ever half an hour I use
if t.minute == 29 and t.second >=50:
print("my local time is", my_time)
elseif t.minute == 59 and t.second >=50):
print("my local time is", my_time)
The problem starts when during the day I change my mind over and over and I decide to run the script every 4 minutes or lets say 6 mintues keeping the start point as 9am and end point as 6pm.
Is there any way where I can set a variable at the beginning of the script such that all I need to do is change that variable and restart the script such that it does the job at the set interval henceforth. So at 9:37am I change the variable to 5 ... where 5 is minutes. then the script will run at 9:39:50, 9:44:50,9:49:50 and so on...
At 10:04 I will change the variable to 15 and the script will make the first print at 10:14:50... the next at 10:29:50 and so on...
How can this be done? Thanks in advance.