Skip to content

Commit

Permalink
Merge pull request #18 from kat9897/k_front_page_heavy_stylin
Browse files Browse the repository at this point in the history
parse_recipes has multiple recipes now
  • Loading branch information
kat9897 authored Jan 27, 2024
2 parents 7d6d95a + 8f9f224 commit 09ccefa
Showing 1 changed file with 67 additions and 65 deletions.
132 changes: 67 additions & 65 deletions app/backend/generate_recipes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,75 +2,77 @@

from .. import API_KEY

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(state):
recipes = []
result = get_random_recipes(state)
for first_recipe in result["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": "",
"RecipeThumbnailLink": first_recipe["image"],
"DatePosted": "",
"RecipeIngredients": [],
"Ingredients": []
}
for ingred in first_recipe["extendedIngredients"]:
# RecipeIngredients
single_rec_ingred = {
"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)

# 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)
return recipes

def get_random_recipes(state):
parameters = {
Expand Down

0 comments on commit 09ccefa

Please sign in to comment.