From 8de74a7ba58cabdea51677280d9fec99b26b69ae Mon Sep 17 00:00:00 2001 From: Kusaeni Date: Sun, 29 Sep 2024 21:26:52 +0700 Subject: [PATCH] tambah ket. env di readme dan hapus beberapa kode yang tidak dipakai --- README.md | 7 +++++++ main.py | 19 +++++++------------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index d9dd3d4..33c50cf 100644 --- a/README.md +++ b/README.md @@ -28,3 +28,10 @@ $ pip install -r requirements.txt ``` Awas, silakan edit dulu isi file requirements.txt karena isinya banyak module yang tak terpakai, ane belum sempat hapus 1 per 1. + +### .env +Saat ini ada 4 environment variable yaitu: +1. GTS_API : untuk URL API dari instance gotosocial +2. GTS_TOKEN : Token dengan scope minimal "Read" untuk akses API gotosocial +3. TELE_BOT : Token Bot Telegram, hubungi Bot Father untuk minta +4. TELE_CHATID : Chat Id dari channel telegram. diff --git a/main.py b/main.py index 3f15417..2de642a 100644 --- a/main.py +++ b/main.py @@ -26,7 +26,7 @@ TELE_BOT = os.getenv('TELE_BOT') TELE_CHATID = os.getenv('TELE_CHATID') bot = telegram.Bot(token=f'{TELE_BOT}') -def getNotif(): +async def getNotif(): req = requests.get(f'{gts_api}?limit=5', headers=headers) if req.status_code == 200: @@ -67,16 +67,12 @@ async def kirim_ke_tele(): for notif in cek_data: - body = { - 'text': 'text', - 'chat_id': {str(TELE_CHATID)}, - 'parse_mode': 'markdown', - 'text': f"{notif.post_id} : {notif.handler}" - } - - if str(notif.type) == 'Follow': + if str(notif.type) == 'follow': try: - req = requests.post(f"https://api.telegram.org/bot{TELE_BOT}/sendMessage", headers=headers, data="fuck") + await bot.send_message(parse_mode='html',chat_id=str(TELE_CHATID), text=f""" + {notif.display_name}\n{notif.handler}\n{flag} + """ + ) except: print('Ada masalah saat kirim ke Telebot') else: @@ -103,11 +99,10 @@ async def kirim_ke_tele(): {notif.display_name}\n{notif.handler}\n{flag}\n\n{status_text}\n\n{notif.url} """ ) - except Exception as e: print(f'Ada masalah saat kirim ke Telebot1', e) -# getNotif() +asyncio.run(getNotif()) asyncio.run(kirim_ke_tele())