Пример #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.existence(s_t[0], sub_list, parser, reddit,
                                              s_t)

        return subs, not_subs
Пример #2
0
    def list_submissions(parser, post_list, reddit):
        """
        Check if submissions exist and list posts that are not found.

        Calls a method from an external module:

            Validation.existence()

        Parameters
        ----------
        parser: ArgumentParser
            argparse ArgumentParser object
        post_list: list
            List of submission URLs
        reddit: Reddit object
            Reddit instance created by PRAW API credentials

        Returns
        -------
        posts: list
            List of valid submission URLs
        """

        print("\nChecking if submission(s) exist...")
        logging.info("Validating submissions...")
        logging.info("")
        posts, not_posts = Validation.existence(s_t[2], post_list, parser,
                                                reddit, s_t)

        if not_posts:
            print(
                Fore.YELLOW + Style.BRIGHT +
                "\nThe following submissions were not found and will be skipped:"
            )
            print(Fore.YELLOW + Style.BRIGHT + "-" * 55)
            print(*not_posts, sep="\n")

            logging.warning("Failed to validate the following submissions:")
            logging.warning("%s" % (not_posts))
            logging.warning("Skipping.")
            logging.info("")

        if not posts:
            logging.critical("ALL SUBMISSIONS FAILED VALIDATION.")
            raise ValueError

        return not_posts, posts
Пример #3
0
    def list_redditors(parser, reddit, user_list):
        """
        Check if Redditors exist and list Redditors who are not found.

        Calls a public method from an external module:

            Validation.existence()

        Parameters
        ----------
        parser: ArgumentParser
            argparse ArgumentParser object
        reddit: Reddit object
            Reddit instance created by PRAW API credentials
        user_list: list
            List of Redditors

        Returns
        -------
        users: list
            List of valid Redditors URLs
        """

        print("\nChecking if Redditor(s) exist...")
        logging.info("Validating Redditors...")
        logging.info("")
        users, not_users = Validation.existence(s_t[1], user_list, parser,
                                                reddit, s_t)

        if not_users:
            print(
                Fore.YELLOW + Style.BRIGHT +
                "\nThe following Redditors were not found and will be skipped:"
            )
            print(Fore.YELLOW + Style.BRIGHT + "-" * 59)
            print(*not_users, sep="\n")

            logging.warning("Failed to validate the following Redditors:")
            logging.warning("%s" % (not_users))
            logging.warning("Skipping.")
            logging.info("")

        if not users:
            logging.critical("ALL REDDITORS FAILED VALIDATION.")
            raise ValueError

        return not_users, users