Last active
February 6, 2021 20:08
-
-
Save amiryousefi/4bc0fb7404b9f399ebcd3af3ecdf2948 to your computer and use it in GitHub Desktop.
This file contains 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
offset_id = 0 | |
limit = 100 | |
all_messages = [] | |
total_messages = 0 | |
total_count_limit = 0 | |
while True: | |
print("Current Offset ID is:", offset_id, "; Total Messages:", total_messages) | |
history = client(GetHistoryRequest( | |
peer=my_channel, | |
offset_id=offset_id, | |
offset_date=None, | |
add_offset=0, | |
limit=limit, | |
max_id=0, | |
min_id=0, | |
hash=0 | |
)) | |
if not history.messages: | |
break | |
messages = history.messages | |
for message in messages: | |
all_messages.append(message.to_dict()) | |
offset_id = messages[len(messages) - 1].id | |
total_messages = len(all_messages) | |
if total_count_limit != 0 and total_messages >= total_count_limit: | |
break | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment