def get_recipe(self, rname): ingredients = [] chef = [] try: connection = cx_Oracle.connect( self.__username, self.__password, cx_Oracle.makedsn('oracle.wpi.edu', 1521, 'ORCL')) except cx_Oracle.DatabaseError as exception: self.printf('Failed to connect to %s\n', self.__database) else: #print('-------Connected to Oracle successfully--------') cur = connection.cursor() #Customer chooses Vegan cur.execute("SELECT * FROM Recipe R WHERE R.RNAME = '" + rname + "'") recipe = cur.fetchall()[0] cur.execute("SELECT * FROM MakesUp M WHERE M.RID IN \ (SELECT R.RID FROM Recipe R WHERE R.RNAME = '" + rname + "')") for result in cur.fetchall(): ingredients.append(result) cur.execute(query_factory.get_chef_info()) chef = cur.fetchall() cur.close() connection.close() #print("-------Connection closed-------") r_out = dao_recipe.build_recipe(recipe, ingredients, chef) return r_out
def get_recipes(self, choice=0): recipes = [] ingredients = [] chef = [] try: connection = cx_Oracle.connect( self.__username, self.__password, cx_Oracle.makedsn('oracle.wpi.edu', 1521, 'ORCL')) except cx_Oracle.DatabaseError as exception: self.printf('Failed to connect to %s\n', self.__database) else: #print('-------Connected to Oracle successfully--------') cur = connection.cursor() #Customer chooses Vegan if choice == 1: cur.execute(query_factory.get_vegan_recipes()) for result in cur: recipes.append(result) cur.execute(query_factory.get_vegan_ingredients()) for result in cur: ingredients.append(result) #Customer chooses Vegetarian elif choice == 2: cur.execute(query_factory.get_vegetarian_recipes()) for result in cur: recipes.append(result) cur.execute(query_factory.get_vegetarian_ingredients()) for result in cur: ingredients.append(result) #Customer chooses Paleo elif choice == 3: cur.execute(query_factory.get_paleo_recipes()) for result in cur: recipes.append(result) cur.execute(query_factory.get_paleo_ingredients()) for result in cur: ingredients.append(result) #Customer chooses Keto #No data, implements later #Return the entire list of recipes elif choice == 0: cur.execute(query_factory.get_recipes()) for result in cur: recipes.append(result) cur.execute(query_factory.get_ingredients_in_recipe()) for result in cur: ingredients.append(result) cur.close() connection.close() #print("-------Connection closed-------") recipes = dao_recipe.add_to_recipes(recipes, ingredients) return recipes
def get_ingredients(self): ingredients = [] try: connection = cx_Oracle.connect('cwang9', 'CWANG9', cx_Oracle.makedsn('oracle.wpi.edu', 1521, 'ORCL')); except: print('Error: Could not connect to database') else: print('Connected to Oracle successfully') cur = connection.cursor() cur.execute(query_factory.get_ingredients()) for result in cur: ingredients.append(result) cur.close() connection.close() print("done") return ingredients
def get_ingredients(self): ingredients = [] try: connection = cx_Oracle.connect( self.__username, self.__password, cx_Oracle.makedsn('oracle.wpi.edu', 1521, 'ORCL')) except: print('Error: Could not connect to database') else: print('Connected to Oracle successfully') cur = connection.cursor() cur.execute(query_factory.get_ingredients()) ingredients = cur.fetchall() cur.close() connection.close() print("done") return ingredients
def select_exclude(self, choice, ingred): exclude = [] ingredient = [] chef = [] try: connection = cx_Oracle.connect( self.__username, self.__password, cx_Oracle.makedsn('oracle.wpi.edu', 1521, 'ORCL')) except: print('Error: Could not connect to database') else: print('Connected to Oracle successfully') cur = connection.cursor() if choice == 1: cur.execute(limitchoice.exclude_ingredient_vegan(ingred)) exclude = cur.fetchall() cur.execute(limitchoice.ingredient_exclude_vegan(ingred)) ingredient = cur.fetchall() cur.execute(query_factory.get_chef_info()) chef = cur.fetchall() #return exclude elif choice == 2: cur.execute(limitchoice.exclude_ingredient_vegetarian(ingred)) exclude = cur.fetchall() cur.execute(limitchoice.ingredient_exclude_vegetarian(ingred)) ingredient = cur.fetchall() cur.execute(query_factory.get_chef_info()) chef = cur.fetchall() #return exclude elif choice == 3: cur.execute(limitchoice.exclude_ingredient_paleo(ingred)) exclude = cur.fetchall() cur.execute(limitchoice.ingredient_exclude_paleo(ingred)) ingredient = cur.fetchall() cur.execute(query_factory.get_chef_info()) chef = cur.fetchall() elif choice == 4: cur.execute(limitchoice.exclude_ingredient_keto(ingred)) exclude = cur.fetchall() cur.execute(limitchoice.ingredient_exclude_keto(ingred)) ingredient = cur.fetchall() cur.execute(query_factory.get_chef_info()) chef = cur.fetchall() elif choice == 0: cur.execute(limitchoice.exclude_ingredient_all(ingred)) for result in cur: exclude.append(result) cur.execute(limitchoice.ingredient_exclulde_all(ingred)) for result in cur: ingredient.append(result) cur.execute(query_factory.get_chef_info()) chef = cur.fetchall() cur.close() connection.close() exclude = dao_recipe.add_to_recipes(exclude, ingredient, chef) return exclude