跳转到主要内容

一个将cron表达式转换为可读字符串的Python库。

项目描述

Cron Descriptor

Python tests Donate

Cron Descriptor是一个将cron表达式转换为可读字符串的Python库。从https://github.com/bradyholt/cron-expression-descriptor迁移到Python。

作者: Adam Schubert (https://www.salamek.cz)
原作者及致谢: Brady Holt (http://www.geekytidbits.com)
许可协议: MIT

功能

  • 支持所有cron表达式特殊字符,包括 * / , - ? L W, #
  • 支持5、6(带有秒或年)或7(带有秒和年)部分的cron表达式
  • 提供大小写选项(句子、标题、小写等)
  • 支持17种语言的本地化
  • 支持Python 3.8 - 3.12

安装

使用PIP

pip install cron-descriptor

使用示例

简单

from cron_descriptor import get_description, ExpressionDescriptor

print(get_description("* 2 3 * *"))

#OR

print(str(ExpressionDescriptor("* 2 3 * *")))

高级

# Consult Options.py/CasingTypeEnum.py/DescriptionTypeEnum.py for more info
from cron_descriptor import Options, CasingTypeEnum, DescriptionTypeEnum, ExpressionDescriptor

descriptor = ExpressionDescriptor(
    expression = "*/10 * * * *",
    casing_type = CasingTypeEnum.Sentence,
    use_24hour_time_format = True
)

# GetDescription uses DescriptionTypeEnum.FULL by default:
print(descriptor.get_description())
print("{}".format(descriptor))

# Or passing Options class as second argument:

options = Options()
options.casing_type = CasingTypeEnum.Sentence
options.use_24hour_time_format = True
descriptor = ExpressionDescriptor("*/10 * * * *", options)
print(descriptor.get_description(DescriptionTypeEnum.FULL))

可用的语言

语言 区域代码 贡献者
英语 en Brady Holt
巴西语 pt_PT Renato Lima
简体中文 zh_CN Star Peng
西班牙语 es_ES Ivan Santos
挪威语 nb_NO Siarhei Khalipski
土耳其语 tr_TR Mustafa SADEDİL
荷兰语 nl_NL TotalMace
俄语 ru_RU LbISS
法语 fr_FR Arnaud TAMAILLON
德语 de_DE Michael Schuler
乌克兰语 uk_UA Taras
意大利语 it_IT rinaldihno
捷克语 cs_CZ Adam Schubert
瑞典语 sv_SE Åke Engelbrektson
泰米尔语 ta_IN Sankar Hari
波斯语 fa_IR M. Yas. Davoodeh
韩语 ko_KR KyuJoo Han
日语 ja_JP Tho Nguyen

原始来源

端口

运行单元测试

python setup.py test

翻译

cron-descriptor 使用 Gettext 进行翻译。

要创建新的翻译或编辑现有的翻译,建议使用 Poedit

您可以从 locale 目录复制/重命名并翻译任何文件

cp ./cron_descriptor/locale/de_DE.po ./cron_descriptor/locale/YOUR_LOCALE_CODE.po
poedit ./cron_descriptor/locale/YOUR_LOCALE_CODE.po

或者您可以在 cron_descriptor 目录中运行以从源生成新的未翻译的 *.po 文件

cd cron_descriptor
xgettext *.py -o locale/YOUR_LOCALE_CODE.po

从 *.po 文件生成 *.mo 文件。在根目录中运行以下命令

msgfmt -o cron_descriptor/locale/YOUR_LOCALE_CODE.mo cron_descriptor/locale/YOUR_LOCALE_CODE.po

开发

欢迎所有建议和 PR

只需克隆此存储库并通过运行以下命令注册 pre-commit 钩子

ln -s ../../pre-commit.sh .git/hooks/pre-commit

然后安装开发需求

pip install ruff

项目详情


下载文件

下载适用于您平台的文件。如果您不确定选择哪个,请了解有关 安装包 的更多信息。

源代码分发

cron_descriptor-1.4.5.tar.gz (30.7 kB 查看哈希值)

上传时间

构建分发

cron_descriptor-1.4.5-py3-none-any.whl (50.4 kB 查看哈希值)

上传时间 Python 3

支持