Hello! ๐
- ๐ I'm Tom
- ๐ I live in London
- ๐ I like Python
- ๐ฆ And rust
- ๐ check out my blog
Parse crontab expressions with Python
Hello! ๐
โฏ crontabula '0 0 1 * *'
minute 0
hour 0
day of month 1
month 1 2 3 4 5 6 7 8 9 10 11 12
day of week 0 1 2 3 4 5 6
next time 2022-05-10 00:00:00 (in 8:05:39.521698)
You can reach this state by iterating over all dates, or probably more commonly by using a cron expression which doesn't make sense like 30th February
>>> import crontabula
>>> crontabula.parse('0 0 30 2 *').next
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "redacted/lib/python3.9/site-packages/crontabula/__init__.py", line 43, in next
return next(self.date_times())
File "redacted/lib/python3.9/site-packages/crontabula/__init__.py", line 60, in date_times
for day in self.dates(anchor_date):
File "redacted/lib/python3.9/site-packages/crontabula/__init__.py", line 115, in dates
anchor = datetime.date(year=anchor.year + 1, month=1, day=1)
ValueError: year 10000 is out of range
We'd have to decide whether to make the .next
return type Optional[datetime.datetime]
or raise an error of its own. I think I prefer the latter
This line raises an error because it tries to create a date with day = 0
crontabula/crontabula/__init__.py
Line 101 in 241832a
import crontabula
from datetime import datetime
from itertools import islice
cron = crontabula.parse('*/5 * * * *')
start = datetime(2022, 5, 16, 11, 30)
for n in islice(cron.date_times(start), 12):
print(n)
2022-05-16 11:30:00
2022-05-16 11:35:00
2022-05-16 11:40:00
2022-05-16 11:45:00
2022-05-16 11:50:00
2022-05-16 11:55:00
# 12:00-12:25 are missing
2022-05-16 12:30:00
2022-05-16 12:35:00
2022-05-16 12:40:00
2022-05-16 12:45:00
2022-05-16 12:50:00
2022-05-16 12:55:00
Sorry if you just didn't get to it, but it would be great if the 0.1.7 release could be pushed to PyPI.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.