Carson1

Untitled

Nov 26th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.35 KB | None | 0 0
  1. import telethon
  2. from telethon import TelegramClient, sync, functions
  3. from telethon.tl.functions.messages import GetHistoryRequest
  4. from telethon.tl.functions.channels import JoinChannelRequest
  5. import gspread
  6. from oauth2client.service_account import ServiceAccountCredentials
  7. import time
  8. import socks
  9. import glob
  10.  
  11. scope = ['https://spreadsheets.google.com/feeds', 'https://www.googleapis.com/auth/drive']
  12. creds = ServiceAccountCredentials.from_json_keyfile_name("CHeatproject-890ddda2e266.json", scope)
  13. client = gspread.authorize(creds)
  14.  
  15. sheet = client.open("cheat").sheet1
  16.  
  17. array_of_channels = []
  18.  
  19. for i in range(sheet.row_count):
  20.     if sheet.cell(i + 1, 1).value != '':
  21.         array_of_channels.append([sheet.cell(i + 1, 1).value,
  22.                                   sheet.cell(i + 1, 2).value,
  23.                                   sheet.cell(i + 1, 3).value,
  24.                                   0])
  25.     else:
  26.         break
  27.  
  28.  
  29. api_id = open('app_id.dat').read().splitlines()[0]
  30. api_hash = open('app_hash.dat').read().splitlines()[0]
  31.  
  32. post_id = 0
  33. z = 1
  34. while True:
  35.     for k in glob.glob("sessions/*.session"):
  36.         tg_client = TelegramClient(k, api_id, api_hash,
  37.                                    )  # proxy=(socks.SOCKS5, "37.1.218.213", 10051)
  38.         tg_client.start()
  39.         for i in array_of_channels:
  40.             try:
  41.                 tg_client(JoinChannelRequest(i[0]))
  42.                 entity = tg_client.get_entity(i[0])
  43.                 peer = telethon.utils.get_input_peer(entity)
  44.                 posts = tg_client(GetHistoryRequest(
  45.                     peer=entity,
  46.                     limit=1,
  47.                     offset_date=None,
  48.                     offset_id=0,
  49.                     max_id=0,
  50.                     min_id=0,
  51.                     add_offset=0,
  52.                     hash=0))
  53.                 if i[3] != posts.messages[0].id:
  54.                     post_id = posts.messages[0].id
  55.                     i[3] = posts.messages[0].id
  56.                     result = tg_client(functions.messages.GetMessagesViewsRequest(
  57.                         peer=peer,
  58.                         id=[post_id],
  59.                         increment=True))
  60.                     tg_client.disconnect()
  61.                     print(result[0])
  62.                 else:
  63.                     continue
  64.             except:
  65.                 continue
  66.     time.sleep(5)
Advertisement
Add Comment
Please, Sign In to add comment