From aac3f92d2f6c3f190f6156527f96946a4503575b Mon Sep 17 00:00:00 2001 From: Lilly Kaemmerling Date: Thu, 2 Sep 2021 20:38:16 +0200 Subject: [PATCH 1/2] Upload data into the db - final version --- notebooks/Final-data-upload.ipynb | 766 ++++++++++++++++++++++++++++++ notebooks/Postgresql.ipynb | 38 +- 2 files changed, 791 insertions(+), 13 deletions(-) create mode 100644 notebooks/Final-data-upload.ipynb diff --git a/notebooks/Final-data-upload.ipynb b/notebooks/Final-data-upload.ipynb new file mode 100644 index 0000000..ed765b8 --- /dev/null +++ b/notebooks/Final-data-upload.ipynb @@ -0,0 +1,766 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "753d7e21", + "metadata": {}, + "source": [ + "# Final Notebook to upload data into database" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "bc86bf51", + "metadata": {}, + "outputs": [], + "source": [ + "import psycopg2\n", + "import os\n", + "import pandas as pd\n", + "from bs4 import BeautifulSoup\n", + "import requests\n", + "import csv" + ] + }, + { + "cell_type": "markdown", + "id": "8a907279", + "metadata": { + "heading_collapsed": true + }, + "source": [ + "## Create table in database" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "c8c39482", + "metadata": { + "hidden": true + }, + "outputs": [], + "source": [ + "DB_PASSWORD = os.environ['DB_PASSWORD']" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "cc995586", + "metadata": { + "hidden": true + }, + "outputs": [], + "source": [ + "conn = psycopg2.connect(database=\"d1hsr1c7nk56dl\", user = \"iadkkqrgljveni\", host = \"ec2-3-230-61-252.compute-1.amazonaws.com\", port = \"5432\", password=DB_PASSWORD)" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "cb6dafbd", + "metadata": { + "hidden": true + }, + "outputs": [], + "source": [ + "cur = conn.cursor()" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "9faba32e", + "metadata": { + "hidden": true + }, + "outputs": [], + "source": [ + "#Creating the table only ONCE\n", + "cur.execute(\n", + " '''CREATE TABLE COOKIT_RECIPES\n", + " (ID INT PRIMARY KEY NOT NULL,\n", + " TITLE TEXT NOT NULL,\n", + " DIFFICULTY TEXT,\n", + " PREPTIME INT,\n", + " NUMBER_OF_INGREDIENTS INT,\n", + " INGREDIENTS TEXT[] NOT NULL,\n", + " CUISINE TEXT NOT NULL,\n", + " CALORIES TEXT,\n", + " LINK TEXT NOT NULL,\n", + " PICTURE_URL TEXT NOT NULL,\n", + " INSTRUCTIONS TEXT);''')\n", + "\n", + "conn.commit()" + ] + }, + { + "cell_type": "markdown", + "id": "0a997eee", + "metadata": { + "heading_collapsed": true + }, + "source": [ + "## Upload 750 recipes from lewagon" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "d0cf9e34", + "metadata": { + "hidden": true + }, + "outputs": [], + "source": [ + "def scrape_recipe(url):\n", + "\n", + " html_content = bytearray()\n", + " response = requests.get(url)\n", + "\n", + " if response.history == []:\n", + " html_content += response.content\n", + "\n", + " return str(html_content)" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "0ad423db", + "metadata": { + "hidden": true + }, + "outputs": [], + "source": [ + "def parse(recipe_html):\n", + " \n", + " #html input = response.content\n", + "\n", + " soup = BeautifulSoup(recipe_html, 'html.parser')\n", + " details = {}\n", + " \n", + " #Find all ingredients on the specific page\n", + " ingredients_soup = soup.find_all('div', class_='ingredient')\n", + " ingredients = []\n", + "\n", + " for ingredient in ingredients_soup:\n", + " description = ingredient.find('p', class_='mb-0').text\n", + " ingredients.append(description)\n", + " \n", + " \n", + " #Find all ingredients on the specific page\n", + " cuisines = []\n", + " cuisines_soup = soup.find_all('span', class_=\"badge badge-success\")\n", + " \n", + " if len(cuisines_soup) < 1:\n", + " cuisines.append(\"No cuisine specified\")\n", + " else:\n", + " for cuisine in cuisines_soup:\n", + " cuisines.append(cuisine.text)\n", + " \n", + " details[\"ingredients\"] = ingredients\n", + " details[\"cuisine\"] = cuisines\n", + " \n", + " return details" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "5644cce5", + "metadata": { + "hidden": true + }, + "outputs": [], + "source": [ + "recipes = pd.read_csv(\"../raw_data/recipes.csv\")" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "369acae7", + "metadata": { + "hidden": true + }, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
namedifficultyprep_timelinkpicture_url
745Yogurt Marinated Lamb SkewersEasy45 minhttps://recipes.lewagon.com/recipes/649https://spoonacular.com/recipeImages/665550-55...
746Yorkshire PuddingModerate45 minhttps://recipes.lewagon.com/recipes/779https://spoonacular.com/recipeImages/665573-55...
747Zucchini Chicken OmeletteEasy45 minhttps://recipes.lewagon.com/recipes/923https://spoonacular.com/recipeImages/665734-55...
748Zucchini Flutes Piped With Basil Ricotta MousseVery hard45 minhttps://recipes.lewagon.com/recipes/863https://spoonacular.com/recipeImages/665744-55...
749Zucchini Ribbon and Ricotta PizzaVery easy45 minhttps://recipes.lewagon.com/recipes/469https://spoonacular.com/recipeImages/665779-55...
\n", + "
" + ], + "text/plain": [ + " name difficulty prep_time \\\n", + "745 Yogurt Marinated Lamb Skewers Easy 45 min \n", + "746 Yorkshire Pudding Moderate 45 min \n", + "747 Zucchini Chicken Omelette Easy 45 min \n", + "748 Zucchini Flutes Piped With Basil Ricotta Mousse Very hard 45 min \n", + "749 Zucchini Ribbon and Ricotta Pizza Very easy 45 min \n", + "\n", + " link \\\n", + "745 https://recipes.lewagon.com/recipes/649 \n", + "746 https://recipes.lewagon.com/recipes/779 \n", + "747 https://recipes.lewagon.com/recipes/923 \n", + "748 https://recipes.lewagon.com/recipes/863 \n", + "749 https://recipes.lewagon.com/recipes/469 \n", + "\n", + " picture_url \n", + "745 https://spoonacular.com/recipeImages/665550-55... \n", + "746 https://spoonacular.com/recipeImages/665573-55... \n", + "747 https://spoonacular.com/recipeImages/665734-55... \n", + "748 https://spoonacular.com/recipeImages/665744-55... \n", + "749 https://spoonacular.com/recipeImages/665779-55... " + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "recipes.tail()" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "8b29a2a8", + "metadata": { + "hidden": true + }, + "outputs": [], + "source": [ + "#Based on loaded dataframe\n", + "def insert_into_db(recipes):\n", + " \n", + " for index, row in recipes.iterrows():\n", + " primary_key = index\n", + " title = row[\"name\"]\n", + " difficulty = row[\"difficulty\"]\n", + " prep_time = int(recipes.loc[index][\"prep_time\"][:2])\n", + " url = row[\"link\"]\n", + " picture_url = row[\"picture_url\"]\n", + " instructions = \"Please follow the link for instructions\"\n", + " \n", + " recipe = parse(scrape_recipe(url))\n", + " \n", + " number_of_ingredients = len(recipe[\"ingredients\"])\n", + " ingredients = recipe[\"ingredients\"]\n", + " cuisine = recipe[\"cuisine\"][0]\n", + " \n", + " calories = \"No information available\"\n", + " \n", + " \n", + " query = \"\"\"INSERT INTO COOKIT_RECIPES (ID, TITLE, DIFFICULTY, PREPTIME, NUMBER_OF_INGREDIENTS, \n", + " INGREDIENTS, CUISINE, CALORIES, LINK, PICTURE_URL, INSTRUCTIONS)\n", + " VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)\"\"\"\n", + " \n", + " cur.execute(query, (primary_key, title, difficulty, prep_time, number_of_ingredients, ingredients, cuisine, calories, url, picture_url, instructions));\n", + " conn.commit()" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "48716df2", + "metadata": { + "hidden": true + }, + "outputs": [], + "source": [ + "insert_into_db(recipes)" + ] + }, + { + "cell_type": "markdown", + "id": "18a34c24", + "metadata": {}, + "source": [ + "## Insert BBC Recipes" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "id": "f58777f9", + "metadata": {}, + "outputs": [], + "source": [ + "recipes_1 = pd.read_csv(\"../raw_data/recipe_list_1015_bbcfood_4231.csv\")" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "id": "413d1738", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "title 0\n", + "total_time 0\n", + "yields 0\n", + "ingredients 0\n", + "instructions 1\n", + "image 0\n", + "calories 0\n", + "url 0\n", + "cuisine 4231\n", + "dietary_restrictions 4231\n", + "num_of_ingredients 0\n", + "dtype: int64" + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "recipes_1.isnull().sum()" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "id": "eee6ab8d", + "metadata": {}, + "outputs": [], + "source": [ + "#Fill NaN of cuisine and dietary restrictions\n", + "recipes_1.fillna(\"Not specified\", inplace=True)" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "id": "87b9ecad", + "metadata": {}, + "outputs": [], + "source": [ + "#add column for difficulty\n", + "for index, row in recipes_1.iterrows():\n", + " if row[\"total_time\"] < 15:\n", + " recipes_1.loc[index, \"difficulty\"] = \"easy\"\n", + " elif row[\"total_time\"] < 45:\n", + " recipes_1.loc[index, \"difficulty\"] = \"medium\"\n", + " else:\n", + " recipes_1.loc[index, \"difficulty\"] = \"hard\" " + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "id": "8abf4c4e", + "metadata": {}, + "outputs": [], + "source": [ + "#ToDO replace calories with not specified or so \n", + "recipes_1.drop(columns=\"calories\", inplace=True)" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "id": "515305fb", + "metadata": {}, + "outputs": [], + "source": [ + "recipes_1[\"calories\"] = \"No information available\"" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "id": "67342450", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "RangeIndex: 4231 entries, 0 to 4230\n", + "Data columns (total 12 columns):\n", + " # Column Non-Null Count Dtype \n", + "--- ------ -------------- ----- \n", + " 0 title 4231 non-null object\n", + " 1 total_time 4231 non-null int64 \n", + " 2 yields 4231 non-null object\n", + " 3 ingredients 4231 non-null object\n", + " 4 instructions 4231 non-null object\n", + " 5 image 4231 non-null object\n", + " 6 url 4231 non-null object\n", + " 7 cuisine 4231 non-null object\n", + " 8 dietary_restrictions 4231 non-null object\n", + " 9 num_of_ingredients 4231 non-null int64 \n", + " 10 difficulty 4231 non-null object\n", + " 11 calories 4231 non-null object\n", + "dtypes: int64(2), object(10)\n", + "memory usage: 396.8+ KB\n" + ] + } + ], + "source": [ + "recipes_1.info()" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "id": "4df23a66", + "metadata": {}, + "outputs": [], + "source": [ + "#Based on loaded dataframe\n", + "def insert_into_db(recipes):\n", + " \n", + " for index, row in recipes.iterrows():\n", + " primary_key = index+750+4123\n", + " title = row[\"title\"]\n", + " difficulty = row[\"difficulty\"]\n", + " prep_time = row[\"total_time\"]\n", + " number_of_ingredients = row[\"num_of_ingredients\"]\n", + " \n", + " liste = recipes.iloc[index][\"ingredients\"][1:-1].split(\"',\")\n", + " ingredient_liste = []\n", + " for element in liste:\n", + " ingredient_liste.append(element.replace(\"'\", \"\").strip())\n", + " \n", + " ingredients = ingredient_liste\n", + " \n", + " cuisine = row[\"cuisine\"]\n", + " calories = row[\"calories\"]\n", + " url = row[\"url\"]\n", + " picture_url = row[\"image\"]\n", + " instructions = row[\"instructions\"]\n", + "\n", + " \n", + " query = \"\"\"INSERT INTO COOKIT_RECIPES (ID, TITLE, DIFFICULTY, PREPTIME, NUMBER_OF_INGREDIENTS, \n", + " INGREDIENTS, CUISINE, CALORIES, LINK, PICTURE_URL, INSTRUCTIONS)\n", + " VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)\"\"\"\n", + " \n", + " cur.execute(query, (primary_key, title, difficulty, prep_time, number_of_ingredients, ingredients, cuisine, calories, url, picture_url, instructions));\n", + " conn.commit()" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "id": "591a391c", + "metadata": {}, + "outputs": [], + "source": [ + "insert_into_db(recipes_1)" + ] + }, + { + "cell_type": "markdown", + "id": "9df5a361", + "metadata": {}, + "source": [ + "## Insert Jamie Oliver Recipes" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "id": "07b07e35", + "metadata": {}, + "outputs": [], + "source": [ + "recipes_2 = pd.read_csv(\"../raw_data/recipe_list_2010_JamieOliver.csv\")" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "id": "db3bbf81", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "title 0\n", + "total_time 0\n", + "yields 0\n", + "ingredients 0\n", + "instructions 0\n", + "image 0\n", + "calories 0\n", + "url 0\n", + "cuisine 4122\n", + "dietary_restrictions 4122\n", + "num_of_ingredients 0\n", + "dtype: int64" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "recipes_2.isnull().sum()" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "id": "544fc24d", + "metadata": {}, + "outputs": [], + "source": [ + "#Fill NaN of cuisine and dietary restrictions\n", + "recipes_2.fillna(\"Not specified\", inplace=True)" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "id": "a4875f4a", + "metadata": {}, + "outputs": [], + "source": [ + "#add column for difficulty\n", + "for index, row in recipes_2.iterrows():\n", + " if row[\"total_time\"] < 15:\n", + " recipes_2.loc[index, \"difficulty\"] = \"easy\"\n", + " elif row[\"total_time\"] < 45:\n", + " recipes_2.loc[index, \"difficulty\"] = \"medium\"\n", + " else:\n", + " recipes_2.loc[index, \"difficulty\"] = \"hard\" " + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "id": "ec3dffe1", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "RangeIndex: 4122 entries, 0 to 4121\n", + "Data columns (total 12 columns):\n", + " # Column Non-Null Count Dtype \n", + "--- ------ -------------- ----- \n", + " 0 title 4122 non-null object\n", + " 1 total_time 4122 non-null int64 \n", + " 2 yields 4122 non-null object\n", + " 3 ingredients 4122 non-null object\n", + " 4 instructions 4122 non-null object\n", + " 5 image 4122 non-null object\n", + " 6 calories 4122 non-null object\n", + " 7 url 4122 non-null object\n", + " 8 cuisine 4122 non-null object\n", + " 9 dietary_restrictions 4122 non-null object\n", + " 10 num_of_ingredients 4122 non-null int64 \n", + " 11 difficulty 4122 non-null object\n", + "dtypes: int64(2), object(10)\n", + "memory usage: 386.6+ KB\n" + ] + } + ], + "source": [ + "recipes_2.info()" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "id": "724fa21d", + "metadata": {}, + "outputs": [], + "source": [ + "#Based on loaded dataframe\n", + "def insert_into_db(recipes):\n", + " \n", + " for index, row in recipes.iterrows():\n", + " primary_key = index+750\n", + " title = row[\"title\"]\n", + " difficulty = row[\"difficulty\"]\n", + " prep_time = row[\"total_time\"]\n", + " number_of_ingredients = row[\"num_of_ingredients\"]\n", + " \n", + " liste = recipes.iloc[index][\"ingredients\"][1:-1].split(\"',\")\n", + " ingredient_liste = []\n", + " for element in liste:\n", + " ingredient_liste.append(element.replace(\"'\", \"\").strip())\n", + " \n", + " ingredients = ingredient_liste\n", + " \n", + " cuisine = row[\"cuisine\"]\n", + " calories = row[\"calories\"]\n", + " url = row[\"url\"]\n", + " picture_url = row[\"image\"]\n", + " instructions = row[\"instructions\"]\n", + "\n", + " \n", + " query = \"\"\"INSERT INTO COOKIT_RECIPES (ID, TITLE, DIFFICULTY, PREPTIME, NUMBER_OF_INGREDIENTS, \n", + " INGREDIENTS, CUISINE, CALORIES, LINK, PICTURE_URL, INSTRUCTIONS)\n", + " VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)\"\"\"\n", + " \n", + " cur.execute(query, (primary_key, title, difficulty, prep_time, number_of_ingredients, ingredients, cuisine, calories, url, picture_url, instructions));\n", + " conn.commit()" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "id": "97cf434f", + "metadata": {}, + "outputs": [], + "source": [ + "insert_into_db(recipes_2)" + ] + }, + { + "cell_type": "markdown", + "id": "a0ef1d1f", + "metadata": {}, + "source": [ + "## Check size of db" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "id": "ccb7371f", + "metadata": {}, + "outputs": [], + "source": [ + "recipes = pd.read_sql(\"\"\"SELECT * FROM COOKIT_RECIPES\"\"\", conn)" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "id": "f7b39a00", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "9103" + ] + }, + "execution_count": 29, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "len(recipes)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8.6" + }, + "toc": { + "base_numbering": 1, + "nav_menu": {}, + "number_sections": true, + "sideBar": true, + "skip_h1_title": false, + "title_cell": "Table of Contents", + "title_sidebar": "Contents", + "toc_cell": false, + "toc_position": {}, + "toc_section_display": true, + "toc_window_display": false + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/notebooks/Postgresql.ipynb b/notebooks/Postgresql.ipynb index 8fd11a8..07cd031 100644 --- a/notebooks/Postgresql.ipynb +++ b/notebooks/Postgresql.ipynb @@ -31,7 +31,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "id": "ce9399d4", "metadata": {}, "outputs": [], @@ -42,7 +42,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "id": "a539b65f", "metadata": {}, "outputs": [], @@ -52,7 +52,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 5, "id": "ea061f74", "metadata": {}, "outputs": [], @@ -62,7 +62,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 6, "id": "da7e7b11", "metadata": {}, "outputs": [], @@ -248,7 +248,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 9, "id": "3de9a993", "metadata": {}, "outputs": [], @@ -729,22 +729,34 @@ }, { "cell_type": "code", - "execution_count": 20, - "id": "f38723db", + "execution_count": 17, + "id": "8abcb962", "metadata": {}, "outputs": [], "source": [ - "cur.execute('''SELECT *\n", - "FROM COOKIT_RECIPES;''')" + "recipes = pd.read_sql(\"\"\"SELECT * FROM COOKIT_RECIPES\"\"\", conn)" ] }, { "cell_type": "code", - "execution_count": null, - "id": "8abcb962", + "execution_count": 18, + "id": "45770671", "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "data": { + "text/plain": [ + "7114" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "len(recipes)" + ] } ], "metadata": { From 34eaea6124cefd21a208cd8df65b25b72fcba573 Mon Sep 17 00:00:00 2001 From: Lilly Kaemmerling Date: Thu, 2 Sep 2021 21:18:23 +0200 Subject: [PATCH 2/2] Fixed joining of recognized ingredients by the model and additional ingredients, renamed parameters and tookout the offset value --- app.py | 12 +++++++----- cookit_frontend/recipes.py | 3 ++- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/app.py b/app.py index 3060ac7..c9477f2 100644 --- a/app.py +++ b/app.py @@ -40,10 +40,13 @@ filtered_ingredients = [ingr for ingr in ingredients if ingr in INGREDIENTS] ingredients_selected = st.multiselect("We found these ingredients (delete any you don't want to use)", filtered_ingredients, default=filtered_ingredients) - ingredients_selected_formatted = ", ".join(ingredients_selected) - must_haves = st.multiselect('You can add more ingredients', INGREDIENTS) - must_haves_formatted = ", ".join(must_haves) + additional_ingredients = st.multiselect('You can add more ingredients', INGREDIENTS) + + # Join recognized and additional ingredients together + for element in ingredients_selected: + additional_ingredients.append(element) + final_ingredients = ", ".join(additional_ingredients) exclusions = st.multiselect("Anything you really don't like?", INGREDIENTS) exclusions_formatted = ", ".join(exclusions) @@ -63,8 +66,7 @@ diet = [] if st.button('get recipes'): - recipes = get_recipes(f"{ingredients_selected_formatted}, {must_haves_formatted}", - exclusions, cuisines_formatted, diet) + recipes = get_recipes(final_ingredients, exclusions, cuisines_formatted, diet) if len(recipes) > 0: show_recipes(recipes, 3) diff --git a/cookit_frontend/recipes.py b/cookit_frontend/recipes.py index 3627387..88312c0 100644 --- a/cookit_frontend/recipes.py +++ b/cookit_frontend/recipes.py @@ -47,7 +47,8 @@ def get_recipes(ingredients, exclusions, cuisine, diet): # The number of results to skip (between 0 and 900). # This is a bit risky in cases where less recipes were found than the offset value; # --> the API is then returning no recipes. - "offset": offset} + #"offset": offset + } response = requests.get(BASE_URI, params) print(params)