def autograde(url): ingredientsDict = scraper.scrapeIngredients(url) directionsList = scraper.getDirections(url) HelperMethods.identifyIngredients(ingredientsDict) HelperMethods.identifyTools(directionsList) HelperMethods.identifyCookingMethods(directionsList) result = {'url':url, 'ingredients':[]} numOfIngredients = 0 numOfCookMethods = 0 numOfTools = 0 numOfPrimMethods = 0 for ingObject in HelperMethods.ingredientList: #These lists hold names, desciptors, preparation and preparation description #for each ingredient. These will be directly pushed to the dictionary. nameList = [] descriptorList = [] preparationList = [] prepDescList = [] #Push different combinations of ingredient names (ingredient name + descriptor(s)) name = ingObject.m_IngName nameList.append(name) for descriptor in ingObject.m_IngDescriptor: name = descriptor + " " + name #Push all descriptors in descriptor list descriptorList.append(descriptor) nameList.append(name) #Push all preparations in preparation list for preparation in ingObject.m_IngPreparation: preparationList.append(preparation) #Push all preparation descriptors in preparation description list for prepDesc in ingObject.m_IngPrepDescriptor: prepDescList.append(prepDesc) entry = {} entry['name'] = nameList entry['quantity'] = ingObject.m_quantAutoGrade entry['measurement'] = ingObject.m_IngMeasurement entry['descriptor'] = ' '.join(descriptorList) entry['preparation'] = ' '.join(preparationList) entry['prepDescList'] = ' '.join(prepDescList) result['ingredients'].append(entry) numOfIngredients = numOfIngredients + 1 result['primary cooking method'] = '' #Add cooking methods methodsList = [] for methodObj in HelperMethods.cookingMethodsList: if(len(methodObj.m_MethodName)>0): for index in range(0,len(methodObj.m_MethodName)): methodsList.append(methodObj.m_MethodName[index]) numOfCookMethods = numOfCookMethods + 1 retVal = checkMethodType(methodObj.m_MethodName[index]) if retVal == True: result['primary cooking method'] = methodObj.m_MethodName[index] #print methodsList result['cooking methods'] = ' '.join(methodsList) #Add cooking tools toolsList = [] for toolObj in HelperMethods.toolsList: toolsList.append(toolObj.m_ToolName) numOfTools = numOfTools + 1 result['cooking tools'] = ' '.join(toolsList) #result['max'] = {'ingredients':numOfIngredients, 'primary cooking method':numOfPrimMethods, 'cooking tools':numOfTools, 'cooking methods':numOfCookMethods} return result
import ProjectDictionary import HelperMethods import scraper import userInput if __name__ == "__main__": print("\t\t\t\tRECIPE MANAGER: Your personal cooking guide.\n") # print ("Enter the recipe you want to explore: ") # recipeName = raw_input() # recipeURL = "" #recipeURL = input("Enter the recipe you want to explore: ") recipeURL = "http://allrecipes.com/Recipe/Chilly-Day-Chili/Detail.aspx?event8=1&prop24=SR_Thumb&e11=chilli%20chicken&e8=Quick%20Search&event10=1&e7=Recipe&soid=sr_results_p1i1" print("Please wait while I understand the recipe...\n") ingredientsDict = scraper.scrapeIngredients(recipeURL) directionsList = scraper.getDirections(recipeURL) #ProjectDictionary.populateTools() print("Reading ingredients...\n") HelperMethods.identifyIngredients(ingredientsDict) HelperMethods.identifyTools(directionsList) HelperMethods.identifyCookingMethods(directionsList) HelperMethods.identifyIngredientType() HelperMethods.ingredientList HelperMethods.cookingMethodsList ## Take the user input and ask them for the transformation print("Ready!!!\n") ## Harsh Code from here ### for ingredient in HelperMethods.ingredientList:
for transformObj in transformList: if(transformObj.m_IngName != "unknown"): output = "Substitute " + transformObj.m_originalIng + " with " + transformObj.m_IngName + ".\n" print output else: outputUnchanged = outputUnchanged + transformObj.m_originalIng + '\n' print "The following remain unchanged:" print outputUnchanged #the main routine if __name__ == "__main__": print ("\t\t\t\tRECIPE MANAGER: Your personal cooking guide.\n") recipeURL = input("Enter the URL of the recipe you want to explore: ") print("Please wait while I understand the recipe...\n") ingredientsDict = scraper.scrapeIngredients(recipeURL) directionsList = scraper.getDirections(recipeURL) #scraper.populateTools() print("Reading ingredients...\n") #parse ingredients, cooking methods and tools HelperMethods.identifyIngredients(ingredientsDict) HelperMethods.identifyTools(directionsList) HelperMethods.identifyCookingMethods(directionsList) print("Ready!!!\n") scraper.getPrepTimeRating(recipeURL) print "\tIngredients:" for ingredient in HelperMethods.ingredientList: output = '' if(ingredient.m_IngQuantity != ''): output = output + ingredient.m_IngQuantity + ' ' if(ingredient.m_IngMeasurement != ''): output = output + ingredient.m_IngMeasurement + ' '