Skip to main content

Libary for repeated execution of functions at specific times.

Project description

REPeated Task ORGanizer - reptaskorg

Libary for repeated execution of functions at specific times.

Examples:

  • Every minute, when seconds 5 and 34 are reached:

    task = RepTaskOrg(second=[5, 34])  # 00:00:05, 00:00:34, 00:01:05, ...
    
  • Every day, when hour 2, 8 and 12 and seconds 5 and 34 are reached:

    task = RepTaskOrg(hour=[2, 8, 12], second=[5, 34])  # 02:00:05, 02:00:31, 08:00:05, ...
    
  • Every year, at the first second of may:

    task = RepTaskOrg(month=[5])  # 2021.05.01 00:00:00, 2022.05.01 00:00:00, ...
    

Installation

For installation use Pypi:

pip install reptaskorg or pip3 install reptaskorg

Usage

without threading

If you have no time-consuming tasks in your main loop RapTaskOrg is a good solution.

import datetime
import time
from reptaskorg import RepTaskOrg

def do_something(alarm_number):
    print('{} - ALARM {}'.format(datetime.datetime.now().strftime('%H:%M:%S:%f'), alarm_number))


def main():
    # Define tasks with desired time stamps.
    task_1 = RepTaskOrg(second=[0, 10, 20, 30, 40, 50])
    task_2 = RepTaskOrg(
        minute=[37, 39],
        second=[0, 10, 20, 30, 40, 50]
        )

    # Call Task repeatedly to keep it up to date. 
    while True:
        # Outputs true as soon as the target time is reached
        if task_1.check_task():
            do_something(1)

        if task_2.check_task():
            do_something(2)
        time.sleep(0.001)


if __name__ == "__main__":
    main()

with threading

If you have time-consuming tasks in your main loop use RepTaskOrgTH.

import datetime
import time
from reptaskorg import RepTaskOrgTH


def do_something(alarm_number):
    """Function which should be executed repeatedly."""

    print('{} - ALARM {}'.format(
        datetime.datetime.now().strftime('%H:%M:%S:%f'),
        alarm_number
        ))


def do_anotherthing(alarm_number, alarm_comment):
    """Function which should be executed repeatedly with multiple arguments."""

    print('{} - ALARM {} {}'.format(
        datetime.datetime.now().strftime('%H:%M:%S:%f'),
        alarm_number,
        alarm_comment
        ))


def main():
    """Main-Function."""

    # Define tasks with desired time stamps.
    task_1 = RepTaskOrgTH(do_something, 1, second=[0, 10, 20, 30, 40, 50])

    # Define multiple arguments for given function at task
    task_2 = RepTaskOrgTH(do_anotherthing, 2, 'test_2', minute=[33, 34, 36], second=[0, 10, 20, 30, 40, 50])

    # Main-loop for other tasks
    while True:
        time.sleep(0.001)


if __name__ == "__main__":
    main()

You can stop and restart task-threads by:

# stop task
task.stop_task()

# restart task
task.restart_task()

Information on the set timer are showed by:

print(task.every_year)
print(task.every_month)
print(task.every_day)
print(task.every_hour)
print(task.every_minute)
print(task.every_second)

Arguments

You can define a task with the arguments in teh following chapters.

RepTaskOrg:

Args:
    year (list, optional): valid year. Defaults to None.
    month (list, optional): valid month. Defaults to None.
    day (list, optional): valid day. Defaults to None.
    hour (list, optional): valid hours. Defaults to None.
    minute (list, optional): valid minute. Defaults to None.
    second (list, optional): valid second. Defaults to None.

RepTaskOrgTH:

Args:
    function (function): function to execute.
    function_arguments (tuple): parameters of the given function.
    year (set, optional): valid year. Defaults to None.
    month (set, optional): valid month. Defaults to None.
    day (set, optional): valid day. Defaults to None.
    hour (set, optional): valid hour. Defaults to None.
    minute (set, optional): valid minute. Defaults to None.
    second (set, optional): valid second. Defaults to None.
    reminder (bool, optional): remind if time missed. Defaults to false.

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

reptaskorg-0.1.0.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

reptaskorg-0.1.0-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file reptaskorg-0.1.0.tar.gz.

File metadata

  • Download URL: reptaskorg-0.1.0.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6

File hashes

Hashes for reptaskorg-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ceff2679cc8785b74b9467e31cd43ed3384d25a9f41bd64589b847c573a20cd4
MD5 d4f206cde450d8dc03324fa3039ca90f
BLAKE2b-256 8f5698c3f109e2d6b9c33bd654dfb452cabad37467ccedf1fd693382b5fde3cc

See more details on using hashes here.

File details

Details for the file reptaskorg-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: reptaskorg-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6

File hashes

Hashes for reptaskorg-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d645053a537f3ba61d8a01253561f3bdcce51bc22d77d23fcb07ffdfa793964a
MD5 4f7159dc33ea4821142cf5ec83d355d9
BLAKE2b-256 91e0b76c574f82fbacaf78af135fcb9a2741d9f337253c32b193b912f4b7dc97

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page