项目作者: Salamek

项目描述 :
A Python library that converts cron expressions into human readable strings.
高级语言: Python
项目地址: git://github.com/Salamek/cron-descriptor.git
创建时间: 2016-01-16T17:58:39Z
项目社区:https://github.com/Salamek/cron-descriptor

开源协议:MIT License

下载


Cron Descriptor

Python tests
Donate

A Python library that converts cron expressions into human readable strings. Ported to Python from https://github.com/bradyholt/cron-expression-descriptor.

Author: Adam Schubert (https://www.salamek.cz)
Original Author & Credit: Brady Holt (http://www.geekytidbits.com)
License: MIT

Features

  • Supports all cron expression special characters including * / , - ? L W, #
  • Supports 5, 6 (w/ seconds or year), or 7 (w/ seconds and year) part cron expressions
  • Provides casing options (Sentence, Title, Lower, etc.)
  • Localization with support for 17 languages
  • Supports Python 3.8 - 3.12

Installation

Using PIP

  1. pip install cron-descriptor

Usage example

Simple

  1. from cron_descriptor import get_description, ExpressionDescriptor
  2. print(get_description("* 2 3 * *"))
  3. #OR
  4. print(str(ExpressionDescriptor("* 2 3 * *")))

Advanced

  1. # Consult Options.py/CasingTypeEnum.py/DescriptionTypeEnum.py for more info
  2. from cron_descriptor import Options, CasingTypeEnum, DescriptionTypeEnum, ExpressionDescriptor
  3. descriptor = ExpressionDescriptor(
  4. expression = "*/10 * * * *",
  5. casing_type = CasingTypeEnum.Sentence,
  6. use_24hour_time_format = True
  7. )
  8. # GetDescription uses DescriptionTypeEnum.FULL by default:
  9. print(descriptor.get_description())
  10. print("{}".format(descriptor))
  11. # Or passing Options class as second argument:
  12. options = Options()
  13. options.casing_type = CasingTypeEnum.Sentence
  14. options.use_24hour_time_format = True
  15. descriptor = ExpressionDescriptor("*/10 * * * *", options)
  16. print(descriptor.get_description(DescriptionTypeEnum.FULL))

Languages Available

Language Locale Code Contributor
English en Brady Holt
Brazilian pt_PT Renato Lima
Chinese Simplified zh_CN Star Peng
Spanish es_ES Ivan Santos
Norwegian nb_NO Siarhei Khalipski
Turkish tr_TR Mustafa SADEDİL
Dutch nl_NL TotalMace
Russian ru_RU LbISS
French fr_FR Arnaud TAMAILLON
German de_DE Michael Schuler
Ukrainian uk_UA Taras
Italian it_IT rinaldihno
Czech cs_CZ Adam Schubert
Swedish sv_SE Åke Engelbrektson
Tamil ta_IN Sankar Hari
Persian fa_IR M. Yas. Davoodeh
Korean ko_KR KyuJoo Han
Japanese ja_JP Tho Nguyen

Original Source

Ports

Running Unit Tests

  1. python setup.py test

Translating

cron-descriptor is using Gettext for translations.

To create new translation or edit existing one, i suggest using Poedit.

You can copy/rename and translate any file from locale directory:

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

or you can generate new untranslated *.po file from sources by running in cron_descriptor directory:

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

Generating .mo file from .po file. In root directory run command:

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

Developing

All suggestions and PR’s are welcomed

Just clone this repository and register pre-commit hook by running:

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

Then install dev requirements:

  1. pip install ruff