Skip to main content

отправка уведомлений в телеграм без зависимостей

Project description

tg_notifier

pip install git+https://imbecility:github_pat_***@github.com/imbecility/tg_notifier

pip install git+https://github.com/imbecility/tg_notifier

uv pip install git+https://github.com/imbecility/tg_notifier

uv add git+https://github.com/imbecility/tg_notifier
from pathlib import Path
from tg_notifier import send_message_to_telegram

bot_token = '7036427666:R38OyUtA1ze20vXu8JcxmD_bfSQiIBhi0R1'
chat_id = '656000000'

msg = 'Господи, Иисусе Христе, Сыне Божий, помилуй мя, грешнаго'

tests = [
    (f'> _{msg}_', 'MarkdownV2'),
    (f'`{msg}`', 'Markdown'),
    (f'<blockquote><i>{msg}</i></blockquote>', 'HTML'),
    (msg, None)
]

# отправка только текста
for message, mode in tests:
    result = send_message_to_telegram(bot_token, chat_id, message, parse_mode=mode)
    # print(result)
    print(f"Text ({mode}): {'OK' if result.get('ok') else 'FAIL'}")


# ----------------------------------------------------------------

# отправка с изображением

def whatever_image():
    """
    просто выдаст путь до первой попавшейся картинки
    чтобы для теста не указывать вручную.
    """
    from os import scandir
    from collections import deque
    queue = deque([Path.home().resolve()])
    while queue:
        folder = queue.popleft()
        try:
            with scandir(folder) as entries:
                for entry in entries:
                    if entry.is_file() and entry.name.lower().endswith(('.jpg', '.jpeg', '.png')):
                        return Path(entry.path)
                    elif entry.is_dir():
                        queue.append(Path(entry.path))
        except:
            pass
    return None


image_path = whatever_image()

for message, mode in tests:
    result = send_message_to_telegram(bot_token, chat_id, message, parse_mode=mode, photo_path=image_path)
    # print(result)
    print(f"Image ({mode}): {'OK' if result.get('ok') else 'FAIL'}")

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

tg_notifier-0.1.0.tar.gz (3.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tg_notifier-0.1.0-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tg_notifier-0.1.0.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.12

File hashes

Hashes for tg_notifier-0.1.0.tar.gz
Algorithm Hash digest
SHA256 de6af953a7de905d17cbde0f3f8b17197cbf92e59bb7414c48900105e7d9fd3c
MD5 392708cfec7b82088aad5746eecb7d7e
BLAKE2b-256 8733b24bccd35490d99f4963084acdf88b2640afb7f6359a865b2a4c77b7cb5a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tg_notifier-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3c228a73fd9038c925ef5e833743786488df92edc37337c28c47dfe92ff8578e
MD5 849d88b52410a9788e75f46a20ecdd10
BLAKE2b-256 e2479255d253d7ed7077bee89af963a1ca90bfd127f3972e36d35835efa21903

See more details on using hashes here.

Supported by

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