How to use the praw.models.Submission function in praw

To help you get started, we’ve selected a few praw examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github praw-dev / praw / tests / integration / models / reddit / test_submission.py View on Github external
def test_upvote(self):
        self.reddit.read_only = False
        with self.recorder.use_cassette("TestSubmission.test_upvote"):
            Submission(self.reddit, "4b536p").upvote()
github praw-dev / praw / tests / integration / models / reddit / test_submission.py View on Github external
def test_unlock(self):
        self.reddit.read_only = False
        with self.recorder.use_cassette(
            "TestSubmissionModeration.test_unlock"
        ):
            Submission(self.reddit, "4s2idz").mod.unlock()
github praw-dev / praw / tests / integration / models / test_comment_forest.py View on Github external
def test_replace__skip_below_threshold(self):
        with self.recorder.use_cassette(
            "TestCommentForest.test_replace__skip_below_threshold",
            match_requests_on=["uri", "method", "body"],
        ):
            submission = Submission(self.reddit, "3hahrw")
            before_count = len(submission.comments.list())
            skipped = submission.comments.replace_more(16, 5)
            assert len(skipped) == 13
            assert all(x.count < 5 for x in skipped)
            assert all(x.submission == submission for x in skipped)
            assert before_count < len(submission.comments.list())
github praw-dev / praw / tests / integration / models / reddit / test_submission.py View on Github external
def test_set_original_content(self, _):
        self.reddit.read_only = False
        with self.recorder.use_cassette(
            "TestSubmissionModeration.test_set_original_content"
        ):
            submission = Submission(self.reddit, "dueqm6")
            assert not submission.is_original_content
            submission.mod.set_original_content()
            submission = Submission(self.reddit, "dueqm6")
            assert submission.is_original_content
github praw-dev / praw / tests / unit / models / reddit / test_submission.py View on Github external
def test_construct_from_url(self):
        assert Submission(self.reddit, url="http://my.it/2gmzqe") == "2gmzqe"
github praw-dev / praw / tests / unit / models / reddit / test_submission.py View on Github external
def test_construct_failure(self):
        message = "Exactly one of `id`, `url`, or `_data` must be provided."
        with pytest.raises(TypeError) as excinfo:
            Submission(self.reddit)
        assert str(excinfo.value) == message

        with pytest.raises(TypeError) as excinfo:
            Submission(self.reddit, id="dummy", url="dummy")
        assert str(excinfo.value) == message

        with pytest.raises(TypeError) as excinfo:
            Submission(self.reddit, "dummy", _data={"id": "dummy"})
        assert str(excinfo.value) == message

        with pytest.raises(TypeError) as excinfo:
            Submission(self.reddit, url="dummy", _data={"id": "dummy"})
        assert str(excinfo.value) == message

        with pytest.raises(TypeError) as excinfo:
            Submission(self.reddit, "dummy", "dummy", {"id": "dummy"})
github praw-dev / praw / tests / integration / models / test_comment_forest.py View on Github external
def test_replace__all_with_comment_sort(self):
        with self.recorder.use_cassette(
            "TestCommentForest.test_replace__all_with_comment_sort",
            match_requests_on=["uri", "method", "body"],
        ):
            submission = Submission(self.reddit, "3hahrw")
            submission.comment_sort = "old"
            skipped = submission.comments.replace_more(None, threshold=0)
            assert len(skipped) == 0
            assert len(submission.comments.list()) >= 500
github shevisjohnson / gpt-2_bot / reddit_bot.py View on Github external
return
        if comment.author is None or comment.author.name == self.name:
            return
        if self.filter_id(comment.id):
            return
        if self.rexp.match(clean_input(comment.body)) is None:
            return
        for h in comment.replies:
            if h.author.name == self.name:
                return
        self.log("Found one!")

        try:
            cp = comment.parent()

            if isinstance(cp, praw.models.Submission):
                self.log("Parent was a submission...\n")
                return
            else:
                cp.refresh()
                for h in cp.replies:
                    if h.author is None:
                        continue
                    if h.author.name == self.name:
                        self.log("Already replied to this comment...\n")
                        return
        except Exception as e:
            self.log("An unknown error occured.\n" + str(e))
            return

        cb = ""
        for line in cp.body.splitlines():
github vihanggodbole / Search-for-reddit-saved-posts / reddit_saved_posts.py View on Github external
def main():
    redditor = login()
    print('Welcome /u/{}. We have been expecting you.'.format(redditor))
    saved = redditor.saved(limit=None)

    saved_posts = []
    saved_comments = []
    saved_links = []

    for post in saved:  # separate out posts and comments
        if isinstance(post, praw.models.Submission):
            if 'reddit' in post.url:
                saved_posts.append(post)
            else:
                saved_links.append(post)
        elif isinstance(post, praw.models.Comment):
            saved_comments.append(post)

    saved_posts_title = {}
    saved_comments_body = {}
    saved_links_title = {}

    for post in saved_posts:    # create a list of saved posts' titles
        saved_posts_title[post.id] = post.title

    for comment in saved_comments:  # create a list of saved comment's body
        saved_comments_body[comment.id] = comment.body
github makuto / Liked-Saved-Image-Downloader / redditScraper.py View on Github external
earlyOutPoint = None, unlikeUnsave = False, user_name = None):
    submissions = []
    comments = []

    numTotalSubmissions = len(redditList)
    for currentSubmissionIndex, singleSubmission in enumerate(redditList):
        if currentSubmissionIndex and currentSubmissionIndex % 100 == 0:
            logger.log('Got {} submissions...'.format(currentSubmissionIndex))

        # If they don't want to save their own post, skip it
        submissionAuthor = singleSubmission.author.name if singleSubmission.author else u'no_author'
        if not settings.settings['Reddit_Save_Your_User_Posts'] and submissionAuthor == user_name:
            logger.log('Skipped a current user post due to Reddit_Save_Your_User_Posts == False')
            continue

        if type(singleSubmission) is praw.models.Submission:
            newSubmission = Submission()

            newSubmission.source = u'reddit'

            newSubmission.title = singleSubmission.title
            newSubmission.author = submissionAuthor

            newSubmission.subreddit = singleSubmission.subreddit.url
            newSubmission.subredditTitle = singleSubmission.subreddit.title

            newSubmission.body = singleSubmission.selftext
            newSubmission.bodyUrl = singleSubmission.url

            newSubmission.postUrl = singleSubmission.permalink

            submissions.append(newSubmission)