-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsms_bot.py
76 lines (64 loc) · 2.36 KB
/
sms_bot.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# import urllib.parse
import time
import aiohttp
try:
from secret import *
except:
import os
import asyncio
from gptit import shorten_text
sms_api = os.environ['sms_api_token']
receivers = os.environ['receiver_phone_number'].split(',')
senderid = os.environ['sender_id']
def process_text(text):
cnt = 0
i = 0
text = '\n'.join([x.strip() for x in text.split('\n') if len(x.strip())>0])
while i < len(text):
if text[i].isdigit():
cnt += 1
elif text[i].isalpha():
cnt = 0
if cnt == 3:
text = text[:i] + '|' + text[i:]
i += 1
cnt = 0
i += 1
return text
async def sendMsg(text, extra, receiver):
if len(text) > 640: text = text[:640] + '...'
# txt = urllib.parse.quote(txt)
try:
msg = process_text(shorten_text(text))
url = 'http://api.smsinbd.com/sms-api/sendsms'
body = {
'api_token': sms_api,
'contact_number': receiver,
'senderid': senderid,
'message': msg
}
async with aiohttp.ClientSession() as session:
async with session.post(url, data=body) as response:
print(await response.text())
except Exception as e:
print(str(e))
async def main(post):
sender = post['sender']
sender = sender[:sender.find('[')]
txt = post['text']
# txt += post['extra']
if len(txt)>0:
for receiver in receivers:
await sendMsg(sender + txt, post['extra'], receiver)
def sendPost(post):
loop = asyncio.get_event_loop()
loop.run_until_complete(main(post))
def testMsg():
loop = asyncio.get_event_loop()
txt = """
যাদের সোসাইটি ফি জমা দেয়া হয়েছে তাদের লিস্ট।আমার কাছে এখনো ১/১ এবং ১/২ এর লিস্টটা আসেনি।তাই ঐটা এখনো আপডেট করিনি।পরিক্ষার আগে সবাই সোসাইটি ফি ৬০০ টাকা করে ৩৪০৫০৫৩৫ এই হিসাব নাম্বারে জমা দিয়ে স্লিপ আমার কাছে জমা দিস।
society fee - Google Drive
"""
loop.run_until_complete(sendMsg(txt, ''))
if __name__ == '__main__':
testMsg()