How to use praw - 10 common examples

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 / unit / models / test_auth.py View on Github external
def script_app():
    return Reddit(
        client_id="dummy client",
        client_secret="dummy secret",
        redirect_uri="https://dummy.tld/",
        user_agent="dummy",
    )
github praw-dev / praw / scripts / init_test_environment.py View on Github external
def make_submissions(r):
    for sub_info in SUBMISSIONS:
        r.login(sub_info['username'], PASSWORD)
        del sub_info['username']
        try:
            r.submit(**sub_info)
            print('Make submission: {0}'.format(sub_info['title']))
        except praw.errors.AlreadySubmitted:
            pass
github praw-dev / praw / tests / integration / models / reddit / test_subreddit.py View on Github external
def test_submit_image__bad_websocket(self, _, __):
        self.reddit.read_only = False
        with self.recorder.use_cassette("TestSubreddit.test_submit_image"):
            subreddit = self.reddit.subreddit(
                pytest.placeholders.test_subreddit
            )
            for file_name in ("test.png", "test.jpg"):
                image = self.image_path(file_name)

                with pytest.raises(ClientException):
                    subreddit.submit_image("Test Title", image)
github praw-dev / praw / old / test_multireddit.py View on Github external
def test_multireddit_representations(self):
        multi = objects.Multireddit(self.r, author='Foo', name='Bar')
        self.assertEqual("Multireddit(author='Foo', name='Bar')", repr(multi))
        self.assertEqual('Bar', str(multi))
github praw-dev / praw / tests / unit / models / reddit / test_subreddit.py View on Github external
def test_equality(self):
        subreddit1 = Subreddit(
            self.reddit, _data={"display_name": "dummy1", "n": 1}
        )
        subreddit2 = Subreddit(
            self.reddit, _data={"display_name": "Dummy1", "n": 2}
        )
        subreddit3 = Subreddit(
            self.reddit, _data={"display_name": "dummy3", "n": 2}
        )
        assert subreddit1 == subreddit1
        assert subreddit2 == subreddit2
        assert subreddit3 == subreddit3
        assert subreddit1 == subreddit2
        assert subreddit2 != subreddit3
        assert subreddit1 != subreddit3
        assert "dummy1" == subreddit1
        assert subreddit2 == "dummy1"
github praw-dev / praw / tests / unit / models / reddit / test_emoji.py View on Github external
def test_hash(self):
        emoji1 = Emoji(
            self.reddit, subreddit=Subreddit(self.reddit, "a"), name="x"
        )
        emoji2 = Emoji(
            self.reddit, subreddit=Subreddit(self.reddit, "a"), name="2"
        )
        emoji3 = Emoji(
            self.reddit, subreddit=Subreddit(self.reddit, "b"), name="1"
        )
        emoji4 = Emoji(
            self.reddit, subreddit=Subreddit(self.reddit, "A"), name="x"
        )
        emoji5 = Emoji(
            self.reddit, subreddit=Subreddit(self.reddit, "a"), name="X"
        )
        emoji6 = Emoji(
            self.reddit, subreddit=Subreddit(self.reddit, "b"), name="x"
        )
        assert hash(emoji1) == hash(emoji1)
        assert hash(emoji2) == hash(emoji2)
        assert hash(emoji3) == hash(emoji3)
        assert hash(emoji1) != hash(emoji2)
        assert hash(emoji1) != hash(emoji3)
        assert hash(emoji1) == hash(emoji4)
        assert hash(emoji1) != hash(emoji5)
        assert hash(emoji1) != hash(emoji6)
github praw-dev / praw / tests / unit / models / reddit / test_subreddit.py View on Github external
def test_hash(self):
        subreddit1 = Subreddit(
            self.reddit, _data={"display_name": "dummy1", "n": 1}
        )
        subreddit2 = Subreddit(
            self.reddit, _data={"display_name": "Dummy1", "n": 2}
        )
        subreddit3 = Subreddit(
            self.reddit, _data={"display_name": "dummy3", "n": 2}
        )
        assert hash(subreddit1) == hash(subreddit1)
        assert hash(subreddit2) == hash(subreddit2)
        assert hash(subreddit3) == hash(subreddit3)
        assert hash(subreddit1) == hash(subreddit2)
        assert hash(subreddit2) != hash(subreddit3)
        assert hash(subreddit1) != hash(subreddit3)
github praw-dev / praw / tests / unit / models / reddit / test_wikipage.py View on Github external
def test_equality(self):
        page1 = WikiPage(
            self.reddit, subreddit=Subreddit(self.reddit, "a"), name="x"
        )
        page2 = WikiPage(
            self.reddit, subreddit=Subreddit(self.reddit, "a"), name="2"
        )
        page3 = WikiPage(
            self.reddit, subreddit=Subreddit(self.reddit, "b"), name="1"
        )
        page4 = WikiPage(
            self.reddit, subreddit=Subreddit(self.reddit, "A"), name="x"
        )
        page5 = WikiPage(
            self.reddit, subreddit=Subreddit(self.reddit, "a"), name="X"
        )
        assert page1 == page1
        assert page2 == page2
        assert page3 == page3
        assert page1 != page2
        assert page1 != page3
        assert page1 == page4
        assert page1 == page5
github praw-dev / praw / tests / unit / models / reddit / test_subreddit.py View on Github external
def test_upload_banner_additional_image(self):
        subreddit = Subreddit(self.reddit, display_name="name")
        with pytest.raises(ValueError):
            subreddit.stylesheet.upload_banner_additional_image(
                "dummy_path", align="asdf"
            )
github praw-dev / praw / tests / unit / models / reddit / test_subreddit.py View on Github external
def test_construct_failure(self):
        message = "Either `display_name` or `_data` must be provided."
        with pytest.raises(TypeError) as excinfo:
            Subreddit(self.reddit)
        assert str(excinfo.value) == message

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