def print_subreddits(parser, reddit, search_for): """ Print valid and invalid Subreddits. Calls previously defined private method: PrintSubs._find_subs() 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 """ check_subs_spinner = Halo(color="white", text="Validating Subreddit(s).") print() check_subs_spinner.start() subs, not_subs = PrintSubs._find_subs(parser, reddit, search_for) check_subs_spinner.succeed("Finished Subreddit validation.") if subs: print(Fore.GREEN + Style.BRIGHT + "\nThe following Subreddits were found and will be scraped:") print(Fore.GREEN + Style.BRIGHT + "-" * 56) print(*subs, sep="\n") if not_subs: print( Fore.YELLOW + Style.BRIGHT + "\nThe following Subreddits were not found and will be skipped:" ) print(Fore.YELLOW + Style.BRIGHT + "-" * 60) print(*not_subs, sep="\n") logging.warning("Failed to validate the following Subreddits:") logging.warning("%s" % not_subs) logging.warning("Skipping.") logging.info("") if not subs: logging.critical("ALL SUBREDDITS FAILED VALIDATION.") Errors.n_title("Subreddits") logging.critical("NO SUBREDDITS LEFT TO SCRAPE.") logging.critical("ABORTING URS.\n") quit() return subs
def wrapper(*args): try: return function(*args) except ValueError: Errors.n_title(reddit_object) logging.critical("NO %s LEFT TO SCRAPE." % reddit_object.upper()) logging.critical("ABORTING URS.\n") quit()
def validate(object_list, reddit, scraper_type): """ Check if Subreddit(s), Redditor(s), or submission(s) exist and catch PRAW exceptions. Log invalid Reddit objects to `urs.log` if applicable. Calls previously defined public method: Validation.check_existence() Parameters ---------- object_list: list List of Reddit objects to check reddit: Reddit object Reddit instance created by PRAW API credentials scraper_type: str String denoting the scraper type Returns ------- invalid: list List of invalid Reddit objects valid: list List of valid Reddit objects """ object_type = "submission" \ if scraper_type == "comments" \ else scraper_type.capitalize() check_status = Status( "Finished %s validation." % object_type, "Validating %s(s)" % object_type, "white" ) check_status.start() logging.info("Validating %s(s)..." % object_type) logging.info("") invalid, valid = Validation.check_existence(object_list, reddit, scraper_type) check_status.succeed() print() if invalid: warning_message = "The following %ss were not found and will be skipped:" % object_type print(Fore.YELLOW + Style.BRIGHT + warning_message) print(Fore.YELLOW + Style.BRIGHT + "-" * len(warning_message)) print(*invalid, sep = "\n") logging.warning("Failed to validate the following %ss:" % object_type) logging.warning("%s" % (invalid)) logging.warning("Skipping.") logging.info("") if not valid: logging.critical("ALL %sS FAILED VALIDATION." % object_type.upper()) Errors.n_title(object_type + "s") logging.critical("NO %sS LEFT TO SCRAPE." % object_type.upper()) logging.critical("ABORTING URS.\n") quit() return invalid, valid