cronwords 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 episodely
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,45 @@
1
+ Metadata-Version: 2.4
2
+ Name: cronwords
3
+ Version: 0.1.0
4
+ Summary: Explain a cron expression in plain English.
5
+ Author: episodely
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/episodely/cronwords
8
+ Project-URL: Issues, https://github.com/episodely/cronwords/issues
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Operating System :: OS Independent
12
+ Requires-Python: >=3.8
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+ Dynamic: license-file
16
+
17
+ # cronwords
18
+
19
+ Explain a cron expression in plain English. Pure Python, no dependencies, offline.
20
+
21
+ ```
22
+ $ python cronwords.py "0 9 * * MON-FRI"
23
+ at 09:00 on Monday through Friday
24
+
25
+ $ python cronwords.py "*/15 * * * *"
26
+ every 15 minutes
27
+
28
+ $ python cronwords.py "@daily"
29
+ at 00:00 every day
30
+ ```
31
+
32
+ ```python
33
+ from cronwords import explain
34
+ explain("0 0 1 1 *") # 'at 00:00 on the 1st of the month in January'
35
+ ```
36
+
37
+ Supports lists (`1,3,5`), ranges (`MON-FRI`), steps (`*/10`), month and day names, `7` as Sunday, and `@hourly`, `@daily`, `@weekly`, `@monthly`, `@yearly`. Five fields only (no seconds, no Quartz `L` or `#`). Invalid input raises `ValueError` and the CLI exits with 1.
38
+
39
+ When both day-of-month and day-of-week are set, standard cron runs on either match; the wording says "and on".
40
+
41
+ ```
42
+ python -m pytest
43
+ ```
44
+
45
+ MIT licensed.
@@ -0,0 +1,29 @@
1
+ # cronwords
2
+
3
+ Explain a cron expression in plain English. Pure Python, no dependencies, offline.
4
+
5
+ ```
6
+ $ python cronwords.py "0 9 * * MON-FRI"
7
+ at 09:00 on Monday through Friday
8
+
9
+ $ python cronwords.py "*/15 * * * *"
10
+ every 15 minutes
11
+
12
+ $ python cronwords.py "@daily"
13
+ at 00:00 every day
14
+ ```
15
+
16
+ ```python
17
+ from cronwords import explain
18
+ explain("0 0 1 1 *") # 'at 00:00 on the 1st of the month in January'
19
+ ```
20
+
21
+ Supports lists (`1,3,5`), ranges (`MON-FRI`), steps (`*/10`), month and day names, `7` as Sunday, and `@hourly`, `@daily`, `@weekly`, `@monthly`, `@yearly`. Five fields only (no seconds, no Quartz `L` or `#`). Invalid input raises `ValueError` and the CLI exits with 1.
22
+
23
+ When both day-of-month and day-of-week are set, standard cron runs on either match; the wording says "and on".
24
+
25
+ ```
26
+ python -m pytest
27
+ ```
28
+
29
+ MIT licensed.
@@ -0,0 +1,45 @@
1
+ Metadata-Version: 2.4
2
+ Name: cronwords
3
+ Version: 0.1.0
4
+ Summary: Explain a cron expression in plain English.
5
+ Author: episodely
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/episodely/cronwords
8
+ Project-URL: Issues, https://github.com/episodely/cronwords/issues
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Operating System :: OS Independent
12
+ Requires-Python: >=3.8
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+ Dynamic: license-file
16
+
17
+ # cronwords
18
+
19
+ Explain a cron expression in plain English. Pure Python, no dependencies, offline.
20
+
21
+ ```
22
+ $ python cronwords.py "0 9 * * MON-FRI"
23
+ at 09:00 on Monday through Friday
24
+
25
+ $ python cronwords.py "*/15 * * * *"
26
+ every 15 minutes
27
+
28
+ $ python cronwords.py "@daily"
29
+ at 00:00 every day
30
+ ```
31
+
32
+ ```python
33
+ from cronwords import explain
34
+ explain("0 0 1 1 *") # 'at 00:00 on the 1st of the month in January'
35
+ ```
36
+
37
+ Supports lists (`1,3,5`), ranges (`MON-FRI`), steps (`*/10`), month and day names, `7` as Sunday, and `@hourly`, `@daily`, `@weekly`, `@monthly`, `@yearly`. Five fields only (no seconds, no Quartz `L` or `#`). Invalid input raises `ValueError` and the CLI exits with 1.
38
+
39
+ When both day-of-month and day-of-week are set, standard cron runs on either match; the wording says "and on".
40
+
41
+ ```
42
+ python -m pytest
43
+ ```
44
+
45
+ MIT licensed.
@@ -0,0 +1,9 @@
1
+ LICENSE
2
+ README.md
3
+ cronwords.py
4
+ pyproject.toml
5
+ cronwords.egg-info/PKG-INFO
6
+ cronwords.egg-info/SOURCES.txt
7
+ cronwords.egg-info/dependency_links.txt
8
+ cronwords.egg-info/entry_points.txt
9
+ cronwords.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ cronwords = cronwords:main
@@ -0,0 +1 @@
1
+ cronwords
@@ -0,0 +1,104 @@
1
+ """Explain a 5-field cron expression in plain English."""
2
+ import re, sys, argparse
3
+
4
+ MONTHS = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]
5
+ DAYS = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
6
+ ALIAS_M = {m[:3].upper(): i + 1 for i, m in enumerate(MONTHS)}
7
+ ALIAS_D = {d[:3].upper(): i for i, d in enumerate(DAYS)}
8
+ SPECIAL = {"@yearly": "0 0 1 1 *", "@annually": "0 0 1 1 *", "@monthly": "0 0 1 * *", "@weekly": "0 0 * * 0", "@daily": "0 0 * * *", "@midnight": "0 0 * * *", "@hourly": "0 * * * *"}
9
+
10
+ def _num(tok, alias):
11
+ t = tok.upper()
12
+ if t in alias:
13
+ return alias[t]
14
+ if not re.fullmatch(r"[0-9]{1,4}", tok):
15
+ raise ValueError(f"bad cron value: {tok[:20]}")
16
+ return int(tok)
17
+
18
+ def _ordinal(n):
19
+ return f"{n}{'th' if 10 <= n % 100 <= 20 else {1: 'st', 2: 'nd', 3: 'rd'}.get(n % 10, 'th')}"
20
+
21
+ def _join(items):
22
+ return items[0] if len(items) == 1 else ", ".join(items[:-1]) + " and " + items[-1]
23
+
24
+ def _field(f, lo, hi, alias, name_fn, unit):
25
+ """Return a phrase for one field, or None when it is '*'."""
26
+ if f in ("*", "?"):
27
+ return None
28
+ parts = []
29
+ for p in f.split(","):
30
+ m = re.fullmatch(r"(\*|[A-Za-z0-9]+(?:-[A-Za-z0-9]+)?)(?:/([0-9]{1,4}))?", p, re.ASCII)
31
+ if not m:
32
+ raise ValueError(f"bad cron field: {f}")
33
+ base, step = m.groups()
34
+ if step is not None and int(step) < 1:
35
+ raise ValueError(f"step must be at least 1: {f[:30]}")
36
+ if base == "*":
37
+ if not step:
38
+ return None
39
+ parts.append(f"every {step} {unit}s" if step != "1" else f"every {unit}")
40
+ continue
41
+ if "-" in base:
42
+ a, b = (_num(x, alias) for x in base.split("-"))
43
+ top = 7 if alias is ALIAS_D else hi
44
+ if not (lo <= a <= top and lo <= b <= top):
45
+ raise ValueError(f"range {base} out of range {lo}-{hi}")
46
+ if a > b:
47
+ raise ValueError(f"range start is after end: {base}")
48
+ rng = f"{name_fn(a)} through {name_fn(b)}"
49
+ parts.append(f"every {step} {unit}s from {rng}" if step else rng)
50
+ else:
51
+ v = _num(base, alias)
52
+ if not lo <= v <= hi and not (alias is ALIAS_D and v == 7):
53
+ raise ValueError(f"value {v} out of range {lo}-{hi}")
54
+ parts.append(f"every {step} {unit}s starting at {name_fn(v)}" if step else name_fn(v))
55
+ return _join(parts)
56
+
57
+ def explain(expr):
58
+ expr = SPECIAL.get(expr.strip().lower(), expr.strip())
59
+ if len(expr) > 200:
60
+ raise ValueError("expression too long")
61
+ f = expr.split()
62
+ if len(f) != 5:
63
+ raise ValueError("expected 5 fields: minute hour day-of-month month day-of-week")
64
+ mi, ho, dom, mon, dow = f
65
+ if re.fullmatch(r"[0-9]+", mi) and re.fullmatch(r"[0-9]+", ho):
66
+ h, m = int(ho), int(mi)
67
+ if not (0 <= h <= 23 and 0 <= m <= 59):
68
+ raise ValueError("hour or minute out of range")
69
+ when = f"at {h:02d}:{m:02d}"
70
+ else:
71
+ pm = _field(mi, 0, 59, {}, str, "minute")
72
+ ph = _field(ho, 0, 23, {}, str, "hour")
73
+ if pm is None and ph is None: when = "every minute"
74
+ elif ph is None and mi.isdigit(): when = f"at minute {mi} of every hour"
75
+ elif ph is None: when = pm
76
+ elif pm is None: when = f"every minute during hour {ph}" if not ho.isdigit() else f"every minute from {int(ho):02d}:00 to {int(ho):02d}:59"
77
+ else: when = (f"at minute {pm}" if mi.replace(",", "").isdigit() else pm) + (f", {ph}" if ph.startswith("every") else f", during hour {ph}")
78
+ out = [when]
79
+ d = _field(dom, 1, 31, {}, _ordinal_wrap, "day")
80
+ w = _field(dow, 0, 7, ALIAS_D, lambda v: DAYS[v % 7], "day")
81
+ mo = _field(mon, 1, 12, ALIAS_M, lambda v: MONTHS[v - 1], "month")
82
+ if d: out.append(f"on the {d} of the month" if re.fullmatch(r"[\d,]+", dom) else f"on {d} of the month")
83
+ if w: out.append(f"on {w}" if not d else f"and on {w}")
84
+ if mo: out.append(f"in {mo}")
85
+ if not (d or w or mo) and ho not in ("*", "?"):
86
+ out.append("every day")
87
+ return " ".join(out)
88
+
89
+ def _ordinal_wrap(v):
90
+ return _ordinal(v)
91
+
92
+ def main(argv=None):
93
+ ap = argparse.ArgumentParser(prog="cronwords")
94
+ ap.add_argument("expr", nargs="+", help='cron expression, quoted: "*/15 9-17 * * MON-FRI"')
95
+ a = ap.parse_args(argv)
96
+ try:
97
+ print(explain(" ".join(a.expr)))
98
+ except ValueError as e:
99
+ print(f"error: {e}", file=sys.stderr)
100
+ return 1
101
+ return 0
102
+
103
+ if __name__ == "__main__":
104
+ sys.exit(main())
@@ -0,0 +1,27 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "cronwords"
7
+ version = "0.1.0"
8
+ description = "Explain a cron expression in plain English."
9
+ readme = "README.md"
10
+ license = { text = "MIT" }
11
+ requires-python = ">=3.8"
12
+ authors = [{ name = "episodely" }]
13
+ classifiers = [
14
+ "License :: OSI Approved :: MIT License",
15
+ "Programming Language :: Python :: 3",
16
+ "Operating System :: OS Independent",
17
+ ]
18
+
19
+ [project.urls]
20
+ Homepage = "https://github.com/episodely/cronwords"
21
+ Issues = "https://github.com/episodely/cronwords/issues"
22
+
23
+ [project.scripts]
24
+ cronwords = "cronwords:main"
25
+
26
+ [tool.setuptools]
27
+ py-modules = ["cronwords"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+