Exemple #1
0
def test():
	# Create fake testing db
	a = api.database_api.DatabaseApi('test')
	fridge = api.fridge_api.FridgeApi(a)

	fake_data.reset_db(a)

	all_ingredients = a.get_all_ingredients()  	
	all_recipes = a.get_all_recipes()
	fridge_ingredients = a.get_current_ingredients('fridgi')

	raw_input("Lookup Ingredient Database?")

	print '\nINGREDIENT DATABASE\n'
	for i in all_ingredients:
		print_ingredient(i)
	print '\n'

	raw_input("Lookup Fridge?")

	print '\nFRIDGE\n'
	for i in fridge_ingredients:
		print_f_ingredient(i)
	print '\n'

	recipe = raw_input("Enter Recipe: ")

	print_can_cook(fridge.can_cook(recipe, 'fridgi'))

	i = 0
	while i < 3:
		upc = long(raw_input("Enter UPC: "))
		print upc
		ingr = a.get_ingredient_info_from_upc(upc)
		if ingr is not None:
			a.insert_ingredient(ingr['name'], 'fridgi')
			print 'Inserted ' + ingr['name']
		i += 1

	f_ingredients = a.get_current_ingredients('fridgi')
	raw_input("Lookup Fridge again?")
	print '\nFRIDGE\n'
	for i in f_ingredients:
		print_f_ingredient(i)
	print '\n'

	recipe = raw_input("Enter Recipe: ")
	print_can_cook(fridge.can_cook(recipe, 'fridgi'))
	raw_input('Want the recipe?')
	print '\nRECIPE\n'
	print_recipe(all_recipes[0])


	return
Exemple #2
0
def test4():
	# Create fake testing db
	a = api.database_api.DatabaseApi('test')
	fridge = api.fridge_api.FridgeApi(a)
	fake_data.reset_db(a)

	all_ingredients = a.get_all_ingredients()  	
	all_recipes = a.get_all_recipes()
	fridge_ingredients = a.get_current_ingredients('fridgi')

	recent_recipes = a.get_recent_recipes('fridgi')
	for recipe in recent_recipes:
		print(recipe['name'])
Exemple #3
0
def test5():
	# Create fake testing db
	a = api.database_api.DatabaseApi('test')
	fridge = api.fridge_api.FridgeApi(a)
	fake_data.reset_db(a)

	all_ingredients = a.get_all_ingredients()  	
	all_recipes = a.get_all_recipes()
	fridge_ingredients = a.get_current_ingredients('fridgi')

	print '\nFRIDGE\n'
	for i in fridge_ingredients:
		print_f_ingredient(i)
	print '\n'

	recipe = raw_input("Enter Recipe: ")

	print_can_cook(fridge.can_cook(recipe, 'fridgi'))
Exemple #4
0
def test2():
	# Create fake testing db
	a = api.database_api.DatabaseApi('test')
	fridge = api.fridge_api.FridgeApi(a)
	fake_data.reset_db(a)

	all_ingredients = a.get_all_ingredients()  	
	all_recipes = a.get_all_recipes()
	fridge_ingredients = a.get_current_ingredients('fridgi')

	tags = raw_input('Search : ')
	recipelist = a.search_recipes(tags)
	for i in recipelist:
		print_recipe(i)

	raw_input("Next : ")

	recipe_id = recipelist[0]['_id']
	new_recipe = fridge.suggest_by_current_recipe(recipe_id, 'fridgi')
	print_recipe(new_recipe)
Exemple #5
0
def test3():

	# Create fake testing db
	a = api.database_api.DatabaseApi('test')
	fridge = api.fridge_api.FridgeApi(a)
	fake_data.reset_db(a)

	all_ingredients = a.get_all_ingredients()  	
	all_recipes = a.get_all_recipes()
	fridge_ingredients = a.get_current_ingredients('fridgi')

	print '\nINGREDIENT DATABASE\n'
	for i in fridge_ingredients:
		print_f_ingredient(i)
	print '\n'

	raw_input("Testing recent recipes : ")
	print fridge.can_cook("chicken penne pasta", 'fridgi')
	pasta = a.get_recipe_info("chicken penne pasta")
	use_chicken = fridge.use_recipe(pasta['_id'], 'fridgi')
	
	print '\nINGREDIENT DATABASE\n'
	fridge_ingredients = a.get_current_ingredients('fridgi')
	for i in fridge_ingredients:
		print_f_ingredient(i)
	print '\n'

	print 'LAST USED'
	recent_recipes = a.get_recent_recipes('fridgi')
	for recipe in recent_recipes:
		print(recipe['name'])

	raw_input('testing duplicates:')
	smoothie = a.get_recipe_info("sweet peach smoothie")
	use_chicken = fridge.use_recipe(smoothie['_id'], 'fridgi')
	use_chicken = fridge.use_recipe(smoothie['_id'], 'fridgi')
	print 'LAST USED'
	recent_recipes = a.get_recent_recipes('fridgi')
	for recipe in recent_recipes:
		print(recipe['name'])
Exemple #6
0
	def get(self):
		fake_data.reset_db(apiObj)
		self.write("Database Reset!")
Exemple #7
0
# FOR TESTING. REMOVE LATER
class ResetListHandler(tornado.web.RequestHandler):
	def get(self):
		fake_data.reset_db(apiObj)
		self.write("Database Reset!")

application = tornado.web.Application([
	(r"/", MainHandler),
    (r"/ingredients", IngredientHandler),
    (r"/recipes", RecipeHandler),
    (r"/fridge/([^/]+)", FridgeHandler),
    (r"/search", SearchRecipeHandler),
    (r"/fridge/([^/]+)/search", SearchFridgeRecipeHandler),
    (r"/fridge/([^/]+)/suggest", SuggestRecipeHandler),
    (r"/fridge/([^/]+)/insert", InsertHandler),
    (r"/fridge/([^/]+)/use", UseRecipeHandler),
    (r"/fridge/([^/]+)/add", AddToGroceryListHandler),
    (r"/fridge/([^/]+)/remove", RemoveFromGroceryListHandler),
    (r"/reset", ResetListHandler),
])

if __name__ == "__main__":
	# Create testing db
	apiObj = api.database_api.DatabaseApi()
	fridgeObj = api.fridge_api.FridgeApi(apiObj)
	fake_data.reset_db(apiObj)
	
	port = int(os.environ.get('PORT', 5000))
	application.listen(port)
	tornado.ioloop.IOLoop.instance().start()
Exemple #8
0
 def get(self):
     fake_data.reset_db(apiObj)
     self.write("Database Reset!")
Exemple #9
0
class ResetListHandler(tornado.web.RequestHandler):
    def get(self):
        fake_data.reset_db(apiObj)
        self.write("Database Reset!")


application = tornado.web.Application([
    (r"/", MainHandler),
    (r"/ingredients", IngredientHandler),
    (r"/recipes", RecipeHandler),
    (r"/fridge/([^/]+)", FridgeHandler),
    (r"/search", SearchRecipeHandler),
    (r"/fridge/([^/]+)/search", SearchFridgeRecipeHandler),
    (r"/fridge/([^/]+)/suggest", SuggestRecipeHandler),
    (r"/fridge/([^/]+)/insert", InsertHandler),
    (r"/fridge/([^/]+)/use", UseRecipeHandler),
    (r"/fridge/([^/]+)/add", AddToGroceryListHandler),
    (r"/fridge/([^/]+)/remove", RemoveFromGroceryListHandler),
    (r"/reset", ResetListHandler),
])

if __name__ == "__main__":
    # Create testing db
    apiObj = api.database_api.DatabaseApi()
    fridgeObj = api.fridge_api.FridgeApi(apiObj)
    fake_data.reset_db(apiObj)

    port = int(os.environ.get('PORT', 5000))
    application.listen(port)
    tornado.ioloop.IOLoop.instance().start()