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

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

问题描述

我需要在 Python 中解析类似 crontab 的计划定义(例如 00 3 * * *),并找到它应该最后运行的位置.

是否有一个好的(最好是小的)库来解析这些字符串并将它们转换为日期?

解决方案

也许 python 包 croniter 适合你的需求.

使用示例:

<预><代码>>>>进口克朗特>>>导入日期时间>>>现在 = 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)

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?

解决方案

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)

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

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