Add soft fail on 5xx Prawcore errors.

This commit is contained in:
OMEGARAZER
2022-12-10 12:36:54 -05:00
parent 1bc20f238e
commit 3aa740e979
2 changed files with 36 additions and 24 deletions

View File

@@ -13,6 +13,7 @@ from abc import ABCMeta, abstractmethod
from datetime import datetime from datetime import datetime
from enum import Enum, auto from enum import Enum, auto
from pathlib import Path from pathlib import Path
from time import sleep
from typing import Callable, Iterator from typing import Callable, Iterator
import appdirs import appdirs
@@ -352,13 +353,14 @@ class RedditConnector(metaclass=ABCMeta):
return [] return []
generators = [] generators = []
for user in self.args.user: for user in self.args.user:
try:
try: try:
self.check_user_existence(user) self.check_user_existence(user)
except errors.BulkDownloaderException as e: except errors.BulkDownloaderException as e:
logger.error(e) logger.error(e)
continue continue
if self.args.submitted: if self.args.submitted:
logger.debug(f"Retrieving submitted posts of user {self.args.user}") logger.debug(f"Retrieving submitted posts of user {user}")
generators.append( generators.append(
self.create_filtered_listing_generator( self.create_filtered_listing_generator(
self.reddit_instance.redditor(user).submissions, self.reddit_instance.redditor(user).submissions,
@@ -368,11 +370,15 @@ class RedditConnector(metaclass=ABCMeta):
logger.warning("Accessing user lists requires authentication") logger.warning("Accessing user lists requires authentication")
else: else:
if self.args.upvoted: if self.args.upvoted:
logger.debug(f"Retrieving upvoted posts of user {self.args.user}") logger.debug(f"Retrieving upvoted posts of user {user}")
generators.append(self.reddit_instance.redditor(user).upvoted(limit=self.args.limit)) generators.append(self.reddit_instance.redditor(user).upvoted(limit=self.args.limit))
if self.args.saved: if self.args.saved:
logger.debug(f"Retrieving saved posts of user {self.args.user}") logger.debug(f"Retrieving saved posts of user {user}")
generators.append(self.reddit_instance.redditor(user).saved(limit=self.args.limit)) generators.append(self.reddit_instance.redditor(user).saved(limit=self.args.limit))
except prawcore.PrawcoreException as e:
logger.error(f"User {user} failed to be retrieved due to a PRAW exception: {e}")
logger.debug("Waiting 60 seconds to continue")
sleep(60)
return generators return generators
else: else:
return [] return []

View File

@@ -8,6 +8,7 @@ import time
from datetime import datetime from datetime import datetime
from multiprocessing import Pool from multiprocessing import Pool
from pathlib import Path from pathlib import Path
from time import sleep
import praw import praw
import praw.exceptions import praw.exceptions
@@ -42,11 +43,16 @@ class RedditDownloader(RedditConnector):
def download(self): def download(self):
for generator in self.reddit_lists: for generator in self.reddit_lists:
try:
for submission in generator: for submission in generator:
try: try:
self._download_submission(submission) self._download_submission(submission)
except prawcore.PrawcoreException as e: except prawcore.PrawcoreException as e:
logger.error(f"Submission {submission.id} failed to download due to a PRAW exception: {e}") logger.error(f"Submission {submission.id} failed to download 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)
def _download_submission(self, submission: praw.models.Submission): def _download_submission(self, submission: praw.models.Submission):
if submission.id in self.excluded_submission_ids: if submission.id in self.excluded_submission_ids: