A simple Python Cron Expression lib
Project description
Python Cron Expression
This is a simple library for making cron job expression. User need to pass timestamp or datetime object to create cron job expression.
Installation
pip install PyCronExpression
Feature List
Name | status |
---|---|
Timestamp or datetime object | done |
Minute | done |
Hourly | done |
Daily | Done |
Weekly | Comming |
Example
Timestamp or datetime object
from datetime import datetime
from py_cron_expression import CronJobExpression
cron_job = CronJobExpression()
timestamp = int(datetime.now().timestamp())
res = cron_job.cron_expression(time=timestamp)
print(res)
# Output
# 10 55 13 2 5 ? 2020
# If you want to remove second from in your cron job expression.
# Then you need to add cancel='second'
# example
cron_job.cron_expression(time=timestamp, cancel='second')
# Output
# 55 13 2 5 ? 2020
If you need to convert the cron job expression to other timezone. Please follow the example. By default your will get the cron job expression as your local timezone.
from datetime import datetime
from py_cron_expression import CronJobExpression
cron_job = CronJobExpression()
timestamp = int(datetime.now().timestamp())
res = cron_job.cron_expression(time=timestamp, timezone='Asia/Dhaka')
print(res)
# Output
# 10 55 13 2 5 ? 2020
Below features will give you two types of cron expression 1. AWS platform and 2. Linux. Both platforms are not supported second. So by default removed the second from the expression
Minute
from py_cron_expression import CronJobExpression
cron = CronJobExpression()
minute = cron.minute(platform="aws", minutes=10)
print(minute)
# */10 * * * ? *
# Every 10 minutes starting at :00 minute after the hour
minute = cron.minute(platform="linux", minutes=10)
print(minute)
# */10 * * * *
# Every 10 minutes starting at :00 minute after the hour
Hourly
from py_cron_expression import CronJobExpression
cron = CronJobExpression()
hourly = cron.hourly(platform="aws", minutes=1)
print(hourly)
# * */1 * * ? *
# Every hour starting at 00am
hourly = cron.hourly(platform="linux", minutes=1)
print(hourly)
# * */1 * * *
# Every hour starting at 00am
Daily
from py_cron_expression import CronJobExpression
cron = CronJobExpression()
daily = cron.daily(platform="aws", minutes=1)
print(daily)
# 0 1 * * ? *
# At 01:00:00am every day
daily = cron.daily(platform="linux", minutes=1)
print(daily)
# 0 1 * * *
# At 01:00:00am every day
Explanation:
Linux platform Cron Expressions Definition (crontab)
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
Linux platform cron job definition
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7)
# | | | | |
# * * * * *
AWS Platform Cron Expressions Definition
# .---------------------- minute (0 - 59)
# | .------------------- hour (0 - 23)
# | | .---------------- day of month (1 - 31)
# | | | .------------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---------- day of week (0 - 6) (Sunday=0 or 7)
# | | | | | .-------- year
# | | | | | |
# * * * * ? *
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file PyCronExpression-0.0.7.tar.gz
.
File metadata
- Download URL: PyCronExpression-0.0.7.tar.gz
- Upload date:
- Size: 4.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2c5bc5985c3f715af6cb584ce1ec247038eabcb894e043eb93b4a34919b6e6f2 |
|
MD5 | ae4f1c1861a0c1283185b0ad4655d2e7 |
|
BLAKE2b-256 | ece60d0de49aa33f8720315910c6e0c5f31a602f18635be9f596c0e063eae378 |
File details
Details for the file PyCronExpression-0.0.7-py3-none-any.whl
.
File metadata
- Download URL: PyCronExpression-0.0.7-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1251ff05037642b4974ab6b5c1be61618436f700ed697549f0547d5da05091d0 |
|
MD5 | 11db1db0b935f7cfa3b6aeefaaf03deb |
|
BLAKE2b-256 | d0cf0276998eb6bb95c5dd718b182342bcc98fd448ad6fafa7e22570edfb5111 |