Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
else:
if reverse_flag:
comment = comment.reply(consts.reply_reverse_template.format(message[::-1], message))
else:
comment = comment.reply(consts.reply_template.format(message))
if context.distinguish:
comment.mod.distinguish(sticky=True)
print("Successfully reversed and replied!")
except praw.exceptions.APIException as err:
error = vars(err)
if err.error_type == "RATELIMIT":
errtokens = error['message'].split()
print("Oops! Hit the rate limit! Gotta wait " + errtokens[len(errtokens) - 2] + " " + errtokens[
len(errtokens) - 1])
except prawcore.exceptions.Forbidden:
# Probably banned, message the gif to them
comment.author.message(consts.reply_ban_subject, consts.reply_ban_template.format(url))
print("Successfully reversed and messaged!")
except praw.exceptions.APIException as e:
print(e, dir(e))
raise e
def check_subreddit_name(self, name):
sub = self.r.subreddit(name)
try:
test = sub.fullname
self.name_validation.emit((name, True))
except (prawcore.exceptions.NotFound, prawcore.exceptions.Redirect, AttributeError):
self.name_validation.emit((name, False))
except:
self.logger.error('Unable to validate subreddit name', extra={'subreddit_name': name}, exc_info=True)
)
)
tor_post = config.r.submission(id=clean_id(tor_post_id))
thing_to_reply_to = tor_post.reply(_(base_comment))
for chunk in chunks(result, 9000):
# end goal: if something is over 9000 characters long, we
# should post a top level comment, then keep replying to
# the comments we make until we run out of chunks.
thing_to_reply_to = thing_to_reply_to.reply(_(chunk))
config.redis.delete(new_post)
except (
prawcore.exceptions.RequestException,
prawcore.exceptions.ServerError
) as e:
logging.warning(
'{} - Issue communicating with Reddit. Sleeping for 60s!'
''.format(e)
)
time.sleep(60)
print("Searching...\n")
try:
for submission in subreddit_sort:
# Is an image tagged post which isn't a gif
if (
hasattr(submission, "post_hint") and
submission.post_hint == "image"and
os.path.splitext(submission.url)[1] != ".gif"
):
logger.info(f"{submission} Has Picture ")
logger.debug("Finished Iteration")
return submission
logger.debug(f"submission: {submission} No Picture")
# Exception thrown when subreddit is not found
except prawcore.exceptions.Redirect as e:
logger.exception(f"{e}")
logger.critical("Couldn't access subreddit")
print(
"Error: Invalid Subreddit. Please try again with valid Subreddit."
)
check_bot_exception("Couldn't access subreddit")
# Exception thrown on network/time out failure
except prawcore.RequestException as e:
logger.exception(f"{e}")
logger.critical("Couldn't establish connection")
print(
"Error: Failed to establish a new connection."
" Please check your connection and try again."
)
check_bot_exception("Couldn't establish connection")
def run_function(self, function, arguments):
output = None
result = None
try:
output = function(*arguments)
except praw.exceptions.APIException as err:
for return_type in ReturnType:
if err.error_type == return_type.name:
result = return_type
break
if result is None:
raise
except prawcore.exceptions.Forbidden:
result = ReturnType.FORBIDDEN
except IndexError:
result = ReturnType.QUARANTINED
if result is None:
result = ReturnType.SUCCESS
return output, result
params = {'sr': scan_sub} if scan_sub else None
try:
if _user.name.lower() == username.lower():
redditor = _user
else:
redditor = _reddit.redditor(username)
if scan_saved:
for saved in redditor.saved(limit=None, params=params):
re = RedditElement(saved)
yield re
if scan_upvoted:
for upvoted in redditor.upvoted(limit=None, params=params):
re = RedditElement(upvoted)
yield re
except prawcore.exceptions.NotFound:
stringutil.error('Cannot locate comments or submissions for nonexistent user: %s' % username)
except prawcore.Forbidden:
stringutil.error('Cannot load Upvoted/Saved Posts from the User "%s", because they are private!' % username)