Parsing crontab-style lines

前端 未结 2 2073
孤独总比滥情好
孤独总比滥情好 2020-12-24 06:39

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 th

2条回答
  •  爱一瞬间的悲伤
    2020-12-24 07:04

    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)
    

提交回复
热议问题