Spaces:
Paused
Paused
Download Powers/utils/parser.py from Dragdev/telegrambot: direct link, hf CLI and curl.
- Browser
- Download file 740 Bytes
-
https://huggingface.co/spaces/Dragdev/telegrambot/resolve/7e375079f94c6d451da00a221aacea4783a3e044/Powers/utils/parser.py
- Command line
-
hf download hf://spaces/Dragdev/telegrambot@7e375079f94c6d451da00a221aacea4783a3e044/Powers/utils/parser.py
-
curl -L -o parser.py https://huggingface.co/spaces/Dragdev/telegrambot/resolve/7e375079f94c6d451da00a221aacea4783a3e044/Powers/utils/parser.py
740 Bytes
| from html import escape | |
| from re import compile as compilere | |
| from re import sub | |
| async def cleanhtml(raw_html: str) -> str: | |
| """Clean html data.""" | |
| cleanr = compilere("<.*?>") | |
| return sub(cleanr, "", raw_html) | |
| async def escape_markdown(text: str) -> str: | |
| """Escape markdown data.""" | |
| escape_chars = r"\*_`\[" | |
| return sub(r"([%s])" % escape_chars, r"\\\1", text) | |
| async def mention_html(name: str, user_id: int) -> str: | |
| """Mention user in html format.""" | |
| name = escape(name) | |
| return f'<a href="tg://user?id={user_id}">{name}</a>' | |
| async def mention_markdown(name: str, user_id: int) -> str: | |
| """Mention user in markdown format.""" | |
| return f"[{(await escape_markdown(name))}](tg://user?id={user_id})" | |