I’m writing a script to sent proxies file from a directory to telegram channel. With the help of some good folks I was able to complete it almost
JavaScript
x
45
45
1
from telegram import Bot, InputMediaDocument
2
3
BOT_TOKEN = "xxx"
4
CHAT_ID = xxx
5
6
7
def main():
8
bot = Bot(BOT_TOKEN)
9
file_paths = (
10
"proxy/proxies/http.txt",
11
"proxy/proxies/socks4.txt",
12
"proxy/proxies/socks5.txt"
13
)
14
path_http = "proxy/proxies/http.txt"
15
with open(path_http,'rb') as file_http:
16
http_count = len(file_http.readlines())
17
file_http.close()
18
19
path_socks4 = 'proxy/proxies/socks4.txt'
20
with open(path_socks4,'rb') as file_socks4:
21
socks4_count = len(file_socks4.readlines())
22
file_socks4.close()
23
24
path_socks5 = 'proxy/proxies/socks5.txt'
25
with open(path_socks5,'rb') as file_socks5:
26
socks5_count = len(file_socks5.readlines())
27
file_socks5.close()
28
29
text = f"Total HTTPs:{http_count}nTotal SOCKS4:{socks4_count}nTotal SOCKS5:{socks5_count}"
30
31
media_group = list()
32
for f in file_paths:
33
with open(f, "rb") as fin:
34
caption = text if f == "proxy/proxies/http.txt" else ''
35
fin.seek(0)
36
media_group.append(InputMediaDocument(fin, caption=caption))
37
38
bot.send_media_group(CHAT_ID, media=media_group)
39
40
41
if __name__ == "__main__":
42
main()
43
44
45
Issues occurred
JavaScript
1
4
1
media_group = list()
2
^
3
IndentationError: unindent does not match any outer indentation level
4
what I’m trying is to send those 3 proxy files with a caption to the first proxy file
Advertisement
Answer
with the help of some good folks I make it work, If there are any easy versions fell free to share
JavaScript
1
43
43
1
from telegram import Bot, InputMediaDocument
2
3
BOT_TOKEN = "xxxxx"
4
CHAT_ID = -1000000
5
6
def http():
7
path_http = 'proxy/proxies/http.txt'
8
with open(path_http, 'rb') as file_http:
9
http_count = len(file_http.readlines())
10
return http_count
11
def socks4():
12
path_socks4 = 'proxy/proxies/socks4.txt'
13
with open(path_socks4, 'rb') as file_socks4:
14
socks4_count = len(file_socks4.readlines())
15
return socks4_count
16
def socks5():
17
path_socks5 = 'proxy/proxies/socks5.txt'
18
with open(path_socks5, 'rb') as file_socks5:
19
socks5_count = len(file_socks5.readlines())
20
return socks5_count
21
http_count = http()
22
socks4_count = socks4()
23
socks5_count = socks5()
24
text = f"Total HTTPs:{http_count}nTotal SOCKS4:{socks4_count}nTotal SOCKS5: {socks5_count}"
25
26
def main():
27
bot = Bot(BOT_TOKEN)
28
file_paths = (
29
"proxy/proxies/http.txt",
30
"proxy/proxies/socks4.txt",
31
"proxy/proxies/socks5.txt"
32
)
33
media_group = list()
34
for f in file_paths:
35
with open(f, "rb") as fin:
36
caption = text if f == "proxy/proxies/socks5.txt" else ''
37
fin.seek(0)
38
media_group.append(InputMediaDocument(fin, caption=caption))
39
bot.send_media_group(CHAT_ID, media=media_group)
40
41
if __name__ == "__main__":
42
main()
43