-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetRecipe.py
34 lines (29 loc) · 1008 Bytes
/
getRecipe.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import requests
from variables import apiKey
def getRecipe(tags=""):
url = f"https://api.spoonacular.com/recipes/random?tags={tags}&apiKey={apiKey}"
response = requests.get(url)
response = response.json()["recipes"]
for data in response:
title = data["title"]
readyInMinutes = data["readyInMinutes"]
servings = data["servings"]
recipeUrl = data["spoonacularSourceUrl"]
vegetarian = data["vegetarian"]
vegan = data["vegan"]
image = data["image"]
message = f"""
{title} 😋{" - Vegan" if vegan else ""}{" - Vegetarian" if vegetarian and not vegan else ""}
Ready in {readyInMinutes} minutes 🕒
{servings} servings 👨🍳
Ingredients:
"""
for ingredient in data["extendedIngredients"]:
message = message+f"""
🔸 {ingredient['original']}
"""
message = message+f"""
{image}
\nRead more about this recipe in {recipeUrl}\n
"""
return message