Skip to content

Commit d27e4d7

Browse files
authored
Merge pull request #22 from nepal143/Recipe_Finder_with_Meal_Planner
Add Ingredient-Based Recipe Search and Weekly Meal Planner Using Spoonacular API
2 parents b6ea04e + 5fad7f8 commit d27e4d7

File tree

6 files changed

+131
-0
lines changed

6 files changed

+131
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Meal Planner with Spoonacular API
2+
3+
## Project Overview
4+
5+
The **Meal Planner** is a command-line application that helps users plan their meals based on available ingredients. By using the [Spoonacular API](https://spoonacular.com/food-api), users can search for recipes, view recipe details, and generate meal plans for the week. It also provides important details like cooking time and servings for each recipe. This tool makes meal planning efficient and fun while minimizing food waste.
6+
7+
## Features
8+
9+
- **Search Recipes by Ingredients**: Input the ingredients you have, and the app will find up to 10 recipes that include those ingredients.
10+
- **View Recipe Details**: Get detailed information about the selected recipes, including preparation time and servings.
11+
- **Plan Meals for the Week**: Generate a random meal plan for up to 7 days based on the available recipes.
12+
- **Interactive User Interface**: Provides a simple, interactive command-line interface for easy input and output.
13+
14+
## Technologies Used
15+
16+
- **Python**: Core programming language used to build the app.
17+
- **Spoonacular API**: API used for fetching recipes and detailed information about them.
18+
- **Requests**: Python library for making HTTP requests to the Spoonacular API.
19+
20+
## Prerequisites
21+
22+
Before running the application, ensure you have the following:
23+
24+
- [Python 3.x](https://www.python.org/downloads/) installed on your system.
25+
- `requests` library installed. You can install it using:
26+
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import requests
2+
import random
3+
4+
# Replace 'your_api_key_here' with your actual Spoonacular API key
5+
API_KEY = "74de4b7826b74b70b4d3a0fe3191239a"
6+
BASE_URL = "https://api.spoonacular.com/recipes"
7+
8+
def find_recipes(ingredients):
9+
"""Search for recipes based on ingredients using the Spoonacular API."""
10+
url = f"{BASE_URL}/findByIngredients"
11+
params = {
12+
'ingredients': ','.join(ingredients),
13+
'number': 10, # Get up to 10 recipes
14+
'apiKey': API_KEY
15+
}
16+
response = requests.get(url, params=params)
17+
18+
if response.status_code == 200:
19+
recipes = response.json()
20+
return [(recipe['title'], recipe['id']) for recipe in recipes]
21+
else:
22+
print(f"Error: {response.status_code}")
23+
return []
24+
25+
def get_recipe_details(recipe_id):
26+
"""Get details of a specific recipe by its ID."""
27+
url = f"{BASE_URL}/{recipe_id}/information"
28+
params = {'apiKey': API_KEY}
29+
response = requests.get(url, params=params)
30+
31+
if response.status_code == 200:
32+
return response.json()
33+
else:
34+
print(f"Error: {response.status_code}")
35+
return None
36+
37+
def plan_meals(ingredients):
38+
"""Plan meals for the week based on available ingredients."""
39+
recipes = find_recipes(ingredients)
40+
41+
if not recipes:
42+
return "No recipes found with the given ingredients."
43+
44+
meals = random.sample(recipes, min(7, len(recipes)))
45+
return meals
46+
47+
def user_interface():
48+
print("Welcome to the Meal Planner!")
49+
print("Enter the ingredients you have, separated by commas:")
50+
51+
ingredients = input().split(",")
52+
ingredients = [ingredient.strip().lower() for ingredient in ingredients]
53+
54+
print("\nSearching for recipes based on your ingredients...\n")
55+
recipes = find_recipes(ingredients)
56+
57+
if recipes:
58+
print(f"Found the following recipes with your ingredients:")
59+
for i, (title, _) in enumerate(recipes):
60+
print(f"{i + 1}. {title}")
61+
else:
62+
print("No recipes found with the given ingredients.")
63+
64+
print("\nDo you want to plan meals for the week with these ingredients? (yes/no)")
65+
if input().strip().lower() == "yes":
66+
meals = plan_meals(ingredients)
67+
print("\nHere is your meal plan for the week:")
68+
for i, (title, recipe_id) in enumerate(meals, 1):
69+
print(f"Day {i}: {title}")
70+
recipe_details = get_recipe_details(recipe_id)
71+
if recipe_details:
72+
print(f" - Ready in: {recipe_details['readyInMinutes']} minutes")
73+
print(f" - Servings: {recipe_details['servings']}")
74+
else:
75+
print("No meal plan generated.")
76+
77+
if __name__ == "__main__":
78+
user_interface()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
python-3.9.18

Youtube Video Downloader/main.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import yt_dlp
2+
3+
def download_video(url, resolution='highest'):
4+
try:
5+
# Set yt-dlp options for video download
6+
ydl_opts = {
7+
'format': f'bestvideo[height<={resolution}]+bestaudio/best[height<={resolution}]' if resolution != 'highest' else 'best',
8+
'outtmpl': '%(title)s.%(ext)s', # Output file name template
9+
}
10+
11+
# Download video with yt-dlp
12+
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
13+
ydl.download([url])
14+
print("Download completed!")
15+
except Exception as e:
16+
print(f"Error: {e}")
17+
18+
if __name__ == "__main__":
19+
video_url = input("Enter YouTube URL: ")
20+
video_resolution = input("Enter resolution (e.g., 720p or leave blank for highest): ").strip()
21+
22+
# Download the video with specified resolution
23+
download_video(video_url, video_resolution or 'highest')
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
yt-dlp
2+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
python-3.10.12

0 commit comments

Comments
 (0)