19
19
from bdfr import exceptions as errors
20
20
from bdfr .configuration import Configuration
21
21
from bdfr .connector import RedditConnector
22
+ from bdfr .progress_bar import Progress
22
23
from bdfr .site_downloaders .download_factory import DownloadFactory
23
24
24
25
logger = logging .getLogger (__name__ )
@@ -43,17 +44,22 @@ def __init__(self, args: Configuration, logging_handlers: Iterable[logging.Handl
43
44
self .master_hash_list = self .scan_existing_files (self .download_directory )
44
45
45
46
def download (self ):
47
+ progress = Progress (self .args .progress_bar , len (self .reddit_lists ))
46
48
for generator in self .reddit_lists :
49
+ progress .subreddit_new (generator )
47
50
try :
48
51
for submission in generator :
49
52
try :
50
- self ._download_submission (submission )
53
+ success = self ._download_submission (submission )
51
54
except prawcore .PrawcoreException as e :
52
55
logger .error (f"Submission { submission .id } failed to download due to a PRAW exception: { e } " )
56
+ success = False
57
+ progress .post_done (submission , success )
53
58
except prawcore .PrawcoreException as e :
54
59
logger .error (f"The submission after { submission .id } failed to download due to a PRAW exception: { e } " )
55
60
logger .debug ("Waiting 60 seconds to continue" )
56
61
sleep (60 )
62
+ progress .subreddit_done ()
57
63
58
64
def _download_submission (self , submission : praw .models .Submission ):
59
65
if submission .id in self .excluded_submission_ids :
@@ -152,6 +158,7 @@ def _download_submission(self, submission: praw.models.Submission):
152
158
self .master_hash_list [resource_hash ] = destination
153
159
logger .debug (f"Hash added to master list: { resource_hash } " )
154
160
logger .info (f"Downloaded submission { submission .id } from { submission .subreddit .display_name } " )
161
+ return True
155
162
156
163
@staticmethod
157
164
def scan_existing_files (directory : Path ) -> dict [str , Path ]:
0 commit comments