예제 #1
0
 def parseRecipesFromJsonFile(self, file):
     """Parses the given json-file, creates Recipe-instances and appends the to Recipebook.recipes"""
     try:
         data = json.load(open(file))
         for dict in data: # Loops through each dictionary in the file
             self.addRecipe(Recipe.recipeFromJson(dict)) #Inits a recipe, and adds it to the recipebook
     except (FileNotFoundError, ValueError, KeyError) as e:
         newFilename = input('File with that name not found or is empty, try another:')
         self.run(newFilename)
예제 #2
0
 def addRecipeFromJson(self, json):
     """creates and adds a recipe from json-object
     the object must be properly formatted with corresponding keys"""
     recipe = Recipe.recipeFromJson(json)
     self.addRecipe(recipe)