{ "info": { "author": "The Megawatt Hour", "author_email": "admin@themwh.com", "bugtrack_url": null, "classifiers": [ "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7" ], "description": "# pycronius\n\nPycronius is a fully-tested, benchmarked utility for efficiently matching datetime objects and cron rules. \n\nFor example, a business might have various sets of opening and closing hours (e.g. weekday and weekend),\nand sets of exceptions to this rule (e.g. holidays). \n\nWith pycronius we could answer questions such as whether or not the business is open right now, \ntomorrow at 9am, Christmas at 4pm, etc.\n\nAnother perfectly reasonable example is the more traditional crontab, although this was not the original motivation.\n\n## Why cron strings?\n\nBecause they are compact, simple, and widely used.\n\n\n## Alright, cool, now show me some code\n\n```python\nfrom pycronius import Scheduler\n\nrules = [(\"open\", \"* 7-19 * * * *\"), (\"closed\", \"* 0-6 * * * *\"), (\"closed\", \"* 20-23 * * * *\")]\nexceptions = [(\"closed\", \"* 0-8 * * 6-7 *\"), (\"closed\", \"* 17-23 * * 6-7 *\"), (\"closed\", \"* * 25 12 * *\"), (\"closed\", \"* * 4 7 * *\")]\n\nscheduler = Scheduler(rules, exceptions, 2010, 2020)\n\nprint scheduler.get_matching_rules(datetime(2014, 12, 19, 12, 0)) # -> [\"open\"]\n```\n\n## CronRange strings\n\nAs those familiar with cron strings are already aware, one drawback of cron strings is that they are really\ninconvenient for representing periods that begin or end on anything other than exactly the hour.\nWith the standard cron string this requires defining multiple strings to handle on contiguous block of time.\nFor example, say our hypothetical business opens at 7:30 and closes at 19:00. We would need the following strings:\n* `(\"closed\", \"* 0-6 * * * *\")`\n* `(\"closed\", \"0-30 7 * * * *\")`\n* `(\"open\", \"30-59 7 * * * *\")`\n* `(\"open\", \"* 8-18 * * * *\")`\n* `(\"closed\", \"* 19-23 * * * *\")`\n\nSince one of the motivating use cases was managing opening hours, pycronius supports strings where \nthe first two fields are the start and stop time in HH:MM format, and the last four are in the traditional style.\nNow the example above can be represented like this:\n* `(\"closed\", \"0:00 7:29 * * * *\")`\n* `(\"open\", \"7:30 19:00 * * * *\")`\n* `(\"closed\", \"19:01 23:59 * * * *\")`\n\nUsing these strings requires no additional configuration, and they can be mixed with traditional strings at will.\n\n\n## Scheduler Documentation\n\n### Initialization\n\nThe `Scheduler` class takes four parameters:\n\n##### `rules`\nA list of tuples that look like (id (a hashable object), cron string) e.g. (1, \"* * * * * *\"), where the fields are either \n\"minute hour day-of-month month day-of-week year\" or \"start-time stop-time day-of-month month day-of-week year\".\n\nFor traditional cron string, each field is separated by a space, and can consist of either:\n* digit (e.g. `\"12\"`)\n* asterisk (wildcard, e.g. `\"*\"`)\n\nAdditionally these can be separated by the following in the standard way:\n* `\"-\"` (range, inclusive on both end-points, e.g. `\"2000-2020\"`)\n* `\"/\"` (interval repetition, e.g. \"*/6\", or `\"1-30/2\"`)\n* `\",\"` (concatenate field defintions, e.g. `\"*/3,*/2\"`)\n\nRules can overlap, which simply means that multiple rules match for a single datetime.\nIt is up to the user to define the appropriate cron rules for their application.\n\n##### `exceptions`\nThe `exceptions` argument has the same type and syntax as the `rules` argument, however the semantics are different.\nThese are meant to be exceptions to the rules defined in `rules`, e.g. the business is closed on Christmas.\nIf such an exception is defined, then even if the business would normally be open, \n`Scheduler.get_matching_rules()` will return closed for any datetime on December 25th.\n\nIf there are multiple exceptions defined for the same time, `Scheduler.get_matching_rules()` will return the first\none it encounters, which is not defined. Unfortunately, the current version of pycronius does not check for overlapping\nexceptions, but since this will almost certainly lead to unpredictable behavior, for now, the user is strongly urged \nnot to define such exceptions.\n\n##### `start_year` and `stop_year`\nThese are YYYY format integers, and are used bound the year field for wildcard and wildcard intervals. \nEvery other field has these boundaries pre-defined (e.g. 24 hours per day), however in general, years have \nno such boundary, so it is best to define this on a per-application basis. \n\n\n### Usage\n\nAfter initializing a Scheduler instance, you can get the matching rules for a datetime object with\n`Scheduler.get_matching_rules(datetime_object)`. This will return a list of ids as defined in `rules` and \n`exceptions`. This is a list because it is possible that more than one rule matches a given datetime object\n\n\n### Other considerations\n\n* `exceptions` that are defined as all minutes/hours of a certain date (e.g. \"* * 4 7 * 2015\") are handled in a\nspecial, optimized way.\n* Even with the HH:MM style strings, there are some rule types which pycronius is still pretty bad at modeling, \n e.g. third friday of every month. Luckily it is not so hard to add subclasses of `rules.BasicCronRule` to\n handle extra use cases.", "description_content_type": "text/markdown", "docs_url": null, "download_url": "https://github.com/themwh/pycronius/archive/v0.0.2.tar.gz", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/themwh/pycronius", "keywords": "python,cron,date,time,match,rule", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "pycronius", "package_url": "https://pypi.org/project/pycronius/", "platform": "", "project_url": "https://pypi.org/project/pycronius/", "project_urls": { "Download": "https://github.com/themwh/pycronius/archive/v0.0.2.tar.gz", "Homepage": "https://github.com/themwh/pycronius" }, "release_url": "https://pypi.org/project/pycronius/0.0.2/", "requires_dist": null, "requires_python": "", "summary": "It is a fully-tested, benchmarked utility for efficiently matching datetime objects and cron rules.", "version": "0.0.2" }, "last_serial": 5095894, "releases": { "0.0.2": [ { "comment_text": "", "digests": { "md5": "157b542a21366a5150f34e702518f1f4", "sha256": "d694bc9b449560ab07fe774c244ba74c4a1313064787665e15c1381b0bffedbf" }, "downloads": -1, "filename": "pycronius-0.0.2.tar.gz", "has_sig": false, "md5_digest": "157b542a21366a5150f34e702518f1f4", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11211, "upload_time": "2019-04-04T09:27:37", "url": "https://files.pythonhosted.org/packages/7a/50/c118afe80d8761c70909a9fd5375ba371a5ac9f5039bab1aafbdb7cdaf68/pycronius-0.0.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "157b542a21366a5150f34e702518f1f4", "sha256": "d694bc9b449560ab07fe774c244ba74c4a1313064787665e15c1381b0bffedbf" }, "downloads": -1, "filename": "pycronius-0.0.2.tar.gz", "has_sig": false, "md5_digest": "157b542a21366a5150f34e702518f1f4", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11211, "upload_time": "2019-04-04T09:27:37", "url": "https://files.pythonhosted.org/packages/7a/50/c118afe80d8761c70909a9fd5375ba371a5ac9f5039bab1aafbdb7cdaf68/pycronius-0.0.2.tar.gz" } ] }