Q2 – Text File to Food The owner of the restaurant has prepared his…

Question Answered step-by-step Q2 – Text File to Food The owner of the restaurant has prepared his… Q2 – Text File to Food The owner of the restaurant has prepared his menu for each month in a text file. Each item in the menu is presented in the following format and separated by a new line: Category: Food Name Food Description Ingredients – a, b, c The restaurant has only three categories of food: Appetizers, Mains and Desserts. The Category will always end with a :. The Food Name will always be on the line immediately after Category and the Food Description will always be on the line immediately after Food Name. All menu item must have a valid Category, Food Name and Food Description. Ingredients is optional. If it is present, it will always be on the line after Food Description with the actual ingredients listed as a comma-separated list after the dash (-). Examples of valid food items in bad_menu.txtAppetizers: Thai Beef Skewers with Jalepeno-Lime Dipping SauceThin strips of beef grilled to perfection with jalapeno-lime dipping sauce Ingredients – beef, jalapeno peppers, lime, soy sauce, rice vinegar  Mains: Pumpkin Ravioli Served with caramelized onions, roasted butternut squash, toasted pine nuts and light maple cream sauce  Examples of invalid food items in bad_menu.txtQuickies: Artisanal Cheese, Fruit, and Cracker Platter  Appetisers: Shrimp Cocktail Fresh shrimp with lemony sauce Task Complete the functions to acquire parameters from command line, parse the text file, extract each valid food name, description, its ingredients list (if present) and its category and process them for the queries needed by the business owner. Implementation details – Invalid food items in the file should be ignored by the program.- The file path of the text file is received by the program as the second command line argument.- If insufficient arguments are received by the program, this exception must be handled by displaying the message Error: Insufficient arguments. and the program ends.- If a file path is given but the file does not exist, the exception must be handled by displaying the message Error: The file or directory cannot be found. and the program ends.- If many command line arguments are received by the program, the second argument will be always be taken as the file name regardless of its contents. 2.1 – Command line arguments Complete the function get_filename() to read the command line arguments using the sys module. get_filename() receives no arguments. The function assumes that the second command line argument (from sys) will always be the file path. If an exception occurs while trying to read the command line arguments, the function should display the error message Error: Insufficient arguments. before terminating the function. The function returns a tuple: – First element – bool, true if successfully receive command line arguments. Otherwise, false (errors).- Second element – str, representing the file path. If the first element is False, the second element is an empty string. If the first element is True, the second element is a string supposedly representing the file path. 2.2 – Read file contents Complete the function read_file(). read_file() receives one argument, a string object representing the file path of the file to be read. The function returns a list: – First element – bool, true if successfully reads the file contents. Otherwise, false.- Second element – list, containing all the contents of the file. If the file contents are not successfully read, the function should display the error message Error: The file or directory cannot be found. and return an empty list as the second element of the tuple. 2.3 – Extract menu details Complete the function extract_contents(). extract_contents() receives two arguments; a list of string objects being all the lines in the menu text file and a tuple of food categories offered by the restaurant. The function then checks each item in the given list and returns a list of tuples with each element in the list representing one food item, and its details, on the menu: – First element – str, Food Name- Second element – str, Food Description- Third element – list of str objects representing the ingredients for the food. If the ingredients is not given, this will be an empty list.- Fourth element – str, Category The function must ignore food items that have Category that are not listed in the type of food served by the restaurant: Appetizers, Mains and Desserts. Example of a menu’s content are given below: Appetizers: Thai Beef Skewers with Jalepeno-Lime Dipping Sauce Thin strips of beef grilled to perfection with jalapeno-lime dipping sauce Ingredients – beef, jalapeno peppers, lime, soy sauce, rice vinegar  Quickies: Artisanal Cheese, Fruit, and Cracker Platter Cheese, fruit and cracker for guests to graze before meals  Mains: Pumpkin Ravioli Served with caramelized onions, roasted butternut squash, toasted pine nuts and light maple cream sauce will return menu_items with these contents:menu_items[0][0] -> “Thai Beef Skewers with Jalepeno-Lime Dipping Sauce” menu_items[0][1] -> “Thin strips of beef grilled to perfection with jalapeno-lime dipping sauce” menu_items[0][2] -> [“beef”, “jalapeno peppers”, “lime”, “soy sauce”, “rice vinegar”] menu_items[0][3] -> “Appetizers” menu_items[1][0] -> “Pumpkin Ravioli” menu_items[1][1] -> “Served with caramelized onions, roasted butternut squash, toasted pine nuts and light maple cream sauce” menu_items[1][2] -> [] menu_items[1][3] -> “Mains” If invalid arguments are given, the function must return an empty list. 2.4: class Food Complete methods for contains() and __str__(). The method contains() receives one argument, a single word or list of words. It then checks if the food name, description or ingredients(if present) contains this argument. If it does, the method returns True. Otherwise, it returns False. The method __str__() returns a formatted string of the name and description of the Food object. Examples of each method usage is given in the docstrings below: Image transcription textdef containsCself, to_check): Ill Checks if the food name, description or ingredients contains contents fromsecond argument to_check, iterable object or a single str object result, bool >>> chicken IFood(“Mains”, “Roast Chicken”, “Tender chicken roasted to perfectio… Show more… Show more food.py class Food:   def __init__(self, cat:str, name:str, desc:str, ls_items:list):       self.category = cat       self.name = name       self.description = desc       self.ingredients = ls_items          def get_name(self):       return self.name      def get_category(self):       return self.category      def get_description(self):       return self.description      def get_ingredients(self):       return self.ingredients   def contains(self, to_check) -> bool:       ”’       Checks if the food description or ingredients contains contents from second argument       to_check, iterable object or a single str object       result, bool       >>> chicken = Food(“Mains”, “Roast Chicken”, “Tender chicken roasted to perfection”, [“chicken”, “honey”])       >>> print(chicken.contains(“chicken”))       True       >>> print(chicken.contains([“bread”, “lamb”]))       False       >>> print(chicken.contains([“bread”, “chicken”]))       True       ”’            def __str__(self)-> bool:       ”’       Converts the object into a formatted string.       Returns:       str, showing the name of the food and its description on a new line       Example:       >>> chicken = Food(“Mains”, “Roast Chicken”, “Tender chicken roasted to perfection”, [“chicken”, “honey”])       >>> print(chicken)       Roast Chicken       Tender chicken roasted to perfection       ”’foof Program.pyfrom food import Foodimport sysdef get_filename()-> tuple:   ”’   Reads the command line arguments from sys to get the file name.   Returns: result, tuple   First element – bool, True for sufficient arguments. Otherwise, False.   Second element – str, file path. Empty string if first element is False.   ”’   def read_file(filename: str) -> list:   ”’   Reads all the lines in the file and stores it in a list.   Parameters: filename, str   Returns: result, list   ”’  def extract_contents(contents:list, food_cat: tuple) -> list:   ”’   Extract menu details from the list of contents retrieved from the file.   Parameters:      contents, list     food_cat, tuple   Returns: menu_items, list of tuples   ”’   # Main programdef main(menu_list=[]):   if __name__ == “__main__”:   args_success, fname = get_filename()      main()  Computer Science Engineering & Technology Python Programming INFO 1113 Share QuestionEmailCopy link Comments (0)