-
Notifications
You must be signed in to change notification settings - Fork 0
/
recipe_runner.py
115 lines (103 loc) · 2.48 KB
/
recipe_runner.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
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import pprint as pp
import ast
lowest_score_recipes = {}
recipes = {
'Baked Stuffed Fish with Turmeric Rice': {
'source': 'Piquant Post',
'serves': 4,
'prep_time_min': 20,
'cook_time_min': 30,
'total_time_min': 50,
'ingredients': {
'yellow onion': {
'amount': .5,
'unit': 'whole'
}
,'raw walnuts': {
'amount': 1,
'unit': 'cup'
}
,'fresh pomegranate seeds': {
'amount': .66,
'unit': 'cup'
}
},
'temp_recipe_score': 0
},
'Ice Cream Sundae': {
'source': 'Homemade',
'serves': 1,
'prep_time_min': 2,
'cook_time_min': 0,
'total_time_min': 2,
'ingredients': {
'vanilla ice cream': {
'amount': 3,
'unit': 'scoop'
}
,'chocolate syrup': {
'amount': 8,
'unit': 'ounce'
}
},
'temp_recipe_score': 0
},
'PB&J': {
'source': 'Homemade',
'serves': 1,
'prep_time_min': 2,
'cook_time_min': 0,
'total_time_min': 2,
'ingredients': {
'bread': {
'amount': 2,
'unit': 'slice'
}
,'jelly': {
'amount': 4,
'unit': 'ounce'
}
,'peanut butter': {
'amount': 4,
'unit': 'ounce'
}
},
'temp_recipe_score': 0
}
}
ingredients_owned = {'vanilla ice cream': {
'amount': 3,
'unit': 'scoop'
}
,'jelly': {
'amount': 8,
'unit': 'ounce'
}
,'bread': {
'amount': 12,
'unit': 'slice'
}
}
ingredients_needed = {}
for rec in recipes:
print(rec)
for rec_ing in recipes[rec]['ingredients']:
if rec_ing not in ingredients_owned.keys():
recipes[rec]['temp_recipe_score'] += 1
elif ingredients_owned[rec_ing]['amount'] < recipes[rec]['ingredients'][rec_ing]['amount']:
recipes[rec]['temp_recipe_score'] += 1
else:
pass
if lowest_score_recipes == {}:
lowest_score_recipes['%i' % recipes[rec]['temp_recipe_score']] = [rec]
print(type(lowest_score_recipes['%i' % recipes[rec]['temp_recipe_score']]))
elif int(list(lowest_score_recipes.keys())[0]) == recipes[rec]['temp_recipe_score']:
lowest_score_recipes[int('%i' % (recipes[rec]['temp_recipe_score']))].append(recipes[rec]['temp_recipe_score'])
elif int(list(lowest_score_recipes.keys())[0]) > recipes[rec]['temp_recipe_score']:
lowest_score_recipes = ast.literal_eval(("{%i : '%s'}" % (recipes[rec]['temp_recipe_score'],rec)))
### ONE HOUR SPENT ON THE BELOW ALTERNATIVE... ###
# lowest_score_recipes = ast.literal_eval(("{'{0}'':''{1}'}").format(recipes[rec]['temp_recipe_score'],rec))
else:
pass
pp.pp(recipes)
pp.pp(lowest_score_recipes)