Skip to content

Commit

Permalink
Merge pull request #22 from kat9897/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
kat9897 authored Jan 28, 2024
2 parents cf97ac6 + 020b7ee commit d4c156e
Show file tree
Hide file tree
Showing 4 changed files with 38,068 additions and 68 deletions.
5 changes: 5 additions & 0 deletions app/backend/formatted_recipes.py

Large diffs are not rendered by default.

138 changes: 71 additions & 67 deletions app/backend/generate_recipes.py
Original file line number Diff line number Diff line change
@@ -1,76 +1,78 @@
import requests

from .. import API_KEY
# from .. import API_KEY
from recipes import og_recipes

def parse_recipe(state):
res = get_random_recipes(state)
first_recipe = res["recipes"][0]
recipe = {
"RecipeID": first_recipe["id"],
"RecipeName": first_recipe["title"],
"Description": "",
"RecipeThumbnailLink": first_recipe["image"],
"DatePosted": "",
"RecipeIngredients": [],
"Ingredients": []
}
for ingred in first_recipe["extendedIngredients"]:
# RecipeIngredients
single_rec_ingred = {
def parse_recipes():
recipes = []
#result = get_random_recipes(state)
for first_recipe in og_recipes["recipes"]:
recipe = {
"RecipeID": first_recipe["id"],
"IngredientID": "",
"Quantity": 0,
"QuantityUnit": "ml"
}
single_rec_ingred["IngredientID"] = ingred["id"]
single_rec_ingred["Quantity"] = ingred["measures"]["us"]["amount"]
single_rec_ingred["QuantityUnit"] = ingred["measures"]["us"]["unitShort"]
recipe["RecipeIngredients"].append(single_rec_ingred)

# Ingredients
ingred_response = get_ingredient(state, int(ingred["id"]))
single_ingred = {
"IngredientID": int(ingred["id"]),
"IngredientName": ingred_response["name"],
"Description": "",
"Sugar_g": 0,
"Sodium_mg": 0,
"Fats_g": 0,
"Protein_g": 0,
"Vitamin_A_mcg": 0,
"Vitamin_B_mcg": 0,
"Vitamin_C_mcg": 0,
"Vitamin_D_mcg": 0,
"Fiber_g": 0,
"Calories": 0
"RecipeName": first_recipe["title"],
"Description": first_recipe["summary"],
"RecipeThumbnailLink": first_recipe["image"],
"DatePosted": "",
"RecipeIngredients": []
}
for ingred in first_recipe["extendedIngredients"]:
# RecipeIngredients
single_rec_ingred = {
"RecipeID": first_recipe["id"],
"IngredientID": ingred["id"],
"IngredientName": ingred["name"],
"Quantity": ingred["measures"]["us"]["amount"],
"QuantityUnit": ingred["measures"]["us"]["unitShort"]
}
recipe["RecipeIngredients"].append(single_rec_ingred)

# Nutrients
for res_nutrient in ingred_response["nutrition"]["nutrients"]:
res_nutrient_title = res_nutrient["name"].strip()
if res_nutrient_title in "Sugar":
single_ingred["Sugar_g"] = res_nutrient["amount"]
elif res_nutrient_title in "Fat":
single_ingred["Fats_g"] = res_nutrient["amount"]
elif res_nutrient_title in "Protein":
single_ingred["Protein_g"] = res_nutrient["amount"]
elif res_nutrient_title in "Sodium":
single_ingred["Sodium_mg"] = res_nutrient["amount"]
elif res_nutrient_title in "Vitamin A":
single_ingred["Vitamin_A_mcg"] = res_nutrient["amount"]
elif res_nutrient_title in "Vitamin C":
single_ingred["Vitamin_C_mcg"] = res_nutrient["amount"]
elif "Vitamin B" in res_nutrient_title:
single_ingred["Vitamin_B_mcg"] = res_nutrient["amount"]
elif res_nutrient_title in "Vitamin D":
single_ingred["Vitamin_D_mcg"] = res_nutrient["amount"]
elif res_nutrient_title in "Fiber":
single_ingred["Fiber_g"] = res_nutrient["amount"]
elif res_nutrient_title in "Calories":
single_ingred["Calories"] = res_nutrient["amount"]
recipe["Ingredients"].append(single_ingred)
# Ingredients
#ingred_response = get_ingredient(state, int(ingred["id"]))
# single_ingred = {
# "IngredientID": int(ingred["id"]),
# "IngredientName": ingred_response["name"],
# "Description": "",
# "Sugar_g": 0,
# "Sodium_mg": 0,
# "Fats_g": 0,
# "Protein_g": 0,
# "Vitamin_A_mcg": 0,
# "Vitamin_B_mcg": 0,
# "Vitamin_C_mcg": 0,
# "Vitamin_D_mcg": 0,
# "Fiber_g": 0,
# "Calories": 0
# }

print(recipe)
# # Nutrients
# for res_nutrient in ingred_response["nutrition"]["nutrients"]:
# res_nutrient_title = res_nutrient["name"].strip()
# if res_nutrient_title in "Sugar":
# single_ingred["Sugar_g"] = res_nutrient["amount"]
# elif res_nutrient_title in "Fat":
# single_ingred["Fats_g"] = res_nutrient["amount"]
# elif res_nutrient_title in "Protein":
# single_ingred["Protein_g"] = res_nutrient["amount"]
# elif res_nutrient_title in "Sodium":
# single_ingred["Sodium_mg"] = res_nutrient["amount"]
# elif res_nutrient_title in "Vitamin A":
# single_ingred["Vitamin_A_mcg"] = res_nutrient["amount"]
# elif res_nutrient_title in "Vitamin C":
# single_ingred["Vitamin_C_mcg"] = res_nutrient["amount"]
# elif "Vitamin B" in res_nutrient_title:
# single_ingred["Vitamin_B_mcg"] = res_nutrient["amount"]
# elif res_nutrient_title in "Vitamin D":
# single_ingred["Vitamin_D_mcg"] = res_nutrient["amount"]
# elif res_nutrient_title in "Fiber":
# single_ingred["Fiber_g"] = res_nutrient["amount"]
# elif res_nutrient_title in "Calories":
# single_ingred["Calories"] = res_nutrient["amount"]
# recipe["Ingredients"].append(single_ingred)

recipes.append(recipe)
# print(recipes)
with open("formatted_recipes.py", "a") as form_recipes:
form_recipes.write(str(recipes))

def get_random_recipes(state):
parameters = {
Expand All @@ -92,4 +94,6 @@ def get_ingredient(state, id):
}
response = requests.get(f"https://api.spoonacular.com/food/ingredients/{id}/information", params=parameters, headers=heads)
res = response.json()
return res
return res

parse_recipes()
Loading

0 comments on commit d4c156e

Please sign in to comment.