Advertisement
Carson1

Untitled

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