dbader / schedule

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

Is there a way to not having to hardcode the days in the schedule? #496

Closed theopfr closed 2 years ago

theopfr commented 2 years ago

I need to read the day, at which the job should run, out of a config file. Therefore I need a way to specify the day in the scheduler as an argument. For example like this:

# how it could look like with a dynamic argument for the days:
schedule.every().day("monday").at("06:00").do(execute_job)

# vs. how I works right now with the day hardcoded: 
schedule.every().monday.at("06:00").do(execute_job)

I didn't find a way to do that. The only workaround that I can think of is by using eval():

day = "monday"
eval(f"schedule.every().{day}('06:00').do(execute_job)")

As long as Im not missing anything, I think it would be nice if such a functionality is added.

Wissperwind commented 2 years ago

Would fit to my feature request to support cron tab expressions.

SijmenHuizenga commented 2 years ago

You could achieve dynamic days like this:

day = 'monday'
getattr(schedule.every(), day).at('06:00').do(execute_job)