You can use `TaskTimer` to automatically calculate and execute when a given function will be executed based on a specified duration in seconds.
Project description
TaskTimer
TaskTimer
is a Python class used to schedule and keep track of upcoming actions. You can use TaskTimer
to automatically calculate and execute when a given function will be executed based on a specified duration in seconds.
Usage
To use the TaskTimer class, you need to initialize an instance of the class with an action name, function and the amount of seconds until the function will be executed.
from task_timer_birdhouses import TaskTimer
Initialize a new TaskTimer
def greet(name):
print(f"Hello, {name}!")
task_timer = TaskTimer('greeting', 5, greet, args=["John"])
Print the next action time in a human-friendly format
print(task_timer.human_friendly())
# Output
June 21, 2023, 02:11 AM
Print the next action time as a datetime object
print(str(task_timer))
# Output
2023-06-21 02:11:05.046499
Print all upcoming actions
print(TaskTimer.get_upcoming_actions())
# Output
{'send_email': 'June 21, 2023, 02:11 AM'}
In the example above, 'send_email' is the action we're scheduling, and 3600 is the number of seconds until the action will be executed.
Other use cases
If you just want to add the sleep time in seconds to the current time you can do this:
task_timer = TaskTimer('test', 5)
print(task_timer)
# Output
2023-06-21 13:03:53.582599
print(task_timer.human_friendly())
# Output
June 21, 2023, 02:11 AM
This might be useful if you use a different setup for executing your functions, and you only want to display the time a function will be executed.
Installation
This package can be installed using pip:
pip install task-timer-birdhouses
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file task_timer_birdhouses-1.0.1.tar.gz
.
File metadata
- Download URL: task_timer_birdhouses-1.0.1.tar.gz
- Upload date:
- Size: 3.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.10.1 requests/2.25.1 rfc3986/1.5.0 tqdm/4.65.0 urllib3/1.26.15 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0cd61363b4be189d344e355544733752611b20a595ad1ce17b6ef4771f932026 |
|
MD5 | 2f325112159a9a1d80be71c5da93b43e |
|
BLAKE2b-256 | aece0c6736e19a98f90278f4b7ad643257cbcb5a42c001336960c958c5d736aa |
File details
Details for the file task_timer_birdhouses-1.0.1-py3-none-any.whl
.
File metadata
- Download URL: task_timer_birdhouses-1.0.1-py3-none-any.whl
- Upload date:
- Size: 3.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.10.1 requests/2.25.1 rfc3986/1.5.0 tqdm/4.65.0 urllib3/1.26.15 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9345b9d5ae4a1e18194699228f986b280c4e0a08c32c3cdec01d185d8ee9279d |
|
MD5 | 00d89613c6687be084e69b5eabbb557d |
|
BLAKE2b-256 | 5318b7777128d4e06e294447a7fba845ae3628bcb8990ec3051222758bbb6d1b |