Question: Please draw the UML of this code and explain each line and don't use the AIis python : from abc import ABC, abstractmethod from openfoodfacts

Please draw the UML of this code and explain each line and don't use the AIis python : from abc import ABC, abstractmethod
from openfoodfacts import openfoodfacts
import spoonacular as sp
import requests
class Command(ABC):
def __init__(self, receiver):
self.receiver = receiver
@abstractmethod
def execute(self):
pass
class FoodFactCommand(Command):
def __init__(self, receiver, barcode):
self.barcode = barcode
super().__init__(receiver)
def execute(self):
return self.receiver.foodfacts(self.barcode)
class RecipeCommand(Command):
def __init__(self, receiver, food, ingredient):
self.food = food
self.ingredient = ingredient
super().__init__(receiver)
def execute(self):
return self.receiver.recipe(self.food, self.ingredient)
class FoodFactReceiver:
def foodfacts(self, barcode):
product = openfoodfacts.products.get_product(barcode)
name = product["product"]["product_name"]
calories = product["product"]["nutriments"]["energy-kcal_serving"]
serving_size = product["product"]["serving_quantity"]
result = "Name: "+ name +"
"
result = result + "Calories: "+ str(calories)+"
"
result = result + "Serving size: "+ str(serving_size)+"g
"
return result
class RecipeReceiver:
def recipe(self, food, ingredient):
api = sp.API("6b15facd54b34b15b34b82f71a8ef815")
response = api.search_recipes_complex(query=food,
includeIngredients=ingredient)
response_dict = response.json()
title = response_dict["results"][0]["title"]
image = response_dict["results"][0]["image"]
result = "Name: "+ title +"
"
result = result + "Image: "+ image +"
"
return result
class Invoker:
def __init__(self):
self.commands =[]
def add_command(self, command):
self.commands.append(command)
def execute_commands(self):
report =""
i =1
total = len(self.commands)
for command in self.commands:
command_output = command.execute()
report = report + command_output
# output progress to the user
percentage = round((i / total)*100,2)
formatted_percentage ="{:.2f}".format(percentage)
print(str(i)+" of "+ str(total)+" commands executed ["+\
formatted_percentage +"% complete]")
i = i +1
return report
def load_commands(command_list,invoker):
foodfact_receiver = FoodFactReceiver()
recipe_receiver = RecipeReceiver()
for command in command_list:
split_command = command.split("(")
name = split_command[0]
args =(split_command[1].split(")")[0]).split(",")
if (name == "FoodFact"):
foodfact_command = FoodFactCommand( foodfact_receiver, args[0])
invoker.add_command( foodfact_command )
elif (name == "Recipe"):
recipe_command = RecipeCommand( recipe_receiver, args[0], args[1])
invoker.add_command( recipe_command )
else:
print("Invalid Command Detected")
print("
")
print("Job Report Generator")
print("********************")
input_filename = input("Enter report command input file: ")
output_filename = input("Enter report output file: ")
input_file = open(input_filename)
input_file_list =[]
for line in input_file:
input_file_list.append(line)
input_file.close()
invoker = Invoker()
load_commands(input_file_list,invoker)
report = invoker.execute_commands()
output_file = open(output_filename, "w")
output_file.write(report)
output_file.close()
print("Report written to file!")

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!