-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmealprep.py
More file actions
78 lines (65 loc) · 2.08 KB
/
mealprep.py
File metadata and controls
78 lines (65 loc) · 2.08 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
from collections import defaultdict
from pathlib import Path
from datetime import datetime
# -------- CONFIG --------
MEAL_PLAN = {
"Monday - Pasta": {
"pasta (g)": 200,
"tomato sauce (ml)": 150,
"olive oil (tbsp)": 1,
"garlic (cloves)": 2
},
"Tuesday - Omelette": {
"eggs": 3,
"cheese (g)": 50,
"milk (ml)": 30
},
"Wednesday - Salad": {
"lettuce (head)": 1,
"tomato": 2,
"olive oil (tbsp)": 1
}
}
PANTRY = {
"pasta (g)": 100,
"olive oil (tbsp)": 3,
"eggs": 2,
"milk (ml)": 200
}
OUTPUT_FILE = Path("grocery_list.txt")
# ------------------------
def calculate_needed_ingredients(meal_plan):
total_needed = defaultdict(int)
for meal, ingredients in meal_plan.items():
for ingredient, amount in ingredients.items():
total_needed[ingredient] += amount
return total_needed
def generate_grocery_list(total_needed, pantry):
grocery_list = {}
for ingredient, needed_qty in total_needed.items():
pantry_qty = pantry.get(ingredient, 0)
if pantry_qty < needed_qty:
grocery_list[ingredient] = needed_qty - pantry_qty
return grocery_list
def save_grocery_list(grocery_list):
date = datetime.now().strftime("%Y-%m-%d")
with open(OUTPUT_FILE, "w", encoding="utf-8") as file:
file.write(f"Grocery List - {date}\n")
file.write("-" * 30 + "\n")
for item, qty in grocery_list.items():
file.write(f"- {item}: {qty}\n")
def main():
print("\n🛒 Grocery List Generator\n" + "-" * 30)
total_needed = calculate_needed_ingredients(MEAL_PLAN)
grocery_list = generate_grocery_list(total_needed, PANTRY)
if grocery_list:
print("\nItems to buy:")
for item, qty in grocery_list.items():
print(f" - {item}: {qty}")
save_grocery_list(grocery_list)
print(f"\n📂 Saved to {OUTPUT_FILE.resolve()}")
else:
print("\n✅ Your pantry is fully stocked!")
if __name__ == "__main__":
main()
journal_entry = input("\n🖊️ Your Entry:\n")