forked from erfan4lx/Telegram-Channel-Member-Scraper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherfan4lx.py
150 lines (137 loc) · 4.21 KB
/
erfan4lx.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
from telethon import TelegramClient
from telethon.tl.functions.messages import GetDialogsRequest
from telethon.tl.types import InputPeerEmpty, InputPeerChannel, InputPeerUser
from telethon.errors.rpcerrorlist import (PeerFloodError, UserNotMutualContactError ,
UserPrivacyRestrictedError, UserChannelsTooMuchError,
UserBotError, InputUserDeactivatedError)
from telethon.tl.functions.channels import InviteToChannelRequest
import time, os, sys, json
wt = (
"""
[[ye]]* ) (
[[re]]` ) /( ) ( ) )\ )
[[ye]]( )(_))( /( ( )\ ( ( ((_)( /(
[[re]](_(_()) )(_)) )\ )((_) )\ ' )\ _ )(_))
[[gr]]|_ _|((_)_ _(_/( (_) _((_)) ((_)| |((_)_
[[gr]]| | / _` || ' \))| || ' \()/ _ \| |/ _` |
|_| \__,_||_||_| |_||_|_|_| \___/|_|\__,_|
Unidentified Cyber Security Team [[re]][erfan4lx][[ye]]
Vortex Cyber Security Team [[re]][erfan4lx][[ye]]
M4nifest0 Cyber Security Team [[re]][erfan4lx][[ye]]
github.com/erfan4lx
youtube.com/channel/UCHL7e6sD1eXIBIvjBYnXYEQ
"""
)
print(wt)
time.sleep(3)
COLORS = {
"re": "\u001b[31;1m",
"gr": "\u001b[32m",
"ye": "\u001b[33;1m",
}
re = "\u001b[31;1m"
gr = "\u001b[32m"
ye = "\u001b[33;1m"
def colorText(text):
for color in COLORS:
text = text.replace("[[" + color + "]]", COLORS[color])
return text
clearType = input('terminal or cmd. (t/c): ').lower()
if clearType == 't':
clear = lambda:os.system('clear')
elif clearType == 'c':
clear = lambda:os.system('cls')
else:
print('Invalid input!!!')
sys.exit()
if sys.version_info[0] < 3:
telet = lambda :os.system('pip install -U telethon')
elif sys.version_info[0] >= 3:
telet = lambda :os.system('pip3 install -U telethon')
telet()
time.sleep(1)
clear()
if os.path.isfile('erfan4lx_log.txt'):
with open('erfan4lx_log.txt', 'r') as r:
data = r.readlines()
api_id = data[0]
api_hash = data[1]
else:
api_id = input('Enter api_id: ')
api_hash = input('Enter api_hash: ')
with open('erfan4lx_log.txt', 'w') as a:
a.write(api_id + '\n' + api_hash)
client = TelegramClient('erfan4lx', api_id, api_hash)
async def main():
chats = []
channel = []
result = await client(GetDialogsRequest(
offset_date=None,
offset_id=0,
offset_peer=InputPeerEmpty(),
limit=2000,
hash=0
))
chats.extend(result.chats)
for a in chats:
try:
if True:
channel.append(a)
except:
continue
a = 0
print(ye+'Choose a channel to scrape: ')
for i in channel:
print(gr+'['+str(a)+']', i.title)
a += 1
op = input(ye+'Enter a number: ')
if op == '':
print(ye+'Ok. skipping...')
time.sleep(1)
sys.exit()
else:
pass
opt = int(op)
print('')
print(ye+'[+] Fetching Members...')
time.sleep(1)
target_group = channel[opt]
all_participants = []
mem_details = []
all_participants = await client.get_participants(target_group)
for user in all_participants:
try:
if user.username:
username = user.username
else:
username = ""
if user.first_name:
firstname = user.first_name
else:
firstname = ""
if user.last_name:
lastname = user.last_name
else:
lastname = ""
new_mem = {
'uid': user.id,
'username': username,
'firstname': firstname,
'lastname': lastname,
'access_hash': user.access_hash
}
mem_details.append(new_mem)
except ValueError:
continue
with open('erfan4lx_members.txt', 'w') as w:
json.dump(mem_details, w)
time.sleep(1)
print(ye+'Please wait.....')
time.sleep(3)
done = input(gr+'[+] Members scraped successfully.')
await client.disconnect()
print(wt)
time.sleep(3)
sys.exit()
with client:
client.loop.run_until_complete(main())