def get_all_text(self, post): """ Obtain all the text of a submission, including its comments. If a comment is passed, its parent submission will be determined. :param post: The comment of submission to obtain the thread's text from. :return: A cleaned up version of all the text within the thread, ready for further analysis. """ all_text = '' # Get the parent submission of a comment if isinstance(post, praw.objects.Comment): submission_id = post.link_id[3:] post = self.reddit.get_submission(submission_id=submission_id) submission_text = post.selftext submission_title = post.title ''.join((all_text, submission_title + '\n', submission_text + '\n')) comments = self.get_comments(post) for comment in comments: ''.join((all_text, comment.body + '\n')) clean_content = Analyzer.clean_up(all_text) return clean_content
def check_post(self, post): """Checks a post for qualities of a recipe. :param post: The post to get the comments from. """ if isinstance(post, praw.objects.Submission): content = post.selftext url = post.permalink else: # Comment content = post.body submission_id = post.link_id[3:] parent_post = self.reddit.get_submission( submission_id=submission_id) url = parent_post.permalink + post.id clean_content = Analyzer.clean_up(content) if self.is_recipe(clean_content): print("Got a recipe!! Mama mia! " + str(datetime.now())) all_text = self.get_all_text(post) author = post.author.name karma = post.score date_posted = post.created post_id = post.id title = Analyzer.determine_title(post) ingredients = Analyzer.get_ingredients(content) instructions = Analyzer.get_instructions(content) recipe_type = Analyzer.determine_type(all_text) post_info = PostInfo(author, karma, date_posted, post_id, url) refined_post = RefinedPost(title, ingredients, instructions, recipe_type) recipe = Recipe(post_info, refined_post) self.recipe_handler.add(recipe)