0

I am making a python program that adds a task of running another python script such that the desired python script runs at increasing time intervals, i.e. the program will run on passing of day 1 from the current time, then on day 2, then day 4, day 8, day 16, day 32, day 64 and day 168.

I know how to run the script after every n minutes or every n days etc. using set_time = dt.datetime.now()+dt.timedelta(minutes=n)

Here is the full code for that:

# to send remainder to windows to run the command
def schedule_task(n=1):
     # import libraries
     import datetime as dt
     import win32com.client

     # Connection to task Scheduler
     task = win32com.client.Dispatch('Schedule.Service')
     task.Connect()
     root_folder = task.GetFolder('\\')
     newtask = task.NewTask(0)

     # Trigger
     # set_time=dt.datetime(2020,9,4,18,44,0,500000)   # refer to it for dates
     # for 1 minutes from current time
     set_time = dt.datetime.now() + dt.timedelta(minutes=n)

     # Action
     TASK_ACTION_EXEC = 0
     action = newtask.Actions.create(TASK_ACTION_EXEC)
     action.ID = 'DO NOTHING'
     action.Path = r'\Path\to\Programs\Python\Python39\python.exe'
     action.Arguments = r'Path\to\script.py'

     # Parameters
     newtask.RegistrationInfo.Description = 'Python Task Test'
     newtask.Settings.Enabled = True
     newtask.Settings.StopIfGoingOnBatteries = False

     # Saving
     TASK_CREATE_OR_UPDATE = 6
     TASK_LOGON_NONE = 0
     root_folder.RegisterTaskDefinition(
         'PTT', # Python Task Test
         newtask,
         TASK_CREATE_OR_UPDATE,
         '', # no user
         '', # no password
         TASK_LOGON_NONE)

but how do I set time such that the script runs after every 2^n days where n is between 0 to 7?

I have referred to this link also, and found the solution of calling command line (import os ) useful, but can't figure out how to use it to solve my problem

okay
  • 13
  • 1
  • 4

0 Answers0