# cronslator
## Natural Language to Cron
A Python 3.9+ library to convert an English string to cron schedule.
## Important
> This is not the library you are looking for!
This codebase was generated entirely from prompting
GitHub Copilot (Clause 3.5 Sonnet) and has not been
audited, verified or even assumed to be correct.
This is an experiment to tinker with new shiny tools,
and to share what's possible using them -
your takeaway could be "Wow, that's nice!" or "Wow, that's crap!"
and either are fine.
Beyond this line, there is no human written text or code,
it is all LLM generated slop (hence the org name pyslop!).
## Understanding Cron Format
The cron expressions generated follow the standard 5-field format:
```ascii
┌───────────── minute (0 - 59)
│ ┌───────────── hour (0 - 23)
│ │ ┌───────────── day of month (1 - 31)
│ │ │ ┌───────────── month (1 - 12)
│ │ │ │ ┌───────────── day of week (0 - 6) (Sunday to Saturday)
│ │ │ │ │
* * * * *
```
Special characters:
- `*`: any value
- `,`: value list separator
- `-`: range of values
- `/`: step values
- `L`: last day of month (only in day of month field)
Supported patterns:
| Natural Language Description | Cron Expression |
|----------------------------|-----------------|
| Every Monday at 3am | `0 3 * * 1` |
| Every weekday at noon | `0 12 * * 1-5` |
| Every 15 minutes | `*/15 * * * *` |
| First day of every month at midnight | `0 0 1 * *` |
| Every Sunday at 4:30 PM | `30 16 * * 0` |
| Every hour on the half hour | `30 * * * *` |
| Every day at 2am and 2pm | `0 2,14 * * *` |
| Every 30 minutes between 9am and 5pm on weekdays | `*/30 9-17 * * 1-5` |
| First Monday of every month at 3am | `0 3 1-7 * 1` |
| Every quarter hour between 2pm and 6pm | `*/15 14-18 * * *` |
| Every weekend at 10pm | `0 22 * * 0,6` |
| Every 5 minutes during business hours | `*/5 9-17 * * 1-5` |
| 3rd day of every month at 1:30am | `30 1 3 * *` |
| Every weekday at 9am, 1pm and 5pm | `0 9,13,17 * * 1-5` |
| At midnight on Mondays and Fridays | `0 0 * * 1,5` |
| Twice daily at 6:30 and 18:30 | `30 6,18 * * *` |
| Monthly on the 15th at noon | `0 12 15 * *` |
| Three times per hour at 15, 30, and 45 minutes | `15,30,45 * * * *` |
| Last day of month at 11:59 PM | `59 23 L * *` |
| Weekdays at quarter past each hour | `15 * * * 1-5` |
| Once per hour in the first 15 minutes | `0-14 * * * *` |
| Workdays at 8:45 AM except on the 13th | `45 8 1-12,14-31 * 1-5` |
| First 5 days of each quarter at dawn | `0 6 1-5 1,4,7,10 *` |
## Usage
### As a Command Line Tool
After installation, you can use the `cronslate` command:
```bash
# Basic usage
cronslate "Every Monday at 3am"
# Output: 0 3 * * 1
# Using quotes is optional for simple phrases
cronslate Every Monday at 3am
# Output: 0 3 * * 1
# Pipe input from other commands
echo "Every 15 minutes" | cronslate
# Output: */15 * * * *
```
### As a Python Library
Basic usage:
```python
from pyslop.cronslator import cronslate
# Simple schedule
result = cronslate("Every Monday at 3am")
print(result) # Output: 0 3 * * 1
# Multiple times
result = cronslate("Every day at 2am and 2pm")
print(result) # Output: 0 2,14 * * *
# Complex schedules
result = cronslate("Every 30 minutes between 9am and 5pm on weekdays")
print(result) # Output: */30 9-17 * * 1-5
```
Error handling:
```python
from pyslop.cronslator import cronslate
try:
# This will raise a ValueError
result = cronslate("at 25:00")
except ValueError as e:
print(f"Error: {e}")
# Invalid inputs will raise ValueError:
invalid_inputs = [
"", # Empty string
"invalid cron string", # Nonsense input
"at 25:00", # Invalid hour
"on day 32", # Invalid day
]
for input_str in invalid_inputs:
try:
cronslate(input_str)
except ValueError as e:
print(f"'{input_str}' is invalid: {e}")
```
Complete script example:
```python
#!/usr/bin/env python3
from pyslop.cronslator import cronslate
def process_schedules():
schedules = [
"Every Monday at 3am",
"Every weekday at noon",
"Every 15 minutes",
"First day of every month at midnight",
"Every Sunday at 4:30 PM"
]
print("Natural Language → Cron Expression")
print("─" * 40)
for schedule in schedules:
try:
cron = cronslate(schedule)
print(f"{schedule:<30} → {cron}")
except ValueError as e:
print(f"{schedule:<30} → Error: {e}")
if __name__ == "__main__":
process_schedules()
# Output:
# Natural Language → Cron Expression
# ─────────────────────────────────────────────
# Every Monday at 3am → 0 3 * * 1
# Every weekday at noon → 0 12 * * 1-5
# Every 15 minutes → */15 * * *
# First day of every month... → 0 0 1 * *
# Every Sunday at 4:30 PM → 30 16 * * 0
```
## Installation
Install from PyPI using pipx (recommended):
```bash
# Install pipx if you haven't already
python -m pip install --user pipx
python -m pipx ensurepath
# Install from PyPI
pipx install pyslop-cronslator
# Or install from TestPyPI
pipx install --pip-args="--index-url https://test.pypi.org/simple/ --no-deps" pyslop-cronslator
```
Or install from PyPI using pip:
```bash
pip install pyslop-cronslator
```
Or install from source:
```bash
git clone https://github.com/pyslop/cronslator.git
cd cronslator
pip install .
```
## Development
Clone and set up development environment:
```bash
# Clone the repository
git clone https://github.com/pyslop/cronslator.git
cd cronslator
# Install poetry if you haven't already
pip install poetry
# Install dependencies and development dependencies
poetry install
# Run tests
poetry run pytest
# Run specific test file
poetry run pytest tests/test_readme_examples.py
```
### Publishing to PyPI
For maintainers, to publish a new version:
```bash
# Update version in pyproject.toml first, then:
# Build the package
poetry build
# Configure TestPyPI repository (one-time setup)
poetry config repositories.testpypi https://test.pypi.org/legacy/
# Publish to TestPyPI first (requires TestPyPI credentials)
poetry publish -r testpypi
# Test the package from TestPyPI
pip install --index-url https://test.pypi.org/simple/ --no-deps pyslop-cronslator
# If everything looks good, publish to PyPI (requires PyPI credentials)
poetry publish
# Or do both build and publish in one step
poetry publish --build
```
Raw data
{
"_id": null,
"home_page": "https://github.com/pyslop/cronslator",
"name": "pyslop-cronslator",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.9",
"maintainer_email": null,
"keywords": "cron, natural language, schedule, translator",
"author": "Harshad Sharma",
"author_email": "harshad@sharma.io",
"download_url": "https://files.pythonhosted.org/packages/d1/10/6aa3a297cd73570bb1651b7eaeeee9f5f7a9be67035efd6ff267ed69ac7f/pyslop_cronslator-0.2.3.tar.gz",
"platform": null,
"description": "# cronslator\n\n## Natural Language to Cron\n\nA Python 3.9+ library to convert an English string to cron schedule.\n\n## Important\n\n> This is not the library you are looking for!\n\nThis codebase was generated entirely from prompting\nGitHub Copilot (Clause 3.5 Sonnet) and has not been\naudited, verified or even assumed to be correct.\n\nThis is an experiment to tinker with new shiny tools,\nand to share what's possible using them -\nyour takeaway could be \"Wow, that's nice!\" or \"Wow, that's crap!\"\nand either are fine.\n\nBeyond this line, there is no human written text or code,\nit is all LLM generated slop (hence the org name pyslop!).\n\n## Understanding Cron Format\n\nThe cron expressions generated follow the standard 5-field format:\n\n```ascii\n\u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 minute (0 - 59)\n\u2502 \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 hour (0 - 23)\n\u2502 \u2502 \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 day of month (1 - 31)\n\u2502 \u2502 \u2502 \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 month (1 - 12)\n\u2502 \u2502 \u2502 \u2502 \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 day of week (0 - 6) (Sunday to Saturday)\n\u2502 \u2502 \u2502 \u2502 \u2502\n* * * * *\n```\n\nSpecial characters:\n\n- `*`: any value\n- `,`: value list separator\n- `-`: range of values\n- `/`: step values\n- `L`: last day of month (only in day of month field)\n\nSupported patterns:\n\n| Natural Language Description | Cron Expression |\n|----------------------------|-----------------|\n| Every Monday at 3am | `0 3 * * 1` |\n| Every weekday at noon | `0 12 * * 1-5` |\n| Every 15 minutes | `*/15 * * * *` |\n| First day of every month at midnight | `0 0 1 * *` |\n| Every Sunday at 4:30 PM | `30 16 * * 0` |\n| Every hour on the half hour | `30 * * * *` |\n| Every day at 2am and 2pm | `0 2,14 * * *` |\n| Every 30 minutes between 9am and 5pm on weekdays | `*/30 9-17 * * 1-5` |\n| First Monday of every month at 3am | `0 3 1-7 * 1` |\n| Every quarter hour between 2pm and 6pm | `*/15 14-18 * * *` |\n| Every weekend at 10pm | `0 22 * * 0,6` |\n| Every 5 minutes during business hours | `*/5 9-17 * * 1-5` |\n| 3rd day of every month at 1:30am | `30 1 3 * *` |\n| Every weekday at 9am, 1pm and 5pm | `0 9,13,17 * * 1-5` |\n| At midnight on Mondays and Fridays | `0 0 * * 1,5` |\n| Twice daily at 6:30 and 18:30 | `30 6,18 * * *` |\n| Monthly on the 15th at noon | `0 12 15 * *` |\n| Three times per hour at 15, 30, and 45 minutes | `15,30,45 * * * *` |\n| Last day of month at 11:59 PM | `59 23 L * *` |\n| Weekdays at quarter past each hour | `15 * * * 1-5` |\n| Once per hour in the first 15 minutes | `0-14 * * * *` |\n| Workdays at 8:45 AM except on the 13th | `45 8 1-12,14-31 * 1-5` |\n| First 5 days of each quarter at dawn | `0 6 1-5 1,4,7,10 *` |\n\n## Usage\n\n### As a Command Line Tool\n\nAfter installation, you can use the `cronslate` command:\n\n```bash\n# Basic usage\ncronslate \"Every Monday at 3am\"\n# Output: 0 3 * * 1\n\n# Using quotes is optional for simple phrases\ncronslate Every Monday at 3am\n# Output: 0 3 * * 1\n\n# Pipe input from other commands\necho \"Every 15 minutes\" | cronslate\n# Output: */15 * * * *\n```\n\n### As a Python Library\n\nBasic usage:\n\n```python\nfrom pyslop.cronslator import cronslate\n\n# Simple schedule\nresult = cronslate(\"Every Monday at 3am\")\nprint(result) # Output: 0 3 * * 1\n\n# Multiple times\nresult = cronslate(\"Every day at 2am and 2pm\")\nprint(result) # Output: 0 2,14 * * *\n\n# Complex schedules\nresult = cronslate(\"Every 30 minutes between 9am and 5pm on weekdays\")\nprint(result) # Output: */30 9-17 * * 1-5\n```\n\nError handling:\n\n```python\nfrom pyslop.cronslator import cronslate\n\ntry:\n # This will raise a ValueError\n result = cronslate(\"at 25:00\")\nexcept ValueError as e:\n print(f\"Error: {e}\")\n\n# Invalid inputs will raise ValueError:\ninvalid_inputs = [\n \"\", # Empty string\n \"invalid cron string\", # Nonsense input\n \"at 25:00\", # Invalid hour\n \"on day 32\", # Invalid day\n]\n\nfor input_str in invalid_inputs:\n try:\n cronslate(input_str)\n except ValueError as e:\n print(f\"'{input_str}' is invalid: {e}\")\n```\n\nComplete script example:\n\n```python\n#!/usr/bin/env python3\nfrom pyslop.cronslator import cronslate\n\ndef process_schedules():\n schedules = [\n \"Every Monday at 3am\",\n \"Every weekday at noon\",\n \"Every 15 minutes\",\n \"First day of every month at midnight\",\n \"Every Sunday at 4:30 PM\"\n ]\n \n print(\"Natural Language \u2192 Cron Expression\")\n print(\"\u2500\" * 40)\n \n for schedule in schedules:\n try:\n cron = cronslate(schedule)\n print(f\"{schedule:<30} \u2192 {cron}\")\n except ValueError as e:\n print(f\"{schedule:<30} \u2192 Error: {e}\")\n\nif __name__ == \"__main__\":\n process_schedules()\n\n# Output:\n# Natural Language \u2192 Cron Expression\n# \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n# Every Monday at 3am \u2192 0 3 * * 1\n# Every weekday at noon \u2192 0 12 * * 1-5\n# Every 15 minutes \u2192 */15 * * *\n# First day of every month... \u2192 0 0 1 * *\n# Every Sunday at 4:30 PM \u2192 30 16 * * 0\n```\n\n## Installation\n\nInstall from PyPI using pipx (recommended):\n\n```bash\n# Install pipx if you haven't already\npython -m pip install --user pipx\npython -m pipx ensurepath\n\n# Install from PyPI\npipx install pyslop-cronslator\n\n# Or install from TestPyPI\npipx install --pip-args=\"--index-url https://test.pypi.org/simple/ --no-deps\" pyslop-cronslator\n```\n\nOr install from PyPI using pip:\n\n```bash\npip install pyslop-cronslator\n```\n\nOr install from source:\n\n```bash\ngit clone https://github.com/pyslop/cronslator.git\ncd cronslator\npip install .\n```\n\n## Development\n\nClone and set up development environment:\n\n```bash\n# Clone the repository\ngit clone https://github.com/pyslop/cronslator.git\ncd cronslator\n\n# Install poetry if you haven't already\npip install poetry\n\n# Install dependencies and development dependencies\npoetry install\n\n# Run tests\npoetry run pytest\n\n# Run specific test file\npoetry run pytest tests/test_readme_examples.py\n```\n\n### Publishing to PyPI\n\nFor maintainers, to publish a new version:\n\n```bash\n# Update version in pyproject.toml first, then:\n\n# Build the package\npoetry build\n\n# Configure TestPyPI repository (one-time setup)\npoetry config repositories.testpypi https://test.pypi.org/legacy/\n\n# Publish to TestPyPI first (requires TestPyPI credentials)\npoetry publish -r testpypi\n\n# Test the package from TestPyPI\npip install --index-url https://test.pypi.org/simple/ --no-deps pyslop-cronslator\n\n# If everything looks good, publish to PyPI (requires PyPI credentials)\npoetry publish\n\n# Or do both build and publish in one step\npoetry publish --build\n```\n",
"bugtrack_url": null,
"license": "CC0-1.0",
"summary": "Natural Language to Cron",
"version": "0.2.3",
"project_urls": {
"Homepage": "https://github.com/pyslop/cronslator"
},
"split_keywords": [
"cron",
" natural language",
" schedule",
" translator"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "0be888c134622ac119664ece9404272ed5320d71b8c1623dab913730395cbb5c",
"md5": "0c762fe16a4d0e39aba6a1f4a60d6e74",
"sha256": "d81e07b206f0a5905179c3c6ef8c9e04cbb904a7adb91a669720acba6db16b0a"
},
"downloads": -1,
"filename": "pyslop_cronslator-0.2.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "0c762fe16a4d0e39aba6a1f4a60d6e74",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.9",
"size": 11356,
"upload_time": "2025-01-22T07:18:21",
"upload_time_iso_8601": "2025-01-22T07:18:21.476940Z",
"url": "https://files.pythonhosted.org/packages/0b/e8/88c134622ac119664ece9404272ed5320d71b8c1623dab913730395cbb5c/pyslop_cronslator-0.2.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "d1106aa3a297cd73570bb1651b7eaeeee9f5f7a9be67035efd6ff267ed69ac7f",
"md5": "8bc050e2262b1c784e13ad67ead0417b",
"sha256": "d313b45fdddd5a00b6b3f6ed6fc9e48b11a26b275deec39dd570007651ff8358"
},
"downloads": -1,
"filename": "pyslop_cronslator-0.2.3.tar.gz",
"has_sig": false,
"md5_digest": "8bc050e2262b1c784e13ad67ead0417b",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.9",
"size": 10161,
"upload_time": "2025-01-22T07:18:23",
"upload_time_iso_8601": "2025-01-22T07:18:23.938361Z",
"url": "https://files.pythonhosted.org/packages/d1/10/6aa3a297cd73570bb1651b7eaeeee9f5f7a9be67035efd6ff267ed69ac7f/pyslop_cronslator-0.2.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-01-22 07:18:23",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "pyslop",
"github_project": "cronslator",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "pyslop-cronslator"
}