Python Forum

Full Version: How to trigger python script twice a day
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,
I want to trigger my python program every day at 8 am & 11 pm. I try to test this using below code, but the program did work well.

import schedule
import time

def job():
    print("I'm working...")
schedule.every().day.at("23:06").do(job)
print('hi at 23:06')
schedule.every().day.at("23:08").do(job)
print('Hi 23:08')
How to trigger at specified times?
I didn't use schedule module before, but it seems from docs that you need to run it in an infinite loop, i.e. your code should be something like this:

import schedule
import time
 
def job():
    print("I'm working...")
    print("hi at %s" % time.ctime())

schedule.every().day.at("23:06").do(job)
schedule.every().day.at("23:08").do(job)

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