コード例 #1
0
    def _find_subs(parser, reddit, search_for):
        """
        Return a list of valid and invalid Subreddits.

        Calls a method from an external module:

            Validation.existence()

        Parameters
        ----------
        parser: ArgumentParser
            argparse ArgumentParser object
        reddit: Reddit object
            Reddit instance created by PRAW API credentials
        search_for: str
            String denoting Subreddits to scrape for

        Returns
        -------
        subs: list
            List of valid Subreddits
        not_subs: list
            List of invalid Subreddits
        """

        search_for = " ".join(search_for.split())
        sub_list = [subreddit for subreddit in search_for.split(" ")]
        subs, not_subs = Validation.check_existence(sub_list, parser, reddit,
                                                    "subreddit")

        return subs, not_subs
コード例 #2
0
    def test_check_existence_only_valid_redditors(self):
        reddit = Login.create_reddit_object()

        object_list = ["spez"]

        scraper_type = "redditor"

        invalid, valid = Validation.check_existence(object_list, reddit,
                                                    scraper_type)

        assert len(valid) == 1
        assert not invalid
コード例 #3
0
    def test_check_existence_both_valid_and_invalid_redditors(self):
        reddit = Login.create_reddit_object()

        object_list = ["spez", "sdhfgiuoh3284th9enbsprgh8-w-wher9ghwe9hw49"]

        scraper_type = "redditor"

        invalid, valid = Validation.check_existence(object_list, reddit,
                                                    scraper_type)

        assert len(valid) == 1
        assert len(invalid) == 1
コード例 #4
0
    def test_check_existence_only_valid_subreddits(self):
        reddit = Login.create_reddit_object()

        object_list = ["askreddit", "wallstreetbets", "cscareerquestions"]

        scraper_type = "subreddit"

        invalid, valid = Validation.check_existence(object_list, reddit,
                                                    scraper_type)

        assert len(valid) == 3
        assert not invalid
コード例 #5
0
    def test_check_existence_only_invalid_submissions(self):
        reddit = Login.create_reddit_object()

        object_list = [
            "https://www.reddit.com/r/heresaninvalidlinkjasdfhuwhrpguhpasdf/"
        ]

        scraper_type = "comments"

        invalid, valid = Validation.check_existence(object_list, reddit, scraper_type)

        assert not valid
        assert len(invalid) == 1
コード例 #6
0
    def test_check_existence_only_valid_submissions(self):
        reddit = Login.create_reddit_object()

        object_list = [
            "https://www.reddit.com/r/announcements/comments/mcisdf/an_update_on_the_recent_issues_surrounding_a/"
        ]

        scraper_type = "comments"

        invalid, valid = Validation.check_existence(object_list, reddit, scraper_type)

        assert len(valid) == 1
        assert not invalid
コード例 #7
0
    def test_check_existence_only_invalid_subreddits(self):
        reddit = Login.create_reddit_object()

        object_list = [
            "shdg8h342842h3gidbsfgjdbs",
            "asdfhauhwspf8912034812hudfghb979023974ht",
            "xcvhcsxiuvbeidefgh3qw48tr324805tyasdguap;l"
        ]

        scraper_type = "subreddit"

        invalid, valid = Validation.check_existence(object_list, reddit, scraper_type)

        assert not valid
        assert len(invalid) == 3
コード例 #8
0
    def test_check_existence_both_valid_and_invalid_subreddits(self):
        reddit = Login.create_reddit_object()

        object_list = [
            "askreddit", "wallstreetbets", "cscareerquestions",
            "shdg8h342842h3gidbsfgjdbs",
            "asdfhauhwspf8912034812hudfghb979023974ht",
            "xcvhcsxiuvbeidefgh3qw48tr324805tyasdguap;l"
        ]

        scraper_type = "subreddit"

        invalid, valid = Validation.check_existence(object_list, reddit,
                                                    scraper_type)

        assert len(valid) == 3
        assert len(invalid) == 3