I need to parse a crontab-like schedule definition in Python (e.g. 00 3 * * *) and get where this should have last run.
Is there a good (preferably small) library that parses these strings and translates them to dates?
0 * * * * -this means the cron will run always when the minutes are 0 (so hourly) 0 1 * * * - this means the cron will run always at 1 o'clock. * 1 * * * - this means the cron will run each minute when the hour is 1.
A cron expression is a string consisting of six or seven subexpressions (fields) that describe individual details of the schedule. These fields, separated by white space, can contain any of the allowed values with various combinations of the allowed characters for that field.
The quick and simple editor for cron schedule expressions by Cronitor.
Perhaps the python package croniter suits your needs.
Usage example:
>>> import croniter >>> import datetime >>> now = datetime.datetime.now() >>> cron = croniter.croniter('45 17 */2 * *', now) >>> cron.get_next(datetime.datetime) datetime.datetime(2011, 9, 14, 17, 45) >>> cron.get_next(datetime.datetime) datetime.datetime(2011, 9, 16, 17, 45) >>> cron.get_next(datetime.datetime) datetime.datetime(2011, 9, 18, 17, 45)
Maybe you can use this module:
http://code.activestate.com/recipes/577466-cron-like-triggers/
I used that module for making an user-space cron in Python and it works very well. This module can handle crontab-like lines.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With