-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
164 lines (142 loc) · 7.66 KB
/
main.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
import parser
import transfrom
import json
import keyWords
from nltk.stem.wordnet import WordNetLemmatizer
import utils
import sys
import keyWords
if __name__ == '__main__':
# url = raw_input("Please enter a URL from allrecipes.com")
# url = "https://www.allrecipes.com/recipe/232458/pork-chops-with-creamy-scalloped-potatoes/"
#
#
# resPath = "./output/parserOutput.json"
# test = parser.parser(url,resPath)
# test.parserIngredient()
# test.parserDirection()
# utils.writeDict(utils.recipeAddNumber(test.res),resPath)
#
# newRecipePath = "./output/newRecipeOutput.json"
# transfromtest = transfrom.transform(test.res)
# # transfromtest.toVegetarian()
# # transfromtest.fromVegetarian()
# # transfromtest.toHealthy()
# # transfromtest.fromHealthy()
# # transfromtest.toMexican()
# # transfromtest.subMethods({"bake":"boil"})
# transfromtest.toIndian()
# utils.writeDict(utils.recipeAddNumber(transfromtest.newrecipe), newRecipePath)
# #transfromtest.subMethods()
#
# exit()
resPath = "./output/parserOutput.json"
newRecipePath = "./output/newRecipeOutput.json"
url = None
transfromtest = None
print ("welcome recipe parser and transformer")
while True:
select = input("press 0: exit this process\npress 1: enter an URL to parse a recipe\n\
press 2: do transformation\npress 3: show old recipe(you can also find the old recipe in ./output/parserOutput.json)\npress 4: show new recipe(to see the complete new recipe of last transformation)(you can also find the new recipe in ./output/newRecipeOutput.json)\n")
if select == '1':
url = str(input("please enter an URL from allrecipe\n\
(default:https://www.allrecipes.com/recipe/232458/pork-chops-with-creamy-scalloped-potatoes/)\n"))
if len(url.strip()) == 0:
url = 'https://www.allrecipes.com/recipe/232458/pork-chops-with-creamy-scalloped-potatoes/'
test = parser.parser(url, resPath)
test.parserIngredient()
test.parserDirection()
utils.printDict(utils.recipeAddNumber(test.res))
utils.writeDict(utils.recipeAddNumber(test.res), resPath)
utils.printRecipeNL(test.res)
elif select == '2':
if url == None:
print ("you need to press 1 to enter an URL to parser an recipe first")
continue
transfromtest = transfrom.transform(test.res)
tran = input("press 0: exit this process\n\
press 1: change recipe to Vegetarian\n\
press 2: change recipe to Non-Vegetarian\n\
press 3: change recipe to Healthy recipe\n\
press 4: change recipe to Non-healthy recipe\n\
press 5: change recipe to Mexican recipe\n\
press 6: change recipe to Indian recipe\n\
press 7: change recipe to easir(DIY)\n\
press 8: change cooking methods\n" \
)
if tran == '0':
break
elif tran == '1':
transfromtest.toVegetarian()
# utils.printDict(utils.recipeAddNumber(transfromtest.newrecipe))
utils.writeDict(utils.recipeAddNumber(transfromtest.newrecipe), newRecipePath)
print ("REMINDER\nWe show the transformation operation above, if you want to see complete new recipe of this transformation, press 4\n")
elif tran == '2':
transfromtest.fromVegetarian()
# utils.printDict(utils.recipeAddNumber(transfromtest.newrecipe))
utils.writeDict(utils.recipeAddNumber(transfromtest.newrecipe), newRecipePath)
print ("REMINDER\nWe show the transformation operation above, if you want to see complete new recipe of this transformation, press 4\n")
elif tran == '3':
transfromtest.toHealthy()
# utils.printDict(utils.recipeAddNumber(transfromtest.newrecipe))
utils.writeDict(utils.recipeAddNumber(transfromtest.newrecipe), newRecipePath)
print ("REMINDER\nWe show the transformation operation above, if you want to see complete new recipe of this transformation, press 4\n")
elif tran == '4':
transfromtest.fromHealthy()
# utils.printDict(utils.recipeAddNumber(transfromtest.newrecipe))
utils.writeDict(utils.recipeAddNumber(transfromtest.newrecipe), newRecipePath)
print ("REMINDER\nWe show the transformation operation above, if you want to see complete new recipe of this transformation, press 4\n")
elif tran == '5':
transfromtest.toMexican()
# utils.printDict(utils.recipeAddNumber(transfromtest.newrecipe))
utils.writeDict(utils.recipeAddNumber(transfromtest.newrecipe), newRecipePath)
print ("REMINDER\nWe show the transformation operation above, if you want to see complete new recipe of this transformation, press 4\n")
elif tran == '6':
transfromtest.toIndian()
# utils.printDict(utils.recipeAddNumber(transfromtest.newrecipe))
utils.writeDict(utils.recipeAddNumber(transfromtest.newrecipe), newRecipePath)
print ("REMINDER\nWe show the transformation operation above, if you want to see complete new recipe of this transformation, press 4\n")
elif tran == '7':
transfromtest.DIY()
# utils.printDict(utils.recipeAddNumber(transfromtest.newrecipe))
utils.writeDict(utils.recipeAddNumber(transfromtest.newrecipe), newRecipePath)
print ("REMINDER\nWe show the transformation operation above, if you want to see complete new recipe of this transformation, press 4\n")
elif tran == '8':
print ("optional old methods that you want to subtititue")
i = 1
for pm in test.res["Methods"]["Primary cooking method"]:
print (str(i) + ":" + pm)
i += 1
orig = int(input("enter sequence of your option of oldMethod\n"))
if orig > len(test.res["Methods"]["Primary cooking method"]):
print ("ilegal input")
print ("optional new methods that you want to use")
i = 1
for pm in keyWords.primaryMethodsList:
print (str(i) + ":" + pm)
i += 1
new = int(input("enter your option of oldMethod\n"))
if new > len(keyWords.primaryMethodsList):
print ("ilegal input")
d = {test.res["Methods"]["Primary cooking method"][orig-1]:keyWords.primaryMethodsList[new-1]}
transfromtest.subMethods(d)
# utils.printDict(utils.recipeAddNumber(transfromtest.newrecipe))
utils.writeDict(utils.recipeAddNumber(transfromtest.newrecipe), newRecipePath)
print ("REMINDER\nWe show the transformation operation above, if you want to see complete new recipe of this transformation, press 4\n")
else:
print ("ilegal input")
elif select == '3':
if url == None:
print ("you need to press 1 to enter an URL to parser an recipe first")
continue
utils.printDict(utils.recipeAddNumber(test.res))
elif select == '4':
if transfromtest == None:
print ("you have not done any transformation before")
continue
utils.printDict(utils.recipeAddNumber(transfromtest.newrecipe))
utils.printDict(utils.recipeAddNumber(transfromtest.newrecipe))
elif select == '0':
break
else:
print ("ilegal input")