Can the schedule program execute on specific seconds?

Viewed 50

I am trying to create a program that can execute on a specific time every day, but I wonder if there's a way to make this program more precise to execute on specific seconds.

import time
import schedule


def func():
    print("ok")


schedule.every().day.at("20:55").do(func)

while True:
    schedule.run_pending()
    time.sleep(1)
1 Answers

Yes, it is pretty simple. You could do something like this:

import schedule
import time
import datetime


def func():
    print("Working now")
    print(datetime.datetime.now())

schedule.every().day.at("15:50:15").do(func)

while True:
    schedule.run_pending()
    time.sleep(1)

Your func will be executed each day at 15:50:15, where the last number of course indicates the seconds. You can verify it with the second print inside func.

Related