Exemplo n.º 1
0
def index():
    #when random button is pressed give a random recipe
    if request.args.get("random") == "Go": 
        id= food2fork().getRandomRecipeID()  
        return redirect(url_for('show_recipe', id =id))
    
    
    #search the tesco database
    if (request.args.get("ingredients")) is not None : 
        #naively validates input
        query = (request.args.get("ingredients")).lower()
        query = urllib.quote_plus(query)  #very important,yay!
        tesco = tescoSearch(query).getResults()    
        return render_template('show_ingredients.html', tesco = tesco , query = query)
    
    #search the food2fork database
    if (request.args.get("ingredients_rec")) is not None: 
        query = (request.args.get("ingredients_rec")).lower()
        query = urllib.quote_plus(query)  #very important,yay!
        f2f = food2fork().search(query) 
        #this should be made into a food2fork method
        if f2f is not None:
            id = f2f['recipes'][1]['recipe_id']
            
        return redirect(url_for('show_recipe', id=id))
    
    
    return render_template('index.html')
Exemplo n.º 2
0
def show_recipe(id):
    f2f = food2fork()
    recipe = f2f.getRecipe(id)
    if recipe is not None:
        title = recipe['recipe']['title']
        ingredients = recipe['recipe']['ingredients']
        source_url = recipe['recipe']['source_url']
        return render_template('show_recipe.html' , title = title ,ingredients= ingredients, source_url = source_url)
Exemplo n.º 3
0
    def call_api(self):
        ## search food2fork api for 30 results.
        ## could jus be searched independently at have the results shown

        f2f = food2fork("42fbfb9eb6159d93b1dfbabc502ee380")
        searched_item = str(self.ingredients)
        recipe = f2f.search(searched_item)
        foodtable = DataFrame(recipe["recipes"])
        recipe_ids = list(foodtable["recipe_id"])

        recipe_list = [f2f.getRecipe(i) for i in recipe_ids]

        ing = []
        inglist = []

        for x in range(30):
            ing.append(DataFrame(recipe_list[x]).loc["ingredients"])

        for i in ing:
            inglist.append(i)

        df = DataFrame({"title": foodtable["title"], "recipe_id": foodtable["recipe_id"], "ingredients": Series(ing)})

        return df
Exemplo n.º 4
0
        return df

    def get_ingredients(self):
        ##shoud prompt for users to input what they have
        ctr = 0
        while ctr < 2:  # limiting a number of ingredients, we'll assume they have seasoning unless it's rare.
            self.ingredients.append(raw_input("what do you have? Enter: "))
            ctr += 1
        return "you have: ", self.ingredients
        ## at this point it returns the ingredient list
        ## i want to compare ingredients with what I have in the list


## looking at the data for one item to test!
f2f = food2fork("42fbfb9eb6159d93b1dfbabc502ee380")

##shoud prompt for users to input what they have
ctr = 0
ingredients = []
while ctr < 2:  # limiting a number of ingredients, we'll assume they have seasoning unless it's rare.
    ingredients.append(raw_input("what do you have? Enter: "))
    ctr += 1

searched_item = ", ".join(ingredients)
recipe = f2f.search(searched_item)

foodtable = DataFrame(recipe["recipes"])
recipe_ids = list(foodtable["recipe_id"])