def _mark_post_as_comment_left(self, post: Post): try: with self.uowm.start() as uow: post.left_comment = True uow.posts.update(post) uow.commit() except Exception as e: log.exception('Failed to mark post %s as checked', post.id, exc_info=True)
def _add_comment(self, post: Post, search_results: SearchResults) -> NoReturn: """ Add a comment to the post :rtype: NoReturn :param post: Post to comment on :param search_results: Results :return: NoReturn """ if self._is_banned_sub(post.subreddit): log.info('Skipping banned sub %s', post.subreddit) with self.uowm.start() as uow: post.left_comment = True uow.posts.update(post) uow.commit() return if self._left_comment(post.post_id): log.info('Already left comment on %s', post.post_id) return with self.uowm.start() as uow: monitored_sub = uow.monitored_sub.get_by_sub(post.subreddit) if monitored_sub: log.info('Skipping monitored sub %s', post.subreddit) return msg = self.response_builder.build_default_comment(search_results) try: self.response_handler.reply_to_submission(post.post_id, msg) except APIException: log.error('Failed to leave comment on %s in %s. ', post.post_id, post.subreddit) except Exception: pass with self.uowm.start() as uow: post.left_comment = True uow.posts.update(post) uow.commit()