python-gotosocial-notif/test/main_test.py

48 lines
1 KiB
Python
Raw Normal View History

2024-10-02 07:39:37 +02:00
import asyncio
import os
import re
2024-10-02 07:39:37 +02:00
import telegram
from dotenv import load_dotenv
from markdownify import markdownify
from telegram.helpers import escape_markdown
from models import Notifikasi, Session
2024-10-02 07:39:37 +02:00
load_dotenv()
TELE_BOT = os.getenv("TELE_BOT")
TELE_CHATID = os.getenv("TELE_CHATID")
session = Session()
2024-10-02 07:39:37 +02:00
bot = telegram.Bot(token=f"{TELE_BOT}")
2024-10-02 07:39:37 +02:00
async def test():
cek_data = session.query(Notifikasi).filter(Notifikasi.id > 18).limit(2).all()
for notif in cek_data:
2024-10-02 07:39:37 +02:00
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)
2024-10-02 07:39:37 +02:00
asyncio.run(test())