forked from richchang0/337RecipeTransform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
recipe_methods.py
38 lines (28 loc) · 1.03 KB
/
recipe_methods.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
import database, recipe_parser
def getMethods(recipe_url):
all_methods, all_tools = database.get_tools_and_methods()
# feed in the url of the recipe
content = recipe_parser.http_string(recipe_url)
methods = []
# tools = []
#send it to directions to get the recipe's directions section
recipDirections = recipe_parser.directions_steps(content)
# to print each instruction
for direction in recipDirections:
# found_tool = search(direction,all_tools)
# if found_tool != None and found_tool not in tool:
# tools.append(found_tool)
found_method = search(direction, all_methods)
if found_method != None and found_method not in method:
methods.append(found_method)
return methods#, tools
def search(direction, tools_or_methods):
for token in direction.split():
token = dePunc(direction.lower())
if token in tools_or_methods:
return token
def dePunc(rawword):
""" remove punctuation in the input string """
L = [ c for c in rawword if 'A' <= c <= 'Z' or 'a' <= c <= 'z' ]
word = ''.join(L)
return word