def vegetarian_ingredients(url): after = [] cookBook = writeBook() scraped = scrapeRecipe(url) scrapedIng = scraped[0] scrapedSteps = scraped[1] basicIngredients = get_all_names_plus_fixed_rejects(scrapedIng, cookBook)[0] for i in scrapedIng: # allrecipes ings merge = [] qty = str(get_ing_quantity(i)) merge.append(qty) msrmnt = str(get_ing_measurement(i)) if qty > 1.0: msrmnt = pluralize(msrmnt) merge.append(msrmnt) for b in basicIngredients: # the stripped ingredients from webpage if b in i: # if i is the full of the basic ingredient sub = str(cookBook[b].vegetarian) merge.append(sub) transformed_ingredient = ' '.join(merge) print transformed_ingredient after.append(transformed_ingredient) break vegetarian_steps(basicIngredients, scrapedSteps, cookBook) return after
def testAll(url): cookBook = writeBook() healthy = [] vegetarian = [] vegan = [] greek = [] mexican = [] scraped = scrapeRecipe(url) scrapedIng = scraped[0] scrapedSteps = scraped[1] #index into the basic names #print(scrapedIng) #print(cookBook) basicIngredients = get_all_names_plus_fixed_rejects(scrapedIng, cookBook)[0] tools = get_tools_names(scrapedSteps) methods = get_methods_names(scrapedSteps) stepParsed = print_steps(scrapedSteps, basicIngredients) for i in basicIngredients: healthy.append('substituted ' + str(i) + ' for ' + str(cookBook[i].healthy)) vegetarian.append('substituted ' + str(i) + ' for ' + str(cookBook[i].vegetarian)) vegan.append('substituted ' + str(i) + ' for ' + str(cookBook[i].vegan)) greek.append('substituted ' + str(i) + ' for ' + str(cookBook[i].greek)) mexican.append('substituted ' + str(i) + ' for ' + str(cookBook[i].mexican)) for i in basicIngredients: for s in scrapedSteps: healthySteps.append(re.sub(i, cookBook[i].healthy, s)) vegetarianSteps.append(re.sub(i, cookBook[i].vegetarian, s)) veganSteps.append(re.sub(i, cookBook[i].vegan, s)) greekSteps.append(re.sub(i, cookBook[i].greek, s)) mexicanSteps.append(re.sub(i, cookBook[i].mexican, s)) transforms = [list(set(healthy)), list(set(vegetarian)), list(set(vegan)), list(set(greek)), list(set(mexican))] transformNames = ['healthy', 'vegetarian', 'vegan', 'greek', 'mexican'] for counter, l in enumerate(transforms): print("Now showing ingredients for " + transformNames[counter] + " transformation:\n") if l: for ing in l: print(ing + "\n") stepLists = [healthySteps, vegetarianSteps, veganSteps, greekSteps, mexicanSteps] for l in range(0, 5): res = ""; for st in stepLists[l]: res += (st + '\n') print('Here are the steps to follow for a ' + transformNames[l] + ' version of this dish: \n' + res) print(tools) print(methods)
def print_original_ingredients(url): cookBook = writeBook() scraped = scrapeRecipe(url) scrapedIng = scraped[0] print "Original Ingredients:", '\n' print_ingredients(scrapedIng, cookBook)
make_vegetarian(url) elif choice == 'vegan': make_vegan(url) elif choice == 'mexican': make_mexican(url) elif choice == 'greek': make_greek(url) repeater = raw_input('\n\nWould you like to do another one? (y/n)\n') if(repeater == 'y'): transformIt(url) url = raw_input('Hello and welcome to SomeRecipes.com!\nTo start out, please input a recipe url from AllRecipes:\n') while(not re.search('allrecipes.com/recipe/', url)): url = raw_input('Uh-oh, it looks like that\s isn\'t a valid url\nTry again with a url from AllRecipes!\n') answer = raw_input('\nThanks! Now do you want some info about that recipe?\n Otherwise we\'ll jump straight to transformations. (y/n)\n') if answer == 'y': print("Cool! Here's some more info on it:\n") print_original_ingredients(url) scraped = scrapeRecipe(url) cookBook = writeBook() scrapedIng = scraped[0] scrapedSteps = scraped[1] basicIngredients = get_all_names_plus_fixed_rejects(scrapedIng, cookBook)[0] print_steps(scrapedSteps, basicIngredients) print_tools(scrapedSteps) print_methods(scrapedSteps) print('\n\nLet\'s move on to some transformations!\n') transformIt(url) print('Okay then. Thanks for using SomeRecipes, come back soon!')