解析crontab样式的行 [英] Parsing crontab-style lines

查看:97
本文介绍了解析crontab样式的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在Python中解析类似crontab的时间表定义(例如00 3 * * *),并获取上次运行的位置。

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包croniter 满足您的需求。

Perhaps the python package croniter suits your needs.

用法示例:

>>> 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)

这篇关于解析crontab样式的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆