Advertisement
RiseAboveHate

scrab-active2.py

Dec 23rd, 2020
977
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.42 KB | None | 0 0
  1. from telethon import events
  2. from telethon import TelegramClient, sync
  3. from telethon.sync import TelegramClient
  4. from telethon.tl.functions.messages import GetDialogsRequest
  5. from telethon.tl.types import InputPeerEmpty
  6. from telethon.sync import TelegramClient
  7. from telethon.tl.functions.messages import GetDialogsRequest
  8. from telethon.tl.types import InputPeerEmpty, InputPeerChannel, InputPeerUser
  9. from telethon.errors.rpcerrorlist import PeerFloodError, UserPrivacyRestrictedError
  10. from telethon.tl.functions.channels import InviteToChannelRequest
  11. import sys
  12. import csv
  13. import traceback
  14. import time
  15.  
  16. api_id = 2573921
  17. api_hash = '274951c65ebf767ec4f9c43ef7b3ed99'
  18. phone = '972543362858'
  19. client = TelegramClient(phone, api_id, api_hash)
  20.  
  21. client.connect()
  22. if not client.is_user_authorized():
  23.     client.send_code_request(phone)
  24.     client.sign_in(phone, input('Enter the code: '))
  25.  
  26.  
  27. chats = []
  28. last_date = None
  29. chunk_size = 200
  30. groups=[]
  31.  
  32. result = client(GetDialogsRequest(
  33.              offset_date=last_date,
  34.              offset_id=0,
  35.              offset_peer=InputPeerEmpty(),
  36.              limit=chunk_size,
  37.              hash = 0
  38.          ))
  39. chats.extend(result.chats)
  40.  
  41. for chat in chats:
  42.     try:
  43.         if chat.megagroup== True:
  44.             groups.append(chat)
  45.     except:
  46.         continue
  47.  
  48. print('Choose a group to scrape members from:')
  49. i=0
  50. for g in groups:
  51.     print(str(i) + '- ' + g.title)
  52.     i+=1
  53.  
  54. g_index = input("Enter a Number: ")
  55. target_group=groups[int(g_index)]
  56.  
  57. print('Fetching Members...')
  58. all_participants = []
  59. all_participants = client.get_participants(target_group, aggressive=True)
  60.  
  61. print('Saving In file...')
  62. with open("members.csv","w",encoding='UTF-8') as f:
  63.     writer = csv.writer(f,delimiter=",",lineterminator="\n")
  64.     writer.writerow(['username','user id', 'access hash','name','group', 'group id'])
  65.     for user in all_participants:
  66.         if user.username:
  67.             username= user.username
  68.         else:
  69.             username= ""
  70.         if user.first_name:
  71.             first_name= user.first_name
  72.         else:
  73.             first_name= ""
  74.         if user.last_name:
  75.             last_name= user.last_name
  76.         else:
  77.             last_name= ""
  78.         name= (first_name + ' ' + last_name).strip()
  79.         writer.writerow([username,user.status,user.access_hash,name,target_group.title, target_group.id, user.id])      
  80. print('Members scraped successfully.')
  81.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement