import json def format_output(raw_response): response_object = json.loads(raw_response) title_block = __get_title_block(response_object["title"]) ingredients_block = __get_ingredients_block(response_object["ingredients"]) method_block = __get_method_block(response_object["method"]) return title_block + ingredients_block + method_block def __get_title_block(title): return f"# {title.title()}\n\n" def __get_ingredients_block(ingredients): ingredients_block = "## Ingredients:\n" for ingredient in ingredients: ingredients_block += f"- {ingredient.capitalize()}\n" return f"{ingredients_block}\n\n" def __get_method_block(method): method_block = "## Method:\n" for step in method: sentences = step.split(".") formatted_sentences = [] for sentence in sentences: formatted_sentences.append(sentence.strip().capitalize()) joined_sentences = ". ".join(formatted_sentences) method_block += f"- {joined_sentences}\n" return f"{method_block}\n\n"