Template request | Bug report | Generate Data Product
Tags: #python #cron #croniter #job #occurrences #scheduling
Author: Florent Ravenel
Description: This notebook will show how to get the next x occurrences of your cron job using croniter. It is usefull for organizations to schedule tasks and jobs.
References:
try:
import croniter
except:
!pip install croniter --user
import croniter
import pytz
from datetime import datetime
cron_expression
: cron expression to be usedoccurrences
: number of occurrences to be returnedtimezone
: timezone identifier
cron_expression = "*/15 * * * *"
occurrences = 5
timezone = 'Europe/Paris'
# Set the timezone
tz = pytz.timezone(timezone)
# Create a cron iterator with the timezone
cron = croniter.croniter(cron_expression, datetime.now(tz), tz)
for i in range(occurrences):
next_occurrence = cron.get_next(datetime)
print(next_occurrence.strftime('%A, %B %d, %Y at %I:%M %p'))