Metadata-Version: 2.4
Name: sched2
Version: 0.8.3
Summary: Event scheduler 2
Project-URL: homepage, https://medecau.github.io/sched2/
Author-email: Pedro Rodrigues <me@pdbr.org>
License: MIT License
        
        Copyright (c) 2023 Pedro Rodrigues
        
        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:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        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.
License-File: LICENSE
Requires-Python: <4.0,>=3.8
Description-Content-Type: text/markdown

````python notest
import sched2
sc = sched2.scheduler()

@sc.every(5)
def magic():
    ```python
    print("✨ Magic sparkles every five seconds! ✨")
    ```

sc.run()
````

The `sched2` module extends the general purpose event scheduler `sched` from Python's standard library. `sched2.scheduler` is a subclass of `sched.scheduler` that adds new features such as the `every` and `cron` decorators. It's a practical tool for automating tasks that need to run repeatedly after certain time delays or at specific times.

# Install

`sched2` is available on PyPI.

```bash
pip install sched2
```

# How to use

```python notest
from urllib.request import urlopen
import sched2

# create the scheduler
sc = sched2.scheduler()

# we'll use this to remember the last IP address between runs
last_ip = None


@sc.every(10)  # seconds
def check_ip_address():
    global last_ip  # in case we need to update this

    # get the current IP address
    current_ip = urlopen("https://icanhazip.com/").read().decode("utf-8").strip()

    # if the IP address has changed
    if last_ip != current_ip:
        last_ip = current_ip

        # emit an event to notify the change
        sc.emit("ip_changed", kwargs={"new_ip": current_ip})

@sc.on("ip_changed")  # 'ip_changed' is the event name
def notify_ip_change(new_ip):  # 'new_ip' is the keyword argument passed to the event
    print(f'Your IP address has changed to {new_ip}')

@sc.cron("0 9 * * 1-5")  # every weekday at 9:00
def daily_greeting():
    print(f'Good morning, your current IP address is {last_ip}')

sc.run()
```

# Source Code and Issues

The source code for `sched2` is available on GitHub at [github.com/medecau/sched2](https://github.com/medecau/sched2).

You can help improve sched2 by reporting any issues or suggestions on the issue tracker at [github.com/medecau/sched2/issues](https://github.com/medecau/sched2/issues).
