Пример #1
0
  def load_recipe( self, recipe_name ):

    recipe_node = None
    for node in self.xml_root.findall("Recipe"):
      if node.attrib["recipe_name"] == recipe_name:
        recipe_node = node
        break;

    if recipe_node == None:
      return ( False, None ) 

    new_recipe = Recipe( recipe_name )
    new_recipe.set_wine_suggestion( recipe_node.find("Wine_suggestion") )
    new_recipe.set_general_info( recipe_node.find("General_info"))
    for ingredient in recipe_node.find("Ingredients").findall("ingredient"):
      ingr_name = ingredient.attrib["name"]
      ingr_quantity = ingredient.attrib["quantity"]
      ingr_full_string = ingredient.attrib["full_string"]
      new_recipe.add_ingredient( Ingredient(ingr_name, ingr_quantity, ingr_full_string ))

    for instruction in recipe_node.find("Instructions").findall("instruction"):
      instruction_step = Instruction_step()
      instruction_step.set_instruction( instruction.attrib["instruction_txt"])
      new_recipe.add_instruction(instruction_step)

    for key in recipe_node.find("Keys_to_success").findall("key"):
      new_recipe.add_key_to_success(Paragraph(key.attrib["key_txt"]))

    return (True, new_recipe)
Пример #2
0
def main():
  xml_cntrl = xml_handler("cook_book_data.xml")

  recipe_name = raw_input("Enter recipe name: ")
  wine_suggestion = raw_input("Enter wine info: ")
  general_info = raw_input("Enter general info: ")
  ingredient_list = []
  instructions = []
  keys = []
  ingredient = raw_input("Enter ingredient name: ")
  while ingredient != "done":
    quantity = raw_input("Enter quantity: ")
    full_string = raw_input("Enter full string: ")
    ingredient_list.append(Ingredient(ingredient, quantity, full_string))
    ingredient = raw_input("Enter ingredient name: ")
  instruction = raw_input("Enter instruction: ")
  while instruction != "done":
    new_instruction = Instruction_step()
    new_instruction.set_instruction(instruction)
    instructions.append(new_instruction)
    instruction = raw_input("Enter instruction: ")
  key = raw_input("Enter key to success: ")
  while key != "done":
    keys.append(Paragraph(key))
    key = raw_input("Enter key to success: ")
  new_recipe = Recipe( recipe_name )
  new_recipe.set_wine_suggestion(wine_suggestion)
  new_recipe.set_general_info(general_info)
  for ingredient in ingredient_list:
    new_recipe.add_ingredient(ingredient)
  for instr in instructions:
    new_recipe.add_instruction(instr)
  for key in keys:
    new_recipe.add_key_to_success(key)


  xml_cntrl.append_recipe(new_recipe)