File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2828messages = [] # List that will contain all the messages of the target chat
2929offset_id = 0 # ID of the last message of the chunk
3030
31- app .start ()
32-
33- while True :
34- try :
35- m = app .get_history (target , offset_id = offset_id )
36- except FloodWait as e : # For very large chats the method call can raise a FloodWait
37- print ("waiting {}" .format (e .x ))
38- time .sleep (e .x ) # Sleep X seconds before continuing
39- continue
40-
41- if not m .messages :
42- break
43-
44- messages += m .messages
45- offset_id = m .messages [- 1 ].message_id
46-
47- print ("Messages: {}" .format (len (messages )))
48-
49- app .stop ()
31+ with app :
32+ while True :
33+ try :
34+ m = app .get_history (target , offset_id = offset_id )
35+ except FloodWait as e : # For very large chats the method call can raise a FloodWait
36+ print ("waiting {}" .format (e .x ))
37+ time .sleep (e .x ) # Sleep X seconds before continuing
38+ continue
39+
40+ if not m .messages :
41+ break
42+
43+ messages += m .messages
44+ offset_id = m .messages [- 1 ].message_id
45+
46+ print ("Messages: {}" .format (len (messages )))
5047
5148# Now the "messages" list contains all the messages sorted by date in
5249# descending order (from the most recent to the oldest one)
You can’t perform that action at this time.
0 commit comments