Issue
I would like to take a list of all the cron expressions that the get back from calling a boto3 api call. Take take that list and convert it into calendar dates for the current month. This way I can use the dates for the backend to look at the events on a calendar.
The current problem I am facing is that I can't find a library in python for parsing AWS cron strings and definitely not a library which does both parsing and cron to date conversion.
Does anyone know of any python libraries for such work?
AWS cron strings are different than cron/crontab.
https://docs.aws.amazon.com/glue/latest/dg/monitor-data-warehouse-schedule.html
cron(Minutes Hours Day-of-month Month Day-of-week Year)
Wildcards
The , (comma) wildcard includes additional values. In the Month field, JAN,FEB,MAR would include January, February, and March.
The - (dash) wildcard specifies ranges. In the Day field, 1–15 would include days 1 through 15 of the specified month.
The * (asterisk) wildcard includes all values in the field. In the Hours field, * would include every hour.
The / (forward slash) wildcard specifies increments. In the Minutes field, you could enter 1/10 to specify every 10th minute, starting from the first minute of the hour (for example, the 11th, 21st, and 31st minute).
The ? (question mark) wildcard specifies one or another. In the Day-of-month field you could enter 7, and if you didn't care what day of the week the seventh was, you could enter ? in the Day-of-week field.
The L wildcard in the Day-of-month or Day-of-week fields specifies the last day of the month or week.
The W wildcard in the Day-of-month field specifies a weekday. In the Day-of-month field, 3W specifies the day closest to the third weekday of the month.
Limits
You can't specify the Day-of-month and Day-of-week fields in the same cron expression. If you specify a value in one of the fields, you must use a ? (question mark) in the other.
Cron expressions that lead to rates faster than 5 minutes are not supported.
Solution
pyawscron:
https://github.com/pitchblack408/pyawscron
https://pypi.org/project/pyawscron/
Which is a python port from a typescript project:
https://github.com/beemhq/aws-cron-parser
cron = '23,24,25 17,18 25 MAR/4 ? 2020,2021,2023,2028'
cron = AWSCron(cron)
dt = datetime.datetime(2020, 5, 9, 22, 30, 57, tzinfo=datetime.timezone.utc)
dt = cron.occurrence(dt).next()
Answered By - pitchblack408 Answer Checked By - David Goodson (WPSolving Volunteer)