Advertisement
alisonpaker

Telegram scraper

Feb 28th, 2022
1,644
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.22 KB | None | 0 0
  1. from telethon.sync import TelegramClient
  2. from telethon.tl.functions.messages import GetDialogsRequest
  3. from telethon.tl.types import InputPeerEmpty, InputPeerChannel, InputPeerUser
  4. from telethon.errors.rpcerrorlist import PeerFloodError, UserPrivacyRestrictedError
  5. from telethon.tl.functions.channels import InviteToChannelRequest
  6. import configparser
  7. import os
  8. import sys
  9. import csv
  10. import traceback
  11. import time
  12. import random
  13. re="\033[1;31m"
  14. gr="\033[1;32m"
  15. cy="\033[1;36m"
  16. print (re+"╔╦╗┌─┐┬  ┌─┐╔═╗  ╔═╗┌┬┐┌┬┐┌─┐┬─┐")
  17. print (gr+" ║ ├┤ │  ├┤ ║ ╦  ╠═╣ ││ ││├┤ ├┬┘")
  18. print (re+" ╩ └─┘┴─┘└─┘╚═╝  ╩ ╩─┴┘─┴┘└─┘┴└─")
  19. print (cy+"version : 1.01")
  20. print (cy+"Make sure you Subscribed android 5 star hacks on Youtube")
  21. print (cy+"www.youtube/c/android5star")
  22. print (re+"NOTE :")
  23. print ("1. Telegram only allow to add 200 members in group by one user.")
  24. print ("2. You can Use multiple Telegram accounts for add more members.")
  25. print ("3. Add only 50 members in group each time otherwise you will get flood error.")
  26. print ("4. Then wait for 15-30 miniutes then add members again.")
  27. print ("5. Make sure you enable Add User Permission in your group")
  28. print ("|| NEED MORE TRICKS : join our tg here:: https://t.me/qtel_a ||")
  29. print ("Red-Alison : A GasCom IT expert")
  30. cpass = configparser.RawConfigParser()
  31. cpass.read('config.data')
  32. try:
  33.     api_id = cpass['cred']['id']
  34.     api_hash = cpass['cred']['hash']
  35.     phone = cpass['cred']['phone']
  36.     client = TelegramClient(phone, api_id, api_hash)
  37. except KeyError:
  38.     os.system('clear')
  39.     banner()
  40.     print(re+"[!] run python setup.py first !!\n")
  41.     sys.exit(1)
  42. client.connect()
  43. if not client.is_user_authorized():
  44.     client.send_code_request(phone)
  45.     os.system('clear')
  46.     banner()
  47.     client.sign_in(phone, input(gr+'[+] Enter the code: '+re))
  48. users = []
  49. with open(r"members.csv", encoding='UTF-8') as f:  #Enter your file name
  50.     rows = csv.reader(f,delimiter=",",lineterminator="\n")
  51.     next(rows, None)
  52.     for row in rows:
  53.         user = {}
  54.         user['username'] = row[0]
  55.         user['id'] = int(row[1])
  56.         user['access_hash'] = int(row[2])
  57.         user['name'] = row[3]
  58.         users.append(user)
  59. chats = []
  60. last_date = None
  61. chunk_size = 200
  62. groups = []
  63. result = client(GetDialogsRequest(
  64.     offset_date=last_date,
  65.     offset_id=0,
  66.     offset_peer=InputPeerEmpty(),
  67.     limit=chunk_size,
  68.     hash=0
  69. ))
  70. chats.extend(result.chats)
  71. for chat in chats:
  72.     try:
  73.         if chat.megagroup == True:
  74.             groups.append(chat)
  75.     except:
  76.         continue
  77. print(gr+'Choose a group to add members:'+cy)
  78. i = 0
  79. for group in groups:
  80.     print(str(i) + '- ' + group.title)
  81.     i += 1
  82. g_index = input(gr+"Enter a Number: "+re)
  83. target_group = groups[int(g_index)]
  84. target_group_entity = InputPeerChannel(target_group.id, target_group.access_hash)
  85. mode = int(input(gr+"Enter 1 to add by username or 2 to add by ID: "+cy))
  86. n = 0
  87. for user in users:
  88.     n += 1
  89.     if n % 80 == 0:
  90.         sleep(60)
  91.     try:
  92.         print("Adding {}".format(user['id']))
  93.         if mode == 1:
  94.             if user['username'] == "":
  95.                 continue
  96.             user_to_add = client.get_input_entity(user['username'])
  97.         elif mode == 2:
  98.             user_to_add = InputPeerUser(user['id'], user['access_hash'])
  99.         else:
  100.             sys.exit("Invalid Mode Selected. Please Try Again.")
  101.         client(InviteToChannelRequest(target_group_entity, [user_to_add]))
  102.         print("Waiting for 60-180 Seconds...")
  103.         time.sleep(random.randrange(0, 5))
  104.     except PeerFloodError:
  105.         print("Getting Flood Error from telegram. Script is stopping now. Please try again after some time.")
  106.         print("Waiting {} seconds".format(SLEEP_TIME_2))
  107.         time.sleep(SLEEP_TIME_2)
  108.     except UserPrivacyRestrictedError:
  109.         print("The user's privacy settings do not allow you to do this. Skipping.")
  110.         print("Waiting for 5 Seconds...")
  111.         time.sleep(random.randrange(0, 5))
  112.     except:
  113.         traceback.print_exc()
  114.         print("Unexpected Error")
  115.         continue
  116.         continue
  117.         continue
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement