mirror of
https://github.com/pyrogram/pyrogram
synced 2025-08-29 05:18:10 +00:00
Make use of the "with" context manager
This commit is contained in:
parent
95821f088b
commit
5e8be0e6ef
@ -28,9 +28,8 @@ target = "me" # "me" refers to your own chat (Saved Messages)
|
|||||||
messages = [] # List that will contain all the messages of the target chat
|
messages = [] # List that will contain all the messages of the target chat
|
||||||
offset_id = 0 # ID of the last message of the chunk
|
offset_id = 0 # ID of the last message of the chunk
|
||||||
|
|
||||||
app.start()
|
with app:
|
||||||
|
while True:
|
||||||
while True:
|
|
||||||
try:
|
try:
|
||||||
m = app.get_history(target, offset_id=offset_id)
|
m = app.get_history(target, offset_id=offset_id)
|
||||||
except FloodWait as e: # For very large chats the method call can raise a FloodWait
|
except FloodWait as e: # For very large chats the method call can raise a FloodWait
|
||||||
@ -46,7 +45,5 @@ while True:
|
|||||||
|
|
||||||
print("Messages: {}".format(len(messages)))
|
print("Messages: {}".format(len(messages)))
|
||||||
|
|
||||||
app.stop()
|
|
||||||
|
|
||||||
# Now the "messages" list contains all the messages sorted by date in
|
# Now the "messages" list contains all the messages sorted by date in
|
||||||
# descending order (from the most recent to the oldest one)
|
# descending order (from the most recent to the oldest one)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user