Parsing crontab-style lines

微笑、不失礼 提交于 2019-11-28 21:14:52

问题


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?


回答1:


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)



回答2:


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.



来源:https://stackoverflow.com/questions/7390170/parsing-crontab-style-lines

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!