Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import telethon
- from telethon import TelegramClient, sync, functions
- from telethon.tl.functions.messages import GetHistoryRequest
- from telethon.tl.functions.channels import JoinChannelRequest
- import gspread
- from oauth2client.service_account import ServiceAccountCredentials
- import socks
- import glob
- import time
- import sys
- import random
- class Channel:
- def __init__(self, channel_name, begining, ending):
- self.channel_name = channel_name
- self.begining = begining
- self.ending = ending
- self.last_message_id = None
- def find_new_post_id(channel, session_name):
- tg_client = TelegramClient(session_name, api_id, api_hash)
- tg_client.start()
- tg_client(JoinChannelRequest(channel.channel_name))
- entity = tg_client.get_entity(channel.channel_name)
- peer = telethon.utils.get_input_peer(entity)
- posts = tg_client(GetHistoryRequest(
- peer=entity,
- limit=1,
- offset_date=None,
- offset_id=0,
- max_id=0,
- min_id=0,
- add_offset=0,
- hash=0))
- tg_client.disconnect()
- if channel.last_message_id != posts.messages[0].id:
- post_id = posts.messages[0].id
- channel.last_message_id = posts.messages[0].id
- return post_id
- scope = ['https://spreadsheets.google.com/feeds', 'https://www.googleapis.com/auth/drive']
- creds = ServiceAccountCredentials.from_json_keyfile_name("CHeatproject-890ddda2e266.json", scope)
- client = gspread.authorize(creds)
- sheet = client.open("cheat").sheet1
- api_id = open('app_id_and_hash.dat').read().splitlines()[0]
- api_hash = open('app_id_and_hash.dat').read().splitlines()[1]
- channels = {}
- for i in range(sheet.row_count):
- if sheet.cell(i + 1, 1).value != '':
- c = Channel(sheet.cell(i + 1, 1).value, sheet.cell(i + 1, 2).value, sheet.cell(i + 1, 3).value)
- find_new_post_id(c, 'sessions/+7 985 073 64 71.session')
- channels[sheet.cell(i + 1, 1).value] = c
- else:
- break
- print("Successfully started", file=sys.stderr)
- while True:
- post_id = None
- for i in glob.glob("sessions/*.session"):
- for channel in channels.values():
- post_id = find_new_post_id(channel, i)
- if post_id != None:
- result = [0]
- time.sleep(30)
- for i in range(random.randint(int(channel.begining), int(channel.ending))):
- tg_client = TelegramClient(glob.glob("sessions/*.session")[i], api_id, api_hash)
- tg_client.start()
- entity = tg_client.get_entity(channel.channel_name)
- peer = telethon.utils.get_input_peer(entity)
- posts = tg_client(GetHistoryRequest(
- peer=entity,
- limit=1,
- offset_date=None,
- offset_id=0,
- max_id=0,
- min_id=0,
- add_offset=0,
- hash=0))
- result = tg_client(functions.messages.GetMessagesViewsRequest(
- peer=peer,
- id=[post_id],
- increment=True))
- tg_client.disconnect()
- time.sleep(3)
Advertisement
Add Comment
Please, Sign In to add comment