예제 #1
0
class ControlFood:
    def __init__(self):
        self.food = Food()

    def check_food(self):
        return self.food.generate_food()

    def set_devoured(self, view):
        self.food.devour()

    def draw(self, view):
        pygame.draw.rect(
            view, pygame.Color(204, 51, 0),
            pygame.Rect(self.food.position[0], self.food.position[1], 10, 10))
예제 #2
0
def createFood():

    data = request.get_json()

    new_food = Food(food=data['name'])
    db.session.add(new_food)
    db.session.commit()
    return jsonify({'message': 'New food added!'})
예제 #3
0
def updateFood(id):

    data = request.get_json()

    new_food = Food(food=data['name'])

    food = Food.query.filter_by(id=id).first()

    food.food = new_food.food
    db.session.commit()
    return jsonify({'message': 'updated!'})
예제 #4
0
    def execute(self, choice):
        if choice == 1:
            print("-----------Add Food-------------")
            foodName = input("Enter the Name: ")
            foodType = input("Enter the Food Type: ")
            foodCategory = input("Enter the Food Category")
            foodDescription = input("Enter the Description")
            foodPrice = float(input("Enter the Food Price"))
            food = Food(foodName, foodType, foodCategory, foodDescription,
                        foodPrice)
            test.view.addFood(food)

        elif choice == 2:
            print("--------update food----------------")
            foodId = int(
                input("ENter the existing foodID ehich you want to update "))
            foodName = input("Enter the Name: ")
            foodType = input("Enter the Food Type: ")
            foodCategory = input("Enter the Food Category")
            foodDescription = input("Enter the Description")
            foodPrice = float(input("Enter the Food Price"))
            food = Food(foodName, foodType, foodCategory, foodDescription,
                        foodPrice)
            food.setFoodId(foodId)
            test.view.updateFood(food)

        elif choice == 3:
            print('---------------delete food---------------')
            foodId = int(input("Enter the existing foodId you want to delete"))
            test.view.deleteFood(foodId)

        elif choice == 4:
            print("----------search food------------")
            foodId = int(input("Enter the existing foodid you want to search"))
            food = test.view.searchFood(foodId)
            print(food)

        elif choice == 5:
            print("----------search food by name------------")
            foodName = input("Enter the foodname you want to search")
            foodlist = test.view.searchbyName(foodName)
            for food in foodlist:
                print(food)

        elif choice == 6:
            print("------------show menu---------------- ")
            foodlist = test.view.getAllData()
            for food in foodlist:
                print(food)

        elif choice == 7:
            print("thank you")
            error  # Exception to handle exit of while loop

        else:
            print("please enter a valid choice")
    def searchFood(self, foodId):
        try:
            sql = "select * from food where foodId=%d"
            i = c.execute(sql % (foodId))
            data = c.fetchone()
            food = Food(data[1], data[2], data[3], data[4], data[5])

            database.commit()
            if i == 0:
                print("food Id doesn't exist")
            else:
                print("data search", i, "rows added")
        except Exception as ex:
            print(ex)
        return food
 def getAllData(self):
     foodlist = []
     try:
         sql = "select * from food"
         i = c.execute(sql)
         data = c.fetchall()
         for result in data:
             food = Food(result[1], result[2], result[3], result[4],
                         result[5])
             foodlist.append(food)
         database.commit()
         if i == 0:
             print("menu data doesn't exist")
         else:
             pass
     except Exception as ex:
         print(ex)
     return foodlist
 def searchbyName(self, foodName):
     foodlist = []
     try:
         sql = 'select * from food where foodName like "%' "{}" '%"'.format(
             foodName)
         i = c.execute(sql)
         data = c.fetchall()
         for result in data:
             food = Food(result[1], result[2], result[3], result[4],
                         result[5])
             foodlist.append(food)
         database.commit()
         if i == 0:
             print("Food doesn't exist")
         else:
             print("data search", i, "rows added")
     except Exception as ex:
         print(ex)
     return foodlist
예제 #8
0
 def __init__(self):
     self.food = Food()