Skip to content

Instantly share code, notes, and snippets.

@avivl
Last active July 15, 2019 04:02
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Get telgrass reviews
import json
from time import sleep
from telethon import TelegramClient
with open('config.json', 'r') as f:
config = json.load(f)
client = TelegramClient('session_id', api_id=config['api_id'],
api_hash=config['api_hash'])
client.connect()
if not client.is_user_authorized():
client.send_code_request(config['phone'])
client.sign_in(phone, input('Enter the code: '))
dialogs, entities = client.get_dialogs(10)
for entity in entities:
if entity.id == config['chat_id']:
chunk_size = 100
last_id = 374747
while True:
total_messages, messages, senders = \
client.get_message_history(
entity,
limit=chunk_size,
offset_date=None,
offset_id=last_id,
max_id=0,
min_id=0,
add_offset=0)
if not messages:
break
for msg in messages:
try:
clean_line = [line for line in
msg.message.split('\n\n') if
line.strip() != '']
print(clean_line)
except IndexError:
pass
except AttributeError:
pass
last_id = min(msg.id for msg in messages)
sleep(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment