Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatic Input repeat and appending memebers.csv updated code #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 47 additions & 35 deletions scraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,40 +64,52 @@ def banner():
groups.append(chat)
except:
continue

# To get input from user continuously we use this while loop
while(1):
print(gr+'[+] Choose a group to scrape members :'+re)
i=0
for g in groups:
print(gr+'['+cy+str(i)+']' + ' - ' + g.title)
i+=1

# 'C' key to exit from I/O operation
print(gr+'[+] Press key C to exit')
print('')
g_index = input(gr+"[+] Enter a Number : "+re)
if(g_index=='C' or g_index=='c'):
break
target_group=groups[int(g_index)]

print(gr+'[+] Choose a group to scrape members :'+re)
i=0
for g in groups:
print(gr+'['+cy+str(i)+']' + ' - ' + g.title)
i+=1

print('')
g_index = input(gr+"[+] Enter a Number : "+re)
target_group=groups[int(g_index)]

print(gr+'[+] Fetching Members...')
time.sleep(1)
all_participants = []
all_participants = client.get_participants(target_group, aggressive=True)
print(gr+'[+] Fetching Members...')
time.sleep(1)
all_participants = []
all_participants = client.get_participants(target_group, aggressive=True)

print(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'])
for user in all_participants:
if user.username:
username= user.username
else:
username= ""
if user.first_name:
first_name= user.first_name
else:
first_name= ""
if user.last_name:
last_name= user.last_name
else:
last_name= ""
name= (first_name + ' ' + last_name).strip()
writer.writerow([username,user.id,user.access_hash,name,target_group.title, target_group.id])
print(gr+'[+] Members scraped successfully. Subscribe Termux Professor Youtube Channel For Add Members')
print(gr+'[+] Saving In file...')
time.sleep(1)

if('members.csv' not in os.listdir()):
f=open('members.csv','w')

#Appends data into a single csv file
if('members.csv' in os.listdir()):
with open("members.csv","a",encoding='UTF-8') as f:
writer = csv.writer(f,delimiter=",",lineterminator="\n")
writer.writerow(['username','user id', 'access hash','name','group', 'group id'])
for user in all_participants:
if user.username:
username= user.username
else:
username= ""
if user.first_name:
first_name= user.first_name
else:
first_name= ""
if user.last_name:
last_name= user.last_name
else:
last_name= ""
name= (first_name + ' ' + last_name).strip()
writer.writerow([username,user.id,user.access_hash,name,target_group.title, target_group.id])
print(gr+'[+] Members scraped successfully. Subscribe Termux Professor Youtube Channel For Add Members')