17
17
from bdfr .configuration import Configuration
18
18
from bdfr .connector import RedditConnector
19
19
from bdfr .exceptions import ArchiverError
20
+ from bdfr .progress_bar import Progress
20
21
from bdfr .resource import Resource
21
22
22
23
logger = logging .getLogger (__name__ )
@@ -27,24 +28,28 @@ def __init__(self, args: Configuration):
27
28
super (Archiver , self ).__init__ (args )
28
29
29
30
def download (self ):
30
- for generator in self .reddit_lists :
31
- for submission in generator :
32
- try :
33
- if (submission .author and submission .author .name in self .args .ignore_user ) or (
34
- submission .author is None and "DELETED" in self .args .ignore_user
35
- ):
36
- logger .debug (
37
- f"Submission { submission .id } in { submission .subreddit .display_name } skipped"
38
- f" due to { submission .author .name if submission .author else 'DELETED' } being an ignored user"
39
- )
40
- continue
41
- if submission .id in self .excluded_submission_ids :
42
- logger .debug (f"Object { submission .id } in exclusion list, skipping" )
43
- continue
44
- logger .debug (f"Attempting to archive submission { submission .id } " )
45
- self .write_entry (submission )
46
- except prawcore .PrawcoreException as e :
47
- logger .error (f"Submission { submission .id } failed to be archived due to a PRAW exception: { e } " )
31
+ progress = Progress (self .args .progress_bar )
32
+ with progress .context ():
33
+ for generator in progress .wrap_subreddit_iter (self .reddit_lists ):
34
+ for submission in progress .wrap_post_iter (generator ):
35
+ try :
36
+ if (submission .author and submission .author .name in self .args .ignore_user ) or (
37
+ submission .author is None and "DELETED" in self .args .ignore_user
38
+ ):
39
+ logger .debug (
40
+ f"Submission { submission .id } in { submission .subreddit .display_name } skipped"
41
+ f" due to { submission .author .name if submission .author else 'DELETED' } being an ignored user"
42
+ )
43
+ continue
44
+ if submission .id in self .excluded_submission_ids :
45
+ logger .debug (f"Object { submission .id } in exclusion list, skipping" )
46
+ continue
47
+ logger .debug (f"Attempting to archive submission { submission .id } " )
48
+ self .write_entry (submission )
49
+ progress .post_log (submission , True )
50
+ except prawcore .PrawcoreException as e :
51
+ logger .error (f"Submission { submission .id } failed to be archived due to a PRAW exception: { e } " )
52
+ progress .post_log (submission , False )
48
53
49
54
def get_submissions_from_link (self ) -> list [list [praw .models .Submission ]]:
50
55
supplied_submissions = []
0 commit comments