Carson1

Untitled

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