-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.py
39 lines (32 loc) · 871 Bytes
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
try:
from secret import *
except:
import os
import time
import telegram
bot_api = os.environ['bot_api']
chat_id = os.environ['chat_id']
bot = telegram.Bot(token=bot_api)
async def sendMsg(text):
i = 0
l = len(text)
while i < l:
time.sleep(5)
txt = text[i:i + 2000]
try:
await bot.send_message(chat_id, txt, parse_mode='HTML', disable_web_page_preview=True)
except Exception as e:
print(str(e))
i += 2000
# Usage example:
post_data = {
'link': 'https://example.com',
'sender': 'Sender Name',
'text': 'This is the main text of the post.',
'extra': 'Additional information (optional)',
'image': []
}
# To call an async function, you need an event loop, like this:
import asyncio
loop = asyncio.get_event_loop()
loop.run_until_complete(sendMsg(post_data['text']))