Last active
July 15, 2019 04:02
-
-
Save avivl/884ec584b19f4c079153e2f5891181a6 to your computer and use it in GitHub Desktop.
Get telgrass reviews
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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