telepy-notify


Nametelepy-notify JSON
Version 0.2.1 PyPI version JSON
download
home_pagehttps://github.com/jeff-hykin/telepy_notify
SummarySend telegram notifications
upload_time2023-09-05 17:33:52
maintainer
docs_urlNone
authorJeff Hykin
requires_python>=3.6
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # What is this?

Super fast (<5min setup) telegram notifications for task-completion, task progress, errors and more. This is a minimal module (one file, no pip dependencies).

# How do I use this?

1. `pip install telepy_notify`

2. Take 30sec to get a token:
  - open up a chat with https://t.me/botfather
  - send `/newbot` to ^
  - copy the token out of the response message

3. DM your bot to initialize it (important!)

4. Use it

```python
from telepy_notify import Notifier

# 
# setup
# 
notify = Notifier(
    # read from file
    token_path="some/file/thats/git/ignored/telegram.token",
    # # OR read from ENV var, ex:
    # token_env_var="TELEGRAM_TOKEN",
    # # OR give the token directly, ex:
    # token="alkdsfjakjfoirj029294ijfoi24j4-2",
    
    # optional: a prefix for all messages (good if multiple machines)
    message_prefix="Lambda Machine: Experiment 19:",
    # optional: set to true when debugging to avoid a million notifications
    disable=False,
)
# NOTE:
#    other people can run your code without setting up a bot
#    because telepy will NEVER throw errors 
#    if a notification fails, or if a token is bad
#    it will intentionally only print warnings instead of
#    crashing whatever long-running process you have

# 
# Basic notification
# 
notify.send("Howdy!")
notify.send("Howdy! <b>I'm bold</b>")
notify.send("Howdy! <b>I'm bold</b>\n<code>thing = [1,3,4]</code>")

# 
# get duration and/or error information
# 
with notify.when_done:
    blah_blah_blah = 10
    for blah in range(blah_blah_blah):
        from time import sleep
        sleep(0.1)
    raise Exception(f'''Hello Telegram :)''')
# """
# process took: 1sec, ended at: Sun Aug 20 11:23:38 2023 however it ended with an error: Exception('Hello Telegram :)')
# """

# 
# Progress notifications
# 
#    - gives ETA and other time-info
#    - can limit notify-rate (by time passed or percent-progress)
#        e.g. percent_per_notify=50 => message me after 50% progress
#        e.g. minutes_per_notify=30 => message once every 30min
#    - notify_iter_delay is used to wait a few iterations before sending an ETA
#      (makes the ETA of the first notification more accurate)
for progress, epoch in notify.progress(range(100), percent_per_notify=50, minutes_per_notify=30, notify_iter_delay=1):
    index = progress.index
    
    # do stuff
    import random
    accuracy = random.random()
    if accuracy > 0.99:
        notify.send("Gottem 🎉🎉🎉")
    # end do stuff
    
    progress.message = f"recent accuracy: <code>{accuracy}</code>"

# that^ outputs:
# message1:
#     [=================>.................] 50.00% 
#     |  50/100 
#     | remaining: 0sec 
#     | eta: 11:52:48 
#     | elapsed: 0sec 
#     | recent accuracy: 0.5086382690344122
# message2:
#     Done in 1sec at 11:52:49


```



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/jeff-hykin/telepy_notify",
    "name": "telepy-notify",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "",
    "author": "Jeff Hykin",
    "author_email": "jeff.hykin@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/55/85/238064d33e38eb5534eabafdd431cf13bc7ad435bac4014d790d55dc4a25/telepy_notify-0.2.1.tar.gz",
    "platform": null,
    "description": "# What is this?\n\nSuper fast (<5min setup) telegram notifications for task-completion, task progress, errors and more. This is a minimal module (one file, no pip dependencies).\n\n# How do I use this?\n\n1. `pip install telepy_notify`\n\n2. Take 30sec to get a token:\n  - open up a chat with https://t.me/botfather\n  - send `/newbot` to ^\n  - copy the token out of the response message\n\n3. DM your bot to initialize it (important!)\n\n4. Use it\n\n```python\nfrom telepy_notify import Notifier\n\n# \n# setup\n# \nnotify = Notifier(\n    # read from file\n    token_path=\"some/file/thats/git/ignored/telegram.token\",\n    # # OR read from ENV var, ex:\n    # token_env_var=\"TELEGRAM_TOKEN\",\n    # # OR give the token directly, ex:\n    # token=\"alkdsfjakjfoirj029294ijfoi24j4-2\",\n    \n    # optional: a prefix for all messages (good if multiple machines)\n    message_prefix=\"Lambda Machine: Experiment 19:\",\n    # optional: set to true when debugging to avoid a million notifications\n    disable=False,\n)\n# NOTE:\n#    other people can run your code without setting up a bot\n#    because telepy will NEVER throw errors \n#    if a notification fails, or if a token is bad\n#    it will intentionally only print warnings instead of\n#    crashing whatever long-running process you have\n\n# \n# Basic notification\n# \nnotify.send(\"Howdy!\")\nnotify.send(\"Howdy! <b>I'm bold</b>\")\nnotify.send(\"Howdy! <b>I'm bold</b>\\n<code>thing = [1,3,4]</code>\")\n\n# \n# get duration and/or error information\n# \nwith notify.when_done:\n    blah_blah_blah = 10\n    for blah in range(blah_blah_blah):\n        from time import sleep\n        sleep(0.1)\n    raise Exception(f'''Hello Telegram :)''')\n# \"\"\"\n# process took: 1sec, ended at: Sun Aug 20 11:23:38 2023 however it ended with an error: Exception('Hello Telegram :)')\n# \"\"\"\n\n# \n# Progress notifications\n# \n#    - gives ETA and other time-info\n#    - can limit notify-rate (by time passed or percent-progress)\n#        e.g. percent_per_notify=50 => message me after 50% progress\n#        e.g. minutes_per_notify=30 => message once every 30min\n#    - notify_iter_delay is used to wait a few iterations before sending an ETA\n#      (makes the ETA of the first notification more accurate)\nfor progress, epoch in notify.progress(range(100), percent_per_notify=50, minutes_per_notify=30, notify_iter_delay=1):\n    index = progress.index\n    \n    # do stuff\n    import random\n    accuracy = random.random()\n    if accuracy > 0.99:\n        notify.send(\"Gottem \ud83c\udf89\ud83c\udf89\ud83c\udf89\")\n    # end do stuff\n    \n    progress.message = f\"recent accuracy: <code>{accuracy}</code>\"\n\n# that^ outputs:\n# message1:\n#     [=================>.................] 50.00% \n#     |  50/100 \n#     | remaining: 0sec \n#     | eta: 11:52:48 \n#     | elapsed: 0sec \n#     | recent accuracy: 0.5086382690344122\n# message2:\n#     Done in 1sec at 11:52:49\n\n\n```\n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Send telegram notifications",
    "version": "0.2.1",
    "project_urls": {
        "Homepage": "https://github.com/jeff-hykin/telepy_notify"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8196113a80a3305f564ccb01e5612579f08f93c19f111924736995da189d76e1",
                "md5": "e6d39c90299a324b616a8e042d10c182",
                "sha256": "f620ae868ef1d84ea56c67125767d0b39466e6d004fbfc830ad91f58441d3f5c"
            },
            "downloads": -1,
            "filename": "telepy_notify-0.2.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e6d39c90299a324b616a8e042d10c182",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 238713,
            "upload_time": "2023-09-05T17:33:49",
            "upload_time_iso_8601": "2023-09-05T17:33:49.985611Z",
            "url": "https://files.pythonhosted.org/packages/81/96/113a80a3305f564ccb01e5612579f08f93c19f111924736995da189d76e1/telepy_notify-0.2.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5585238064d33e38eb5534eabafdd431cf13bc7ad435bac4014d790d55dc4a25",
                "md5": "c3e9cbc0660efc0f4f1b3dd4290efb4c",
                "sha256": "6b72dfe81b4281606342746194d89ec7da94cd4d8a41cb69a8bde2999c7f2b87"
            },
            "downloads": -1,
            "filename": "telepy_notify-0.2.1.tar.gz",
            "has_sig": false,
            "md5_digest": "c3e9cbc0660efc0f4f1b3dd4290efb4c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 8543896,
            "upload_time": "2023-09-05T17:33:52",
            "upload_time_iso_8601": "2023-09-05T17:33:52.342608Z",
            "url": "https://files.pythonhosted.org/packages/55/85/238064d33e38eb5534eabafdd431cf13bc7ad435bac4014d790d55dc4a25/telepy_notify-0.2.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-09-05 17:33:52",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "jeff-hykin",
    "github_project": "telepy_notify",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "telepy-notify"
}
        
Elapsed time: 0.89430s