-
Notifications
You must be signed in to change notification settings - Fork 1
/
display_recipes.py
73 lines (61 loc) · 2.43 KB
/
display_recipes.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
import script
import helper
def merge_ingredient(ingredient):
return ingredient['quantity']+ ingredient['measurement']+ ingredient['ingredient_name']+ingredient['preparation']
def display(search_url):
rf = script.RecipeFetcher()
# meat_lasagna = rf.search_recipes(search_term)[0]
result = rf.scrape_recipe(search_url)
ings = result['ingredients']
ingredients = []
for ingredient in ings:
ingredients.append(helper.tokenize_ingredient(ingredient))
ingredient_names = []
for ingredient in ingredients:
ingredient_names.append(ingredient['ingredient_name'])
directions = result['directions']
tools, methods, steps = helper.get_steps(directions, ingredient_names)
print('-------Ingredients-----')
for ingredient in ingredients:
print(merge_ingredient(ingredient).rstrip(','))
print('..........')
print('name:', ingredient['ingredient_name'].rstrip(','))
print('quantity:', ingredient['quantity'])
print('measurement:', ingredient['measurement'])
print('preparation:', ingredient['preparation'])
print()
print('\n-------Tools-----')
for tool in tools:
print(tool)
print('\n-------Methods-----')
for method in methods:
print(method)
print('\n-------Steps------')
cnt = 1
for step in steps:
print("step", cnt)
print(step[0].strip())
print('..........')
if len(step[1]['ingredient']) != 0:
print('ingredients: ', end = '')
for ing in step[1]['ingredient'][:-1]:
print(ing.strip(), end = ', ')
print(step[1]['ingredient'][-1])
if len(step[1]['cooking tools']) != 0:
print('cooking tools: ', end = '')
for ing in step[1]['cooking tools'][:-1]:
print(ing.strip(), end = ', ')
print(step[1]['cooking tools'][-1])
if len(step[1]['cooking methods']) != 0:
print('cooking methods: ', end = '')
for ing in step[1]['cooking methods'][:-1]:
print(ing.strip(), end = ', ')
print(step[1]['cooking methods'][-1])
if len(step[1]['time']) != 0:
print('cooking time: ', end = '')
for ing in step[1]['time'][:-1]:
print(ing.strip(), end = ', ')
print(step[1]['time'][-1])
print()
cnt+=1
return ingredients, tools, methods, steps