Forums

Create task from script

Hi there! How do i create scheduled task from python script? Like a crontab:

cron = CronTab(user=True)
job = cron.new(command='python3 ~/send_to_bot.py', comment = dt_val)
job.day.on(int(dt_val[0:2]))
job.month.on(int(dt_val[2:4]))
job.hour.on(int(dt_val[5:7]))
job.minute.on(int(dt_val[7:9]))
cron.write()

Take a look at https://blog.pythonanywhere.com/190/

Thanks! It was helpful. But, how to schedule a task for a specific day? Example, i want to run a task on April 3 at 12:00. How to do it? Help please

We don't have a feature to set a task to be run on a specific date, but you can easily set this up in your code by adding a condition that checks the date and executes the relevant part when needed.