Example #1
0
    def fromHealthy(self):
        print("transfomation from healthy recipe to non-healthy recipe")
        self.newrecipe = copy.deepcopy(self.oldrecipe)
        newingredientlist = []
        i = 1
        for ing in self.newrecipe["ingredients"]:
            # print (ing)

            flag = True
            if ing["name"] in healtyDict:
                if "butter" in ing["name"] or "sugar" in ing["name"]:
                    halfquantity = 2
                else:
                    halfquantity = None

                need = False
                for dep in healtyDict[ing["name"]]["descriptor"]:
                    if dep not in ing["descriptor"]:
                        need = True
                if need:
                    self.newrecipe[
                        "directions"] = self.updateingredForDirection(
                            self.newrecipe["directions"],
                            healtyDict[ing["name"]]["name"], ing["name"])

                    newTemp = self.updateingredForIngredient(
                        healtyDict[ing["name"]], ing, halfquantity)
                    newingredientlist.append(newTemp)
                    print("sub" + str(i))
                    i += 1
                    print("original ingredient:")
                    utils.printDict(ing)
                    print("new ingredient:")
                    utils.printDict(newTemp)
                    print("\n")
                    flag = False

            if flag and (ing["name"] == "butter" or ing["name"] == "sugar"):
                halfquantity = 2
                newTemp = self.updateingredForIngredient(
                    copy.deepcopy(ing), ing, halfquantity)
                newingredientlist.append(newTemp)
                print("sub" + str(i))
                i += 1
                print("original ingredient:")
                utils.printDict(ing)
                print("new ingredient:")
                utils.printDict(newTemp)
                print("\n")
                flag = False

            if flag:
                newingredientlist.append(ing)
        if i == 1:
            print(
                "can not find anything healthy that can change to something non-healthy"
            )
        else:
            utils.printRecipeNL(self.newrecipe)
        self.newrecipe["ingredients"] = newingredientlist
Example #2
0
    def subMethods(self, subDict):
        self.newrecipe = copy.deepcopy(self.oldrecipe)
        newPrimaryList = []
        i = 1
        for pcm in self.newrecipe["Methods"]["Primary cooking method"]:
            if pcm in subDict:
                newPrimaryList.append(subDict[pcm])
                self.newrecipe["directions"] = self.updateMethodForDirection(
                    self.newrecipe["directions"], subDict[pcm], pcm)

                print("sub:" + str(i))
                print("original method:")
                utils.printDict(pcm)
                print("new method:")
                utils.printDict(subDict[pcm])
                print("\n")

                i += 1

            else:
                newPrimaryList.append(pcm)

        self.newrecipe["Methods"]["Primary cooking method"] = list(
            set(newPrimaryList))

        # print (self.newrecipe)
        # print (json.dumps(self.newrecipe, indent=4))

        if i == 1:
            print("can not find a cooking method that can be replaced")
        else:
            utils.printRecipeNL(self.newrecipe)
Example #3
0
    def toIndian(self):
        print("transfomation to make recipe more indian")
        self.newrecipe = copy.deepcopy(self.oldrecipe)
        newingredientlist = []
        i = 1
        cnt = 0
        for ing in self.newrecipe["ingredients"]:
            # print (ing)

            flag = True
            if ing["name"] in nonIndianDict:
                self.newrecipe["directions"] = self.updateingredForDirection(
                    self.newrecipe["directions"],
                    nonIndianDict[ing["name"]]["name"], ing["name"])

                newTemp = self.updateingredForIngredient(
                    nonIndianDict[ing["name"]], ing, None)
                newingredientlist.append(newTemp)
                print("sub" + str(i))
                i += 1
                print("original ingredient:")
                utils.printDict(ing)
                print("new ingredient:")
                utils.printDict(newTemp)
                print("\n")
                flag = False
            elif ing["measurement"][0] in [
                    "teaspoon", "teaspoons", "taste", "pinch", "dash"
            ] and cnt < len(mexicanSpicyList):
                self.newrecipe["directions"] = self.updateingredForDirection(
                    self.newrecipe["directions"],
                    copy.deepcopy(indianSpciyList[cnt]["name"]), ing["name"])
                newTemp = self.updateingredForIngredient(
                    indianSpciyList[cnt], ing, None)
                newingredientlist.append(newTemp)
                print("sub" + str(i))
                i += 1
                print("original ingredient:")
                utils.printDict(ing)
                print("new ingredient:")
                utils.printDict(newTemp)
                print("\n")
                flag = False
                cnt = cnt + 1

            if flag:
                newingredientlist.append(ing)

        if i == 1:
            print("can not find anything that can make recipe more indian")
        else:
            utils.printRecipeNL(self.newrecipe)

        self.newrecipe["ingredients"] = newingredientlist
Example #4
0
    def fromVegetarian(self):
        print("transfomation from non-healthy recipe to healthy recipe")
        self.newrecipe = copy.deepcopy(self.oldrecipe)
        newingredientlist = []
        cnt = 0
        i = 1
        for ing in self.newrecipe["ingredients"]:
            # print (ing)
            namewords = ing["name"].split()
            flag = True
            for n in namewords:
                if n in nonMeatList and cnt < len(nonMeatSubList):
                    self.newrecipe[
                        "directions"] = self.updateingredForDirection(
                            self.newrecipe["directions"],
                            copy.deepcopy(nonMeatSubList[cnt]["name"]),
                            ing["name"])
                    newTemp = self.updateingredForIngredient(
                        nonMeatSubList[cnt], ing, None)
                    newingredientlist.append(newTemp)
                    print("sub" + str(i))
                    i += 1
                    print("original ingredient:")
                    utils.printDict(ing)
                    print("new ingredient:")
                    utils.printDict(newTemp)
                    print("\n")

                    cnt = cnt + 1
                    flag = False
                    break
            if flag:
                newingredientlist.append(ing)

        self.newrecipe["ingredients"] = newingredientlist
        if i == 1:
            print(
                "can not find anything that can change from Vegetarian to Non-Vegetarian"
            )
        else:
            utils.printRecipeNL(self.newrecipe)
Example #5
0
    def toHealthy(self):
        print("transfomation from non-healthy recipe to healthy recipe")
        self.newrecipe = copy.deepcopy(self.oldrecipe)
        newingredientlist = []
        i = 1
        for ing in self.newrecipe["ingredients"]:
            # print (ing)

            flag = True
            if ing["name"] in nonHealthyDict:
                if "butter" in ing["name"] or "sugar" in ing["name"]:
                    halfquantity = 0.5
                else:
                    halfquantity = None
                self.newrecipe["directions"] = self.updateingredForDirection(
                    self.newrecipe["directions"],
                    nonHealthyDict[ing["name"]]["name"], ing["name"])
                newTemp = self.updateingredForIngredient(
                    nonHealthyDict[ing["name"]], ing, halfquantity)
                newingredientlist.append(newTemp)
                print("sub" + str(i))
                i += 1
                print("original ingredient:")
                utils.printDict(ing)
                print("new ingredient:")
                utils.printDict(newTemp)
                print("\n")
                flag = False

            if flag:
                newingredientlist.append(ing)

        if i == 1:
            print(
                "can not find anything non-healthy that can change to something healthy"
            )
        else:
            utils.printRecipeNL(self.newrecipe)
        self.newrecipe["ingredients"] = newingredientlist
Example #6
0
    def DIY(self):
        print("transfomation to make recipe easier")
        self.newrecipe = copy.deepcopy(self.oldrecipe)
        newingredientlist = []
        i = 1
        cnt = 0
        for ing in self.newrecipe["ingredients"]:
            flag = True
            if ing["measurement"][0] in [
                    "teaspoon", "teaspoons", "taste", "pinch", "dash"
            ]:
                need = True
                for cp in commonSpicesList:
                    if cp in ing["name"]:
                        need = False
                        break
                if need:
                    self.newrecipe[
                        "directions"] = self.removeingredForDirection(
                            self.newrecipe["directions"], ing["name"])
                    print("remove" + str(i))
                    i += 1
                    print("remove ingredient:")
                    utils.printDict(ing)
                    print("\n")
                    flag = False
                    cnt = cnt + 1

            if flag:
                newingredientlist.append(ing)

        if i == 1:
            print("can not find anything that can make recipe easier")
        else:
            utils.printRecipeNL(self.newrecipe)

        self.newrecipe["ingredients"] = newingredientlist
Example #7
0
            "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\
Example #8
0
    def toVegetarian(self):
        print("transfomation from non-healthy recipe to healthy recipe")
        self.newrecipe = copy.deepcopy(self.oldrecipe)
        newingredientlist = []
        cnt = 0
        i = 1
        for ing in self.newrecipe["ingredients"]:
            #print (ing)

            if ing["name"] == "chicken broth" or ing["name"].find(
                    "chicken broth") >= 0 or ing["name"].find(
                        "chicken-broth") >= 0:
                self.newrecipe["directions"] = self.updateingredForDirection(
                    self.newrecipe["directions"],
                    copy.deepcopy(nonChickenBroh.ing["name"]), ing["name"])
                newTemp = self.updateingredForIngredient(
                    copy.deepcopy(nonChickenBroh.ing), ing, None)
                newingredientlist.append(newTemp)

                print("sub" + str(i))
                i += 1
                print("original ingredient:")
                utils.printDict(ing)
                print("new ingredient:")
                utils.printDict(newTemp)
                print("\n")
                flag = False
                continue

            if ing["name"] == "beef broth" or ing["name"].find(
                    "beef broth") >= 0 or ing["name"].find("beef-broth") >= 0:
                self.newrecipe["directions"] = self.updateingredForDirection(
                    self.newrecipe["directions"],
                    copy.deepcopy(nonBeefBroh.ing["name"]), ing["name"])
                newTemp = self.updateingredForIngredient(
                    copy.deepcopy(nonBeefBroh.ing), ing, None)
                newingredientlist.append(newTemp)

                print("sub" + str(i))
                i += 1
                print("original ingredient:")
                utils.printDict(ing)
                print("new ingredient:")
                utils.printDict(newTemp)
                print("\n")
                flag = False
                continue

            namewords = ing["name"].split()
            flag = True
            for n in namewords:

                if n in meatlist and cnt < len(meatsubList):

                    self.newrecipe[
                        "directions"] = self.updateingredForDirection(
                            self.newrecipe["directions"],
                            meatsubList[cnt]["name"], ing["name"])
                    newTemp = self.updateingredForIngredient(
                        meatsubList[cnt], ing, None)
                    newingredientlist.append(newTemp)

                    print("sub" + str(i))
                    i += 1
                    print("original ingredient:")
                    utils.printDict(ing)
                    print("new ingredient:")
                    utils.printDict(newTemp)
                    print("\n")

                    cnt = cnt + 1
                    flag = False
                    break
            if flag:
                newingredientlist.append(ing)

        self.newrecipe["ingredients"] = newingredientlist
        if i == 1:
            print(
                "can not find anything that can change from Non-Vegetarian to Vegetarian"
            )
        else:
            utils.printRecipeNL(self.newrecipe)