예제 #1
0
def removePreferences():

	input = request.json
	userID = input['userID']
	preferences = input['preferences']
	print("################")
	print("User " + str(userID) + " removed " + str(preferences) + " to his preferences\n")
	print("################")
	
	try:
		user = user_profil.User_Profil(userID)
	except:
		tmp = {}
		tmp["status"] = "User not found"
		res = jsonify(tmp)
		return str(res.json)
		
	res = user.remove_preferences(preferences)
	
	for preference in user.get_preferences() :
		print("_________ "+str(preference))

	tmp = {}
	tmp["status"] = "Preferences :  " + str(preferences) +" have been removed from the user's preferences"
	tmp["preferences"] = user.get_preferences()
	tmp["removed"] = res[0]
	tmp["Was not in preferences"] = res[1]
	tmp["Unknown"] = res[2]
	res = jsonify(tmp)
	return str(res.json)
예제 #2
0
def inquireAllergies():

	input = request.json
	userID = input['userID']
	allergies = input['allergies']
	print("################")
	print("User " + str(userID) + " inquire his allergies : " + str(allergies) +"\n")
	print("################")

	try:
		user = user_profil.User_Profil(userID)
	except:
		tmp = {}
		tmp["status"] = "User not found"
		res = jsonify(tmp)
		return str(res.json)

	res = user.add_allergies(allergies)


	for allergie in user.get_allergies() :
		print("_________ "+str(allergie))

	tmp = {}
	tmp["status"] = "Preferences have been added to the user."
	tmp["allergies"] = user.get_allergies()
	tmp["added"] = res[0]
	tmp["already inquired"] = res[1]
	tmp["Unknown"] = res[2]
	res = jsonify(tmp)
	return str(res.json)
예제 #3
0
def removeAllIngredientsFrigo():
	input = request.json
	userID = input['userID']
	print("################")
	print("User " + str(userID) + " cleared his fridge\n")
	print("################")

	try:
		user = user_profil.User_Profil(userID)
	except:
		tmp = {}
		tmp["status"] = "User not found"
		res = jsonify(tmp)
		return str(res.json)

	cleared_fridge = user.clear_fridge()

	for ingredient in user.get_fridge():
		print("_________ " + str(ingredient))

	tmp = {}
	tmp["status"] = "user's fridge has "+ str(len(cleared_fridge)) + " ingredients in his gridge\n"
	tmp["fridge"] = user.get_fridge()
	res = jsonify(tmp)
	return str(res.json)
예제 #4
0
def removeIngredientsFrigo():
	input = request.json
	userID = input['userID']
	ingredients = input['items']   #list of ingredients
	print("################")
	print("User " + str(userID) + " removed " + str(ingredients) + " from his frigo\n")
	print("################")

	try:
		user = user_profil.User_Profil(userID)
	except:
		tmp = {}
		tmp["status"] = "User not found"
		res = jsonify(tmp)
		return str(res.json)

	res = user.remove_ingredients_fridge(ingredients)

	for ingredient in user.get_fridge():
		print("_________ " + str(ingredient))

	tmp = {}
	tmp["status"] = "Ingredient " + str(ingredients) + " have been removed from the user fridge"
	tmp["fridge"] = user.get_fridge()
	tmp["removed"] = res[0]
	tmp["Was not in fridge"] = res[1]
	tmp["Unknown"] = res[2]
	res = jsonify(tmp)
	return str(res.json)
예제 #5
0
def removeAllergies():

	input = request.json
	userID = input['userID']
	allergies = input['allergies']
	print("################")
	print("User " + str(userID) + " removed " + str(allergies) + " to his allergies\n")
	print("################")
	
	try:
		user = user_profil.User_Profil(userID)
	except:
		tmp = {}
		tmp["status"] = "User not found"
		res = jsonify(tmp)
		return str(res.json)

	res = user.remove_allergies(allergies)

	for allergie in user.get_allergies() :
		print("_________ "+str(allergie))

	tmp = {}
	tmp["status"] = "Ingredient " + str(allergies) +" have been removed from the user allergies"
	tmp["allergies"] = user.get_allergies()
	tmp["removed"] = res[0]
	tmp["Was not in allergies"] = res[1]
	tmp["Unknown"] = res[2]
	res = jsonify(tmp)
	return str(res.json)
 def setUp(self):
     self.user_profil_under_test = user_profil.User_Profil(675719)
     self.user_profil_under_test.set_db_test()  # set test database for this test case
     self.preferences_to_add = ['coconut', 'artichoke']
     self.allergies_to_add = ['lemon', 'macaroni']
     self.allergies_to_remove_not_found = ['spice', 'tart', 'sugar']
     self.preferences_to_remove_not_found = ['wasabi', 'wheat', 'gluten']
     self.user_fridge_depart = ['milk','apple']
     self.ingredients_to_add_fridge = ['coconut', 'onion']
     self.existant_ingredients_to_remove_fridge = self.ingredients_to_add_fridge
     self.remaining_ingredients_fridge = ['onion']
     self.inexistant_ingredients_to_remove_fridge = ['parmesan', 'coconut']
     self.not_found_ingredients = [['coconut'],['parmesan'],[]]
예제 #7
0
def getUserFridge(id):

	print("################")
	print("Get user " + str(id) + " fridge\n")
	print("################")
	res = {}
	try:
		user = user_profil.User_Profil(id)
		res["fridge"] = user.get_fridge()
		return jsonify(res)
	except:
		res["fridge"] = []
		return jsonify(res)
예제 #8
0
def get_user_profil(id):

    complete_profil = [[], [], [], [], []]

    # get User
    try:
        user = user_profil.User_Profil(id)
        complete_profil[4] = 0  # 0 success code

        #if user.get_user_id() == None :
        #return []

        # get preferences, allergies and fridge
        preferences = user.get_preferences()
        allergies = user.get_allergies()
        fridge = user.get_fridge()
        history = user.get_history()

        # create complete profil
        '''complete_profil.append(preferences)
        complete_profil.append(allergies)
        complete_profil.append(fridge)
        complete_profil.append(history)'''
        #break
        complete_profil[0] = preferences
        complete_profil[1] = allergies
        complete_profil[2] = fridge
        complete_profil[3] = history

    except ValueError as exception:
        complete_profil[4] = -1  # -1 failure code
        print(exception)

    #l = len(complete_profil[0]) + len(complete_profil[1]) + len(complete_profil[2]) + len((complete_profil[3]))
    #print(l)
    #print(complete_profil)
    return complete_profil