|
| 1 | +========= |
| 2 | +crontools |
| 3 | +========= |
| 4 | + |
| 5 | +Features: |
| 6 | + |
| 7 | +- crontab expression parser |
| 8 | +- optional seconds field support |
| 9 | +- optional year field support |
| 10 | +- crontab fire time sequential iteration support |
| 11 | + |
| 12 | +Installation |
| 13 | +------------ |
| 14 | + |
| 15 | +You can install crontools with pip: |
| 16 | + |
| 17 | +.. code-block:: console |
| 18 | +
|
| 19 | + $ pip install crontools |
| 20 | +
|
| 21 | +
|
| 22 | +Quickstart |
| 23 | +---------- |
| 24 | + |
| 25 | +On the server side everything is also pretty straightforward: |
| 26 | + |
| 27 | +.. code-block:: python |
| 28 | +
|
| 29 | + import datetime as dt |
| 30 | + import crontools as ct |
| 31 | +
|
| 32 | + tz = dt.timezone.utc |
| 33 | + now = dt.datetime.fromisoformat('2021-02-01 00:00:00+00:00') |
| 34 | + ct = ct.Crontab.parse( |
| 35 | + '30 30 12-16/2 1,2 JAN SAT,SUN *', |
| 36 | + seconds_ext=True, |
| 37 | + years_ext=True, |
| 38 | + tz=tz, |
| 39 | + ) |
| 40 | +
|
| 41 | + cron_iter = ct.iter(start_from=now) |
| 42 | + for n, fire_datetime in zip(range(1, 31), cron_iter): |
| 43 | + print("{n:2}: {dt}".format(n=n, dt=fire_datetime)) |
| 44 | +
|
| 45 | + output: |
| 46 | +
|
| 47 | + 1: 2022-01-01 12:30:30+00:00 |
| 48 | + 2: 2022-01-01 14:30:30+00:00 |
| 49 | + 3: 2022-01-01 16:30:30+00:00 |
| 50 | + 4: 2022-01-02 12:30:30+00:00 |
| 51 | + 5: 2022-01-02 14:30:30+00:00 |
| 52 | + 6: 2022-01-02 16:30:30+00:00 |
| 53 | + 7: 2022-01-08 12:30:30+00:00 |
| 54 | + 8: 2022-01-08 14:30:30+00:00 |
| 55 | + 9: 2022-01-08 16:30:30+00:00 |
| 56 | + 10: 2022-01-09 12:30:30+00:00 |
| 57 | + 11: 2022-01-09 14:30:30+00:00 |
| 58 | + 12: 2022-01-09 16:30:30+00:00 |
| 59 | + 13: 2022-01-15 12:30:30+00:00 |
| 60 | + 14: 2022-01-15 14:30:30+00:00 |
| 61 | + 15: 2022-01-15 16:30:30+00:00 |
| 62 | + 16: 2022-01-16 12:30:30+00:00 |
| 63 | + 17: 2022-01-16 14:30:30+00:00 |
| 64 | + 18: 2022-01-16 16:30:30+00:00 |
| 65 | + 19: 2022-01-22 12:30:30+00:00 |
| 66 | + 20: 2022-01-22 14:30:30+00:00 |
| 67 | + 21: 2022-01-22 16:30:30+00:00 |
| 68 | + 22: 2022-01-23 12:30:30+00:00 |
| 69 | + 23: 2022-01-23 14:30:30+00:00 |
| 70 | + 24: 2022-01-23 16:30:30+00:00 |
| 71 | + 25: 2023-01-01 12:30:30+00:00 |
| 72 | + 26: 2023-01-01 14:30:30+00:00 |
| 73 | + 27: 2023-01-01 16:30:30+00:00 |
| 74 | + 28: 2023-01-02 12:30:30+00:00 |
| 75 | + 29: 2023-01-02 14:30:30+00:00 |
| 76 | + 30: 2023-01-02 16:30:30+00:00 |
0 commit comments