示例#1
0
    def get_recipes(self):
        """
        Method extracting recipes from Marmiton website based on ingredients list.
    
        Parameters
        ----------
        ingredients_to_include : list of strings
            Ingredients to include to recipe (in French)
        ingredients_to_exclude : list of strings
            Ingredients to exclude from recipe (in French)


        Returns
        -------
        DataFrame
            DataFrame containing all matching recipes with recipe name as index 
            and with recipe infos as columns :
            - ingredients: string list of the recipe ingredients (including quantities)
            - steps: string list of each step of the recipe
            - image: if exists, image of the recipe (url).
        """

        # Creation of query keywords based on ingredients
        ingredients_to_include = self.included_ingredients
        ingredients_to_exclude = self.excluded_ingredients

        query_keywords = " ".join(ingredients_to_include)
        if len(ingredients_to_exclude) > 0:
            query_keywords += " sans "
            query_keywords += " ".join(ingredients_to_exclude)

        # Search :
        query_options = {"aqt": query_keywords, "st": 1}

        query_result = []
        try:
            query_result = Marmiton.search(query_options)
        except URLError:
            st.error('Vérifie ta connexion internet !')
            return query_result
        else:
            if len(query_result) == 0:
                st.error('Vérifie ta connexion internet !')
                return query_result

        # Recap on recipes and urls
        url_list = [recipe['url'] for recipe in query_result]
        recipes_list = [recipe['name'] for recipe in query_result]

        # Creation of tab with recipes infos
        recipes_keys = ['image', 'ingredients', 'steps']
        recipes_tab = pd.DataFrame(index=recipes_list, columns=recipes_keys)

        for url in url_list:
            recipe = Marmiton.get(url)

            for key in recipes_keys:
                recipes_tab.loc[recipe['name'], key] = recipe[key]

        return recipes_tab
示例#2
0
def searchMarmiton(es, id, name, vg=-1, exp=-1, dif=-1):

    res = es.get(index="users", id=0)
    res = res["_source"]
    if exp == -1:
        exp = res["expMax"]
    if dif == -1:
        dif = res["difMax"]
    if vg == -1:
        vg = res["vg"]
    result = []
    query_options = {
        "aqt": name,  # Query keywords - separated by a white space
        "exp":
        exp,  # Plate price : 1 -> Cheap, 2 -> Medium, 3 -> Kind of expensive (optional)
        "dif":
        dif,  # Recipe difficulty : 1 -> Very easy, 2 -> Easy, 3 -> Medium, 4 -> Advanced (optional)
        "veg": vg,  # Vegetarien only : 0 -> False, 1 -> True (optional)
    }
    query_result = Marmiton.search(query_options)
    k = 0
    while k < len(query_result):
        try:
            Marmiton.get(query_result[k]['url'])
            k += 1
        except:
            query_result.pop(k)
    l = 0
    while (l < len(query_result) and l < 5):
        result.append(query_result[l])
        l += 1

    return result
示例#3
0
def get_recipes(ingredients_to_include=[], ingredients_to_exclude=[]):
    """Function extracting recipes from Marmiton website based on ingredients list.
    
    Parameters
        ----------
        ingredients_to_include : list of strings
            Ingredients to include to recipe (in French)
        ingredients_to_exclude : list of strings
            Ingredients to exclude from recipe (in French)


        Returns
        -------
        DataFrame
            DataFrame containing all matching recipes with recipe name as index 
            and with recipe infos as columns :
            - ingredients: string list of the recipe ingredients (including quantities)
            - steps: string list of each step of the recipe
            - image: if exists, image of the recipe (url).
            - cook_time: string, cooking time of the recipe
            - prep_time: string, estimated preparation time of the recipe
            - total_time: string, estimated total time of the recipe (cooking + preparation time)
            - author: string, name of the author of the recipe
            - nb_comments: string, number of comments/rates left by users
            - people_quantity: string, number of people the recipie is made for
            - budget: string, indicate the category of budget according to the website
            - difficulty: string, indicate the category of difficulty according to the website
            - rate, string: rate of the recipe out of 5
            - author_tip: string, note or tip left by the author
            - tags: string list, tags of the recipe
        """

    # Creation of query keywords based on ingredients
    query_keywords = " ".join(ingredients_to_include)
    if len(ingredients_to_exclude) > 0:
        query_keywords += " sans "
        query_keywords += " ".join(ingredients_to_exclude)

    # Search :
    query_options = {"aqt": query_keywords, "st": 1}
    query_result = Marmiton.search(query_options)

    # Recap on recipes and urls
    url_list = [recipe['url'] for recipe in query_result]
    recipes_list = [recipe['name'] for recipe in query_result]

    # Creation of tab with recipes infos
    recipes_keys = list(Marmiton.get(url_list[0]).keys())
    recipes_keys.remove('name')
    recipes_tab = pd.DataFrame(index=recipes_list,
                               columns=['url'] + recipes_keys)

    for url in url_list:
        recipe = Marmiton.get(url)
        recipes_tab.loc[recipe['name'], 'url'] = url
        for key in recipes_keys:
            recipes_tab.loc[recipe['name'], key] = recipe[key]

    return recipes_tab
示例#4
0
def randomMenu(es, id=0):
    res = es.get(index="users", id=id)
    res = res['_source']
    if len(res["menuList"]) == 0:
        return "erreur bro"
    nb = randint(0, len(res["menuList"]) - 1)
    return Marmiton.get(res["menuList"][nb]['url'])
def recipes_dl(keywords, offset, limit, dl=None):
	keywords = keywords.replace('-', ' ')
	query_opt = {
		"aqt": keywords
	}
	dl = True if (flask.request.args.get('download') == '') else False
	query_search = Marmiton.search(query_opt)
	final = dict()
	x = 0
	if offset < len(query_search) and offset >= 0:
		x = offset
	if limit > len(query_search) or limit <= 0:
		limit = len(query_search)
	if (dl == True):
		z = zipfile.ZipFile('./Flask-archives.zip', 'w')
	while x < limit:
		final[x] = query_search[x]['image']
		name = '/tmp/recipe' + str(x) + '.jpg'
		if (dl == True):
			request.urlretrieve(final[x], name)
			z.write(name)
		x += 1
	if (dl == True):
		z.close()
	return jsonify(final)
示例#6
0
    def __init__(self, intentMessage, name, url):
        self.session_id = intentMessage.session_id
        self.site_id = intentMessage.site_id
        self.name = name
        self.url = url
        recipe = Marmiton.get(self.url)
        #
        for key in recipe:
            print(key, end=", ")
            setattr(self, key, recipe[key])

        self.currentStep = -1
        self.numStep = len(self.steps)
示例#7
0
 def search(self, hh):
     print("searching")
     menu_list = menudb.searchRecipe(menudb.init(), self.user.get_id(), self.textsearch, vg=self.vg, exp=self.exp_last_press, dif=self.dif_last_press)
     print(menu_list)
     self.current_menu_list=menu_list
     self.screen_manager.current="showresults"
     if len(menu_list)==0:
         while len(self.current_menu_list)<5:
             self.current_menu_list.append({"image":"","name":"Aucuns résultats","url":""})
     else:
         while len(self.current_menu_list)<5:
             self.current_menu_list.append(self.current_menu_list[-1])
     
     self.current_menu_names4=self.current_menu_list[4]["name"]
     self.current_menu_names3=self.current_menu_list[3]["name"]
     self.current_menu_names2=self.current_menu_list[2]["name"]
     self.current_menu_names1=self.current_menu_list[1]["name"]
     self.current_menu_names0=self.current_menu_list[0]["name"]
     
     self.image0=Marmiton.get(self.current_menu_list[0]["url"])["image"]
     self.image1=Marmiton.get(self.current_menu_list[1]["url"])["image"]
     self.image2=Marmiton.get(self.current_menu_list[2]["url"])["image"]
     self.image3=Marmiton.get(self.current_menu_list[3]["url"])["image"]
     self.image4=Marmiton.get(self.current_menu_list[4]["url"])["image"]
示例#8
0
def lookup(url: str) -> Recipe:
    source = 'marmiton'
    recipe_details = mr.get(url)
    name = recipe_details.get('name')
    ingredients = recipe_details.get('ingredients')
    time = recipe_details.get('total_time')
    image = recipe_details.get('image')
    rating = recipe_details.get('rate')
    return Recipe({ 'name' : name,
                    'ingredients' : ingredients,
                    'time' : time,
                    'image' : image,
                    'rating' : rating,
                    'url' : url,
                    'source' : source
                    })
示例#9
0
def action_open_recipe(hermes, intentMessage):
    recipe_name = intentMessage.slots.recipe.first().value
    print(recipe_name)

    if (intentMessage.site_id in OPENED_RECIPES):
        close_recipe(hermes, OPENED_RECIPES[intentMessage.site_id])

    query_options = {
        "aqt": recipe_name,  # Query keywords - separated by a white space
    }
    query_result = Marmiton.search(query_options)
    print("Research done")
    # Get :
    if len(query_result) == 0:
        result_sentence = f"Je n'ai pas trouvé de recettes pour {recipe_name}"
        hermes.publish_end_session(intentMessage.session_id, result_sentence)
    else:
        result_sentence = f"C'est parti pour la recette de {query_result[0]['name']}"
        hermes.publish_start_session_notification(intentMessage.site_id,
                                                  result_sentence, {})
        open_recipe(
            hermes,
            Recipe(intentMessage, query_result[0]['name'],
                   query_result[0]['url']))
示例#10
0
from marmiton import Marmiton

# Search :
query_options = {
  "aqt": "boeuf bourguignon",      # Query keywords - separated by a white space
  "dt": "platprincipal",      # Plate type : "entree", "platprincipal", "accompagnement", "amusegueule", "sauce" (optional)
  "exp": 2,                   # Plate price : 1 -> Cheap, 2 -> Medium, 3 -> Kind of expensive (optional)
  "dif": 2,                   # Recipe difficulty : 1 -> Very easy, 2 -> Easy, 3 -> Medium, 4 -> Advanced (optional)
  "veg": 0,                   # Vegetarien only : 0 -> False, 1 -> True (optional)
}
query_result = Marmiton.search(query_options)

# Get :
recipe = query_result[0]
main_recipe_url = recipe['url']

detailed_recipe = Marmiton.get(main_recipe_url)  # Get the details of the first returned recipe (most relevant in our case)

# Display result :
print("## %s\n" % detailed_recipe['name'])  # Name of the recipe
print("Recette par '%s'" % (detailed_recipe['author']))
print("Noté %s/5 par %s personnes." % (detailed_recipe['rate'], detailed_recipe['nb_comments']))
print("Temps de cuisson : %s / Temps de préparation : %s / Temps total : %s." % (detailed_recipe['cook_time'] if detailed_recipe['cook_time'] else 'N/A',detailed_recipe['prep_time'], detailed_recipe['total_time']))
print("Tags : %s" % (", ".join(detailed_recipe['tags'])))
print("Difficulté : '%s'" % detailed_recipe['difficulty'])
print("Budget : '%s'" % detailed_recipe['budget'])

print("\nRecette pour %s personne(s) :\n" % detailed_recipe['people_quantity'])
for ingredient in detailed_recipe['ingredients']:  # List of ingredients
    print("- %s" % ingredient)
示例#11
0
def get_marmiton_val(keywords):
    keywords = keywords.replace('-', ' ')
    query_opt = {"aqt": keywords}
    query_search = Marmiton.search(query_opt)
    return query_search
示例#12
0
def search(ingredients: List[str]) -> List[int]:
    query_options = {
        'aqt' : ' '.join(ingredients),
    }
    query_results = mr.search(query_options)
    return db_interface.add([recipe['url'] for recipe in query_results], 'marmiton')