Parsing crontab-style lines

Question:

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?

Asked By: Krumelur

||

Answers:

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.

Answered By: Diego Navarro

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)
Answered By: HAL
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.