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