Search code examples
pythonpython-2.7python-3.xscheduled-tasksapscheduler

python script advanced scheduling


I'm trying to do something really complicated. Using a Windows box, I'm try to get a script to run every half-an-hour, Mon-Fri, 9:00am-7:00pm, skipping certain dates I define as "holidays". I would love for Python to run this script itself. I've looked into 'apschedule', but can't seem to find the right options I need to do this. If not able to do this through Python, what other solutions can I look at?

By the way, as of right now, I'm running Python 3.3, but am willing to downgrade if necessary.


Solution

  • decorate your job-functions to skip the special days:

    from datetime import date
    
    def not_on(dates):
        def noop(): pass
        def decor(fn):
            if date.today() in dates:
                return noop
            else:
                return fn
        return decor
    
    
    @not_on( ( date(2013, 03, 01), ) )
    def job():
        print "yeah"
    

    then just schedule your jobs for the regular dates and done. if the job is called on a special day the decorator will just skip execution.

    just keep using apscheduler.