Skip to content

Commit

Permalink
added progress bar to archiver and cloner
Browse files Browse the repository at this point in the history
  • Loading branch information
stared committed Jan 19, 2024
1 parent 93cf4aa commit 7b113b7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
7 changes: 7 additions & 0 deletions bdfr/archiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from bdfr.configuration import Configuration
from bdfr.connector import RedditConnector
from bdfr.exceptions import ArchiverError
from bdfr.progress_bar import Progress
from bdfr.resource import Resource

logger = logging.getLogger(__name__)
Expand All @@ -29,7 +30,9 @@ def __init__(self, args: Configuration, logging_handlers: Iterable[logging.Handl
super().__init__(args, logging_handlers)

def download(self) -> None:
progress = Progress(self.args.progress_bar, len(self.reddit_lists))
for generator in self.reddit_lists:
progress.subreddit_new(generator)
try:
for submission in generator:
try:
Expand All @@ -40,18 +43,22 @@ def download(self) -> None:
f"Submission {submission.id} in {submission.subreddit.display_name} skipped due to"
f" {submission.author.name if submission.author else 'DELETED'} being an ignored user"
)
progress.post_done(submission, False)
continue
if submission.id in self.excluded_submission_ids:
logger.debug(f"Object {submission.id} in exclusion list, skipping")
progress.post_done(submission, False)
continue
logger.debug(f"Attempting to archive submission {submission.id}")
self.write_entry(submission)
progress.post_done(submission, True)
except prawcore.PrawcoreException as e:
logger.error(f"Submission {submission.id} failed to be archived due to a PRAW exception: {e}")
except prawcore.PrawcoreException as e:
logger.error(f"The submission after {submission.id} failed to download due to a PRAW exception: {e}")
logger.debug("Waiting 60 seconds to continue")
sleep(60)
progress.subreddit_done()

def get_submissions_from_link(self) -> list[list[praw.models.Submission]]:
supplied_submissions = []
Expand Down
8 changes: 7 additions & 1 deletion bdfr/cloner.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from bdfr.archiver import Archiver
from bdfr.configuration import Configuration
from bdfr.downloader import RedditDownloader
from bdfr.progress_bar import Progress

logger = logging.getLogger(__name__)

Expand All @@ -18,15 +19,20 @@ def __init__(self, args: Configuration, logging_handlers: Iterable[logging.Handl
super().__init__(args, logging_handlers)

def download(self) -> None:
progress = Progress(self.args.progress_bar, len(self.reddit_lists))
for generator in self.reddit_lists:
progress.subreddit_new(generator)
try:
for submission in generator:
try:
self._download_submission(submission)
success = self._download_submission(submission)
self.write_entry(submission)
except prawcore.PrawcoreException as e:
logger.error(f"Submission {submission.id} failed to be cloned due to a PRAW exception: {e}")
success = False
progress.post_done(submission, success)
except prawcore.PrawcoreException as e:
logger.error(f"The submission after {submission.id} failed to download due to a PRAW exception: {e}")
logger.debug("Waiting 60 seconds to continue")
sleep(60)
progress.subreddit_done()

0 comments on commit 7b113b7

Please sign in to comment.