Telegram Message Copy (TeMeCo)
temeco is a simple Telegram message entities to html translator.
Telegram Bot API makes it cumbersome fro bots to copy a user's message
preserving its entities, since it is currently impossible for a bot to send
entities directly along with a message,
so it needs to translate a message with entities into HTML or Markdown.
This little package solves this problem and provides a convenient way to translate a message with entities to HTML.
TelegramUTF16Text class is also aware of the fact that Telegram calculates
offsets for entities using UTF-16 encoding.
This comes into play when text being copied contains symbols which have different lengths
in UTF-8 and UTF-16 code units, like emojis.
Installation
pip install temeco
Usage:
from temeco.temeco import BasicEntity, TelegramUTF16Text, HtmlFromMsg
text = (
"dolorem ipsum, quia dolor sit, 🔥🚒 amet, consectetur, adipisci velit, sed quia 🙃 non numquam eius modi"
" tempora incidunt, 🙊\nut labore et dolore magnam aliquam quaerat voluptatem."
)
HtmlFromMsg(
msg_txt=TelegramUTF16Text(text),
entities=[
BasicEntity(
type="bold", offset=8, length=5, msg_text=TelegramUTF16Text(text)
),
BasicEntity(
type="code", offset=55, length=8, msg_text=TelegramUTF16Text(text)
),
BasicEntity(
type="text_link",
offset=64,
length=5,
data={"url": "http://google.com/"},
msg_text=TelegramUTF16Text(text),
),
BasicEntity(
type="italic",
offset=153,
length=7,
msg_text=TelegramUTF16Text(text),
),
],
).as_str()
Note:
BasicEntity class supports the following types of entities:
bolditalictext_linkcode(monospace text)pre(preformatted text)
Entities like hashtags and usernames are copied as is, since Telegram recognizes them without extra code.
You may create your own class implementing Entity interface and use it instead of
BasicEntity.
Release files for temeco 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| temeco-0.1.3.tar.gz | 4.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| temeco-0.1.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 9.0 kB
Release files / temeco-0.1.3.tar.gz
| Download URL | temeco-0.1.3.tar.gz |
|---|---|
| Size | 4.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
658914a0f5a98662ec35c06bf026edc5ee36fb341945c1dfd7ac7fc1f41e2c47
|
|
BLAKE2b-256 checksum How to use checksums |
281855a4a85d7f1b95661b204f7f06eb3e0a3816131b8f8ee7014574e7d881f0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.0.10 CPython/3.8.2 Linux/5.4.0-42-generic
|
Release files / temeco-0.1.3-py3-none-any.whl
| Download URL | temeco-0.1.3-py3-none-any.whl |
|---|---|
| Size | 4.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
290e5bbf02a514cf072535836c47b0bd6090bc4afa495f8e424c5ed6baabea52
|
|
BLAKE2b-256 checksum How to use checksums |
947f2a3ec7f258bb2432af7e3401af99b9e01f10dba9ff800b0dbebcab8fdb0c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.0.10 CPython/3.8.2 Linux/5.4.0-42-generic
|