Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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?

python-crontab was one of the first solutions I investigated, and it does not have the functionality to get the dates. Krumelur Sep 13, 2011 at 9:09 Now that I know what I'm looking for, I believe this is more a duplicate of stackoverflow.com/questions/4610904/… Krumelur Sep 13, 2011 at 9:19 >>> 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) +1 for croniter. I was looking for a Python equivalent of Java's Spring CronTrigger . I find the latter's API a bit more natural, although I don't really like either. I would rather favor a stateless and immutable object instead, e.g. cronExpr = CronExpression.compile("0 0 * * * "); datetime = cronExpr.next(datetime); . Pierre D Nov 7, 2015 at 1:05

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.

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question . Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers .