47 lines
1 KiB
Python
47 lines
1 KiB
Python
import asyncio
|
|
import os
|
|
import re
|
|
|
|
import telegram
|
|
from dotenv import load_dotenv
|
|
from markdownify import markdownify
|
|
from telegram.helpers import escape_markdown
|
|
|
|
from models import Notifikasi, Session
|
|
|
|
load_dotenv()
|
|
TELE_BOT = os.getenv("TELE_BOT")
|
|
TELE_CHATID = os.getenv("TELE_CHATID")
|
|
|
|
session = Session()
|
|
|
|
bot = telegram.Bot(token=f"{TELE_BOT}")
|
|
|
|
|
|
async def test():
|
|
cek_data = session.query(Notifikasi).filter(Notifikasi.id > 18).limit(2).all()
|
|
|
|
for notif in cek_data:
|
|
|
|
def buang_href(x):
|
|
return re.sub(r'<a\s+(?:[^>]*?\s+)?href="([^"]*)">(.*?)</a>', r"\2", x)
|
|
|
|
y = buang_href(str(notif.status))
|
|
n = markdownify(y)
|
|
t = escape_markdown(n, version=2)
|
|
|
|
# print(t)
|
|
|
|
try:
|
|
await bot.send_message(
|
|
parse_mode="MarkdownV2",
|
|
chat_id=str(TELE_CHATID),
|
|
text=f"""
|
|
{t}
|
|
""",
|
|
)
|
|
except Exception as e:
|
|
print("Mentions: Ada masalah saat kirim ke Telebot", e)
|
|
|
|
|
|
asyncio.run(test())
|