-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
pars2.py
142 lines (122 loc) · 4.02 KB
/
pars2.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
from telethon.sync import TelegramClient
from telethon.tl.functions.messages import GetDialogsRequest
from telethon.tl.functions.messages import ReadHistoryRequest
from telethon.tl.functions.channels import GetParticipantsRequest
from telethon.tl.functions.channels import GetFullChannelRequest
from telethon.tl.types import ChannelParticipantsRecent
from telethon.tl.types import ChannelParticipantsSearch
from telethon.tl.types import InputPeerEmpty
import os, sys
import configparser
import csv
import time
from tgbot.services.api_sqlite import *
re="\033[1;31m"
gr="\033[1;32m"
cy="\033[1;36m"
def banner():
print(f"""
´´´´¶¶¶¶¶¶´´´´´´¶¶¶¶¶¶
´´¶¶¶¶¶¶¶¶¶¶´´¶¶¶¶¶¶¶¶¶¶
´¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶´´´´¶¶¶¶
¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶´´´´¶¶¶¶
¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶´´¶¶¶¶¶
¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶ ´¶¶¶¶¶´
´´¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶
´´´´´¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶
´´´´´´´¶¶¶¶¶¶¶¶¶¶¶¶¶
´´´´´´´´´¶¶¶¶¶¶¶¶
´´´´´´´´´´´¶¶¶¶
{re}
by rikudo
""")
cpass = configparser.RawConfigParser()
cpass.read('config.data')
try:
api_id = cpass['cred']['id']
api_hash = cpass['cred']['hash']
phone = cpass['cred']['phone']
client = TelegramClient(phone, api_id, api_hash)
except KeyError:
os.system('clear')
banner()
print(re+"[!] run python3 setup.py first !!\n")
sys.exit(1)
client.connect()
if not client.is_user_authorized():
client.send_code_request(phone)
os.system('clear')
banner()
client.sign_in(phone, input(f'{gr}[+] Enter the code: {re}'))
os.system('clear')
banner()
chats = []
last_date = None
chunk_size = 200
groups=[]
result = client(GetDialogsRequest(
offset_date=last_date,
offset_id=0,
offset_peer=InputPeerEmpty(),
limit=chunk_size,
hash = 0
))
chats.extend(result.chats)
for chat in chats:
try:
if chat.megagroup== True:
groups.append(chat)
except Exception:
continue
print(f'{gr}[+] Choose a group to scrape members :{re}')
for i, g in enumerate(groups):
print(f'{gr}[{cy}{str(i)}{gr}]{cy} - {g.title}')
print('')
g_index = input(f"{gr}[+] Enter a Number : {re}")
target_group=groups[int(g_index)]
print(f'{gr}[+] Fetching Members...')
time.sleep(1)
#all_participants = self.client.get_participants(target_Group)
#all_participants = []
#while_condition = True
#my_filter = ChannelParticipantsSearch('')
#offset = 0
#while while_condition:
# participants = self.client(GetParticipantsRequest(channel=target_Group, offset= offset, filter = my_filter, limit=200, hash=0))
# all_participants.extend(participants.users)
# offset += len(participants.users)
# print(len(participants.users))
# if len(participants.users) < 1 :
# while_condition = False
offset = 0
limit = 100
all_participants = []
channel = 'building_work'
while True:
participants = client(GetParticipantsRequest(
channel, ChannelParticipantsRecent(), offset, limit,
hash=0
))
if not participants.users:
break
all_participants.extend(participants.users)
offset += len(participants.users)
print(offset)
print(f'{gr}[+] Saving In file...')
time.sleep(1)
with open("members.csv","w",encoding='UTF-8') as f:
writer = csv.writer(f,delimiter=",",lineterminator="\n")
writer.writerow(['username','user id', 'access hash','name','group', 'group id'])
state = ""
source = 'groups'
for user in all_participants:
username = user.username or ""
first_name = user.first_name or ""
last_name = user.last_name or ""
name = f'{first_name} {last_name}'.strip()
groupname = target_group.title
usah = user.access_hash
usid = user.id
writer.writerow([username,user.id,user.access_hash,name,target_group.title, target_group.id])
add_tgacc_todb(username,usid,usah,name,source,state)
print(f'{gr}[+] Members scraped successfully.')