-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
99 lines (77 loc) · 2.52 KB
/
Copy pathmain.py
File metadata and controls
99 lines (77 loc) · 2.52 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
"""
Recipe Finder with Meal Planner
Finds recipes using TheMealDB API
"""
import requests
import random
def search_recipe(query):
"""Search for recipes"""
try:
url = f"https://www.themealdb.com/api/json/v1/1/search.php?s={query}"
response = requests.get(url, timeout=10)
data = response.json()
if data['meals']:
return data['meals']
return None
except Exception as e:
print(f"Error: {e}")
return None
def get_random_recipe():
"""Get random recipe"""
try:
url = "https://www.themealdb.com/api/json/v1/1/random.php"
response = requests.get(url, timeout=10)
data = response.json()
if data['meals']:
return data['meals'][0]
return None
except Exception as e:
print(f"Error: {e}")
return None
def display_recipe(recipe):
"""Display recipe details"""
print("\n" + "="*60)
print(" RECIPE")
print("="*60)
print(f"\n🍽️ {recipe['strMeal']}")
print(f"📍 Category: {recipe['strCategory']}")
print(f"🌍 Cuisine: {recipe['strArea']}")
print("\n📝 Instructions:")
print(recipe['strInstructions'][:200] + "...")
print(f"\n🔗 Full recipe: {recipe['strSource'] or 'N/A'}")
print("="*60 + "\n")
def main():
"""Main function"""
print("\n" + "="*60)
print(" RECIPE FINDER")
print("="*60 + "\n")
try:
while True:
print("Options:")
print(" 1. Search recipe")
print(" 2. Get random recipe")
print(" 3. Exit")
choice = input("\nChoice: ").strip()
if choice == '1':
query = input("Enter dish name: ").strip()
if query:
print("\nSearching...")
recipes = search_recipe(query)
if recipes:
display_recipe(recipes[0])
else:
print("No recipes found!")
elif choice == '2':
print("\nGetting random recipe...")
recipe = get_random_recipe()
if recipe:
display_recipe(recipe)
elif choice == '3':
print("\nGoodbye!")
break
else:
print("\nInvalid choice!")
except KeyboardInterrupt:
print("\n\nGoodbye!")
if __name__ == "__main__":
main()