dbader / schedule

Python job scheduling for humans.
https://schedule.readthedocs.io/
MIT License
11.83k stars 965 forks source link

Error Scheduling #461

Closed redkad closed 3 years ago

redkad commented 3 years ago

I was wondering if there's a way to schedule a function to run from a particular time to another time and repeat the same process each day?

SijmenHuizenga commented 3 years ago

I'm not exactly sure what you mean. Could you elaborate a bit more?

If i'm taking a wild guess you want to run a job every second/minute/hour between some period of time every day. This can be achieved by running a job continuously and check if the current time is in the period that it needs to run at.

This example shows how to run a job every hour between 09:00 and 17:00:

import schedule
import datetime

def hourly():
    hour_now = datetime.datetime.now().hour
    if hour_now >= 9 and hour_now < 17:
        print("I run every hour between 09:00 and 17:00")
    pass

schedule.every().hour.do(hourly)

print(schedule.next_run())
redkad commented 3 years ago

Thank you.