Advertisement
Guest User

userlistV2.py

a guest
Jan 21st, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.74 KB | None | 0 0
  1. #Requirements to run: Python, xlwt, telethon. to install these dependencies, run
  2. # pip install xlwt
  3. # pip install telethon
  4. import xlwt
  5. from telethon import TelegramClient, sync
  6.  
  7. #api_id and api_hash from https://my.telegram.org/apps, create a program to use.
  8. # If the code is not modified to have one built in, it will instead prompt the user at runtime.
  9. api_id = 'YOUR_TOKEN_ID_HERE'
  10. if (api_id is 'YOUR_TOKEN_ID_HERE'):
  11.     print("you did not set an api_id in the script.")
  12.     api_id = input('Please input api_id: ')
  13.  
  14. api_hash = 'YOUR_HASH_ID_HERE'
  15. if(api_hash is 'YOUR_HASH_ID_HERE'):
  16.     print("you did not set an api_hash in the script.")
  17.     api_hash = input('Please input api_hash: ')
  18.  
  19. #Authentication Token is saved to reuse in the future for less API prompts
  20. #saved in whatever directory the command prompt is running from
  21. client = TelegramClient('authenticationToken', api_id, api_hash).start()
  22.  
  23. #sets the program to connect to the chat channel listed.
  24. #for example, 't.me/joinchat/ChatInviteCode' or 't.me/ChatName'
  25. # If the code is not modified to have one built in, it will instead prompt the user at runtime.
  26. url = 'URL_TO_JOIN_HERE'
  27. if (url is 'URL_TO_JOIN_HERE'):
  28.     print('you did not set a url in the script.')
  29.     url = input("Please input a valid url: ")
  30. channel = client.get_entity(url)
  31.  
  32. # get all the users and saves them to xls file
  33. book = xlwt.Workbook()
  34. sheet = book.add_sheet('Sheet 1')
  35. i = 0
  36.  
  37. #writes their id, firstname, lastname, and username to spreadsheet
  38. for u in client.get_participants(channel):
  39.     sheet.write(i, 0, u.id)
  40.     sheet.write(i, 1, u.first_name)
  41.     sheet.write(i, 2, u.last_name)
  42.     sheet.write(i, 3, u.username)
  43.     i += 1
  44.  
  45. print('saving to spreadsheet...')
  46. book.save('userlist.xls')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement