def display_comment():
    ##displays all comments on a specified recipe
    print('*' * 120)
    recipe_name = input(
        "Enter name of recipe for which you'd like to view comments ?\n")
    flag = True
    while (flag):
        if (cnc.check_for_Blanks(recipe_name) == False):
            recipe_name = input("Enter the recipe you're looking for! \n")
        else:
            flag = False
    sql = "select recipe_id,recipe,recipe_name from `recipe` where `recipe_name`= %s"
    cnc.c.execute(sql, (recipe_name))
    p = []
    result = cnc.c.fetchall()
    if (cnc.c.rowcount == 0):
        print("Recipe does not exist!!\n")
    else:
        for row in result:
            p.append(row['recipe_id'])
            print("recipe_id \t recipe \t recipe_name \n")
            print(row['recipe_id'], '\t', row['recipe'], '\t',
                  row['recipe_name'], '\n')

        recipe_id = (input(
            "From the list above, which recipe_id is the one you're looking for?\n"
        ))
        flag = True
        while (flag):
            if (cnc.check_for_Blanks(recipe_id) == False):
                recipe_id = (input(
                    "From the list above, which recipe_id is the one you're looking for?\n"
                ))
            else:
                try:
                    recipe_id = int(recipe_id)
                    if (recipe_id in p):
                        flag = False
                    else:
                        print("Choose a valid recipe_id!\n")
                        recipe_id = (input(
                            "From the list above, which recipe_id is the one you want to leave a comment on?\n"
                        ))

                except ValueError:
                    print("Please enter a numeric value\n")
                    recipe_id = (input(
                        "From the list above, which recipe_id is the one you want to leave a comment on?\n"
                    ))

        sql = "select comment from `comments` where `recipe_id`= %s"
        cnc.c.execute(sql, (recipe_id))
        result = cnc.c.fetchall()
        if (cnc.c.rowcount == 0):
            print("No comments on this one yet!!\n")
        else:
            for row in result:
                print(row['comment'])
        cnc.conn.commit()
def write_comment():
    print('*' * 120)
    ## writes a user's comment
    recipe_name = input("Which recipe you want to comment on?\n")
    flag = True
    while (flag):
        if (cnc.check_for_Blanks(recipe_name) == False):
            recipe_name = input("Enter the recipe you're looking for! \n")
        else:
            flag = False
    sql = "select recipe_id,recipe_name from `recipe` where `recipe_name` = %s"
    cnc.c.execute(sql, (recipe_name))
    p = []
    result = cnc.c.fetchall()
    if (cnc.c.rowcount == 0):
        print("Recipe does not exist!!\n")
    else:
        for row in result:
            p.append(row['recipe_id'])
            print(row)

        recipe_id = (input(
            "From the list above, which recipe_id is the one you want to leave a comment on?\n"
        ))
        flag = True
        while (flag):
            if (cnc.check_for_Blanks(recipe_id) == False):
                recipe_id = (input(
                    "From the list above, which recipe_id is the one you want to leave a comment on?\n"
                ))
            else:
                try:
                    recipe_id = int(recipe_id)
                    if (recipe_id in p):
                        flag = False
                    else:
                        print("Choose a valid recipe_id!\n")
                        recipe_id = (input(
                            "From the list above, which recipe_id is the one you want to leave a comment on?\n"
                        ))

                except ValueError:
                    print("Please enter a numeric value\n")
                    recipe_id = (input(
                        "From the list above, which recipe_id is the one you want to leave a comment on?\n"
                    ))

        comment = input("Enter your comment  \n")
        flag = True
        while (flag):
            if (cnc.check_for_Blanks(comment) == False):
                comment = input("Enter your comment  \n")
            else:
                flag = False
        sql = "INSERT INTO `comments` (`user_id`,`recipe_id`,`comment`)VALUES (%s, %s,%s)"
        cnc.c.execute(sql, (cnc.user_id, recipe_id, comment))
        print("Comment entered!\n")
        cnc.conn.commit()
def edit_comment():
    print('*' * 120)
    ##fetch all comments by this user and ask which one he wants to delete
    sql = (
        "select c.recipe_id,r.recipe_name,  c.comment_id, c.comment from comments c join recipe r on r.recipe_id=c.recipe_id where c.user_id=%s"
    )
    cnc.c.execute(sql, cnc.user_id)
    result = cnc.c.fetchall()
    p = []
    if (cnc.c.rowcount == 0):
        print("You have not commented yet!!\n")
    else:
        for row in result:
            print('recipe_id \t recipe_name \t comment_id \t comment \n')
            p.append(row['comment_id'])
            print(row['recipe_id'], '\t', row['recipe_name'], '\t',
                  row['comment_id'], '\t', row['comment'], '\t')
    comment_id = input("Enter comment_id for the comment you want to edit?\n")
    flag = True
    while (flag):
        if (cnc.check_for_Blanks(comment_id) == False):
            comment_id = input(
                "Enter comment_id for the comment you want to edit?\n")
        else:
            try:
                comment_id = int(comment_id)
                if (comment_id in p):
                    flag = False
                else:
                    print("Choose a valid comment_id!\n")
                    comment_id = input(
                        "Enter comment_id for the comment you want to edit?\n")

            except ValueError:
                print("Please enter a numeric value\n")
                comment_id = input(
                    "Enter comment_id for the comment you want to edit?\n")

    comment = input("Write your updated comment  \n")
    flag = True
    while (flag):
        if (cnc.check_for_Blanks(comment) == False):
            comment = input("Write your updated comment  \n")
        else:
            flag = False
    sql = "update `comments` set `comment`= %s where `comment_id`= %s"
    cnc.c.execute(sql, (comment, comment_id))
    print("Editing.. \n")
    print("Comment Edit successful!!\n")
    cnc.conn.commit()
def search_recipe():
    ## Searches for the recipe

    recipe_name = input("Enter the name of the recipe you're looking for! \n")
    flag = True
    while (flag):
        if (cnc.check_for_Blanks(recipe_name) == False):
            recipe_name = input("Enter the recipe you're looking for! \n")

        else:

            flag = False
    print('*' * 120)
    recipe_name = recipe_name.strip()
    sql = "select recipe ,prep_time,cook_time,ready_time,nutrition_val from `recipe` where `recipe_name`= %s"

    cnc.c.execute(sql, (recipe_name))
    result = cnc.c.fetchall()
    if (cnc.c.rowcount != 0):
        print("Here's the recipe!!\n")
        for row in result:
            print(
                "Prep Time \t Cook Time \t Ready Time \t Nutrition Val \t Recipe \n"
            )
            print(row['prep_time'], '\t', row['cook_time'], '\t',
                  row['ready_time'], '\t', row['nutrition_val'], "\n")
            print(row['recipe'])
    else:
        print("No recipe found!\n")
        print('*' * 120)
    cnc.conn.commit()
def delete_comment():

    ## Deletes an existing entry for a user's comment
    ##fetch all comments by this user and ask which one he wants to delete
    sql = (
        "select c.recipe_id,r.recipe_name,  c.comment_id, c.comment from comments c join recipe r on r.recipe_id=c.recipe_id where c.user_id=%s"
    )
    cnc.c.execute(sql, cnc.user_id)
    result = cnc.c.fetchall()
    if (cnc.c.rowcount == 0):
        print("No comments on this one yet!!\n")
        pass

    else:
        print("Here's a list of all your comments")
        p = []
        for row in result:
            p.append(row['comment_id'])
            print("comment_id \t comment")
            print(row['comment_id'], '\t', row['comment'])

        comment_id = input(
            "Enter comment_id for the comment you want to delete?\n")
        flag = True
        while (flag):
            if (cnc.check_for_Blanks(comment_id) == False):
                comment_id = input(
                    "Enter comment_id for the comment you want to delete?\n")
            else:
                try:
                    comment_id = int(comment_id)
                    if (comment_id in p):
                        flag = False
                    else:
                        print("Choose a valid comment_id!\n")
                        comment_id = input(
                            "Enter comment_id for the comment you want to delete?\n"
                        )

                except ValueError:
                    print("Please enter a numeric value\n")
                    comment_id = input(
                        "Enter comment_id for the comment you want to delete?\n"
                    )

        sql = "delete from `comments` where `comment_id`= %s"
        cnc.c.execute(sql, (comment_id))
        print("Deleting.. \n")
        print("Comment deletion successful!!\n")
        cnc.conn.commit()
Exemplo n.º 6
0
def give_feedback():
    print('*'*120)
 ## gives feedback for the system
    feedback= input("Thanks for your feedback. Enter it here  \n")
    
    flag=True
    while(flag):
        if(cnc.check_for_Blanks(feedback)==False):
            feedback= input("Thanks for your feedback. Enter it here  \n")
        else:
            
            flag=False

    sql = "INSERT INTO `feedback` (`user_id`,`feedback`)VALUES (%s, %s)"
    cnc.c.execute(sql, (cnc.user_id,feedback))
    cnc.conn.commit()
Exemplo n.º 7
0
def delete_feedback():
    print('*'*120)
 ## Deletes an existing entry for a user's feedback
    p=[]
    sql = "select feedback_id, feedback from `feedback` where `user_id`= %s"
    cnc.c.execute(sql, (cnc.user_id))
    result = cnc.c.fetchall()
    if (cnc.c.rowcount==0):
        print("You haven't provided us a feedback yet!!\n")
    else:
        print("Here's a list of all your feedback")
        for row in result:
            print("Feedback\t feedback_id\t")
            p.append(row['feedback_id'])

            print(row['feedback'],'\t',row['feedback_id']) 

        feedback_id=input("From the list above, which feedback_id is the one you want to delete?\n")
        flag=True
        while(flag):
            if(cnc.check_for_Blanks(feedback_id)==False):
                feedback_id=input("From the list above, which feedback_id is the one you want to delete?\n")
            else:
                try:
                    feedback_id=int(feedback_id)
                    if(feedback_id in p):
                        flag=False
                    else:
                        print("Choose a valid recipe_id!\n")
                        feedback_id=input("From the list above, which feedback_id is the one you want to delete?\n")
                          
                except ValueError  :
                    print("Please enter a numeric value\n")
                    feedback_id=input("From the list above, which feedback_id is the one you want to delete?\n")
                    
        sql = "delete from `feedback` where `feedback_id`= %s"
        cnc.c.execute(sql, (feedback_id))
        print("Feedback deletion successful!!\n")   
        cnc.conn.commit() 
def delete_recipe():
    ## Deletes an existing entry for a recipe
    print('*' * 120)
    recipe_name = input("Enter name of recipe you want to delete?  \n")
    flag = True
    while (flag):
        if (cnc.check_for_Blanks(recipe_name) == False):
            recipe_name = input("Enter the recipe you're looking for! \n")
        else:
            flag = False
    sql = "select distinct user_id from `recipe` where `recipe_name`= %s"
    cnc.c.execute(sql, (recipe_name))
    result = cnc.c.fetchall()
    p = []
    for row in result:
        p.append(row['user_id'])
    if (cnc.user_id in p):
        sql = "delete from `recipe` where `recipe_name`= %s and user_id=%s"
        cnc.c.execute(sql, (recipe_name, cnc.user_id))
        print("Deletion successful!\n")
    else:
        print("Oops,You can not delete someone else's recipe!\n")
    cnc.conn.commit()
def main():
    ### Describes the order in which operations should be performed.Connection establishment first, then schema creation.  """
    print('*' * 120)
    print(sys.version)
    print("Welcome to Recipe Management System \n")
    print("Setting up the Connection....\n")
    cnc.initialize()

    if cnc.conn is not None:
        print("Setting up...\n")
    else:
        print("Error! cannot create the database connection.\n")
        print('*' * 120)
    flag = True
    while (flag):
        signup = input(
            " Sign up? Enter YES if you're a new user or NO, if you're a registered user \n"
        )
        signup = signup.lower()
        signup = signup.strip()
        if signup == 'yes':
            cnc.sign_up()
            flag = False
        elif signup == 'no':
            cnc.log_in()
            flag = False
        else:
            print("Invalid choice\n")

    flag_home = True
    while (flag_home):
        print('*' * 120)
        choice = input(
            " Press \n 1 to search a recipe\n 2 to enter a new recipe \n 3 to delete an existing recipe\n 4 to give a comment \n 5 to edit a comment \n 6 to delete a comment \n 7 to view comments \n 8 to view fun facts \n 9 to delete your account\n 10 to give feedback to our System\n 11 to delete your feedback \n 12 to exit \n"
        )
        print('*' * 120)
        flag = True
        while (flag):
            if (cnc.check_for_Blanks(choice) == False):
                choice = input(
                    " Press \n 1 to search a recipe\n 2 to enter a new recipe \n 3 to delete an existing recipe\n 4 to give a comment \n 5 to edit a comment \n 6 to delete a comment \n 7 to view comments \n 8 to view fun facts \n 9 to delete your account\n 10 to give feedback to our System\n 11 to delete your feedback \n 12 to exit \n"
                )
                print('*' * 120)
            else:
                try:
                    choice = int(choice)
                    flag = False
                except ValueError:
                    print("Please enter a numeric value\n")
                    choice = input(
                        " Press \n 1 to search a recipe\n 2 to enter a new recipe \n 3 to delete an existing recipe\n 4 to give a comment \n 5 to edit a comment \n 6 to delete a comment \n 7 to view comments \n 8 to view fun facts \n 9 to delete your account\n 10 to give feedback to our System\n 11 to delete your feedback \n 12 to exit \n"
                    )
        if choice == 1:
            search_recipe()
        elif choice == 2:
            enter_recipe()
        elif choice == 3:
            delete_recipe()
        elif choice == 4:
            write_comment()
        elif choice == 5:
            edit_comment()
        elif choice == 6:
            delete_comment()
        elif choice == 7:
            display_comment()
        elif choice == 8:
            fun_facts()
        elif choice == 9:
            cnc.delete_user()
        elif choice == 10:
            give_feedback()
        elif choice == 11:
            delete_feedback()
        elif choice == 12:
            print("Come again soon!!")
            exit()
        else:
            print("Invalid choice\n")
def enter_recipe():
    ## Makes a new entry for a recipe
    print('*' * 120)
    recipe_name = input("What is the name of your recipe?\n")
    flag = True
    while (flag):
        if (cnc.check_for_Blanks(recipe_name) == False):
            recipe_name = input("What is the name of your recipe? \n")
            recipe_name = recipe_name.strip()
        else:
            flag = False
    recipe_name = recipe_name.strip()
    flag_category = True
    while (flag_category):
        category = (input(
            " Select category: Press\n 1 for breakfast \n 2 for Dessert \n 3 for Comfort food\n 4 for Lunch\n 5 for Dinner \n 6 for Soup \n 7 for Appetizer \n 8 for Baking \n"
        ))
        flag = True
        while (flag):
            if (cnc.check_for_Blanks(category) == False):
                category = (input(
                    " Select category: Press\n 1 for breakfast \n 2 for Dessert \n 3 for Comfort food\n 4 for Lunch\n 5 for Dinner \n 6 for Soup \n 7 for Appetizer \n 8 for Baking \n"
                ))
            else:
                try:
                    category = int(category)
                    flag = False
                except ValueError:
                    print("Please enter a numeric value\n")
                    category = (input(
                        " Select category: Press\n 1 for breakfast \n 2 for Dessert \n 3 for Comfort food\n 4 for Lunch\n 5 for Dinner \n 6 for Soup \n 7 for Appetizer \n 8 for Baking \n"
                    ))

        if category == 1:
            category_id = 1
            flag_category = False
        elif category == 2:
            category_id = 2
            flag_category = False
        elif category == 3:
            category_id = 3
            flag_category = False
        elif category == 4:
            category_id = 4
            flag_category = False
        elif category == 5:
            category_id = 5
            flag_category = False
        elif category == 6:
            category_id = 6
            flag_category = False
        elif category == 7:
            category_id = 7
            flag_category = False
        elif category == 8:
            category_id = 8
            flag_category = False
        else:
            print("Invalid choice\n")
    flag_cuisine = True
    while (flag_cuisine):
        cuisine = (input(
            " Select cuisine: Press\n 1 for Indian \n 2 for Mexican \n 3 for American\n 4 for Japanese\n 5 for Chinese \n 6 for Carribean \n 7 for Vietnamese \n 8 for Thai \n  9 for Chinese \n 10 for Italian \n "
        ))
        flag = True
        while (flag):
            if (cnc.check_for_Blanks(cuisine) == False):
                cuisine = (input(
                    " Select cuisine: Press\n 1 for Indian \n 2 for Mexican \n 3 for American\n 4 for Japanese\n 5 for Chinese \n 6 for Carribean \n 7 for Vietnamese \n 8 for Thai \n  9 for Chinese \n 10 for Italian \n "
                ))
            else:
                try:
                    cuisine = int(cuisine)
                    flag = False
                except ValueError:
                    print("Please enter a numeric value\n")
                    cuisine = (input(
                        " Select cuisine: Press\n 1 for Indian \n 2 for Mexican \n 3 for American\n 4 for Japanese\n 5 for Chinese \n 6 for Carribean \n 7 for Vietnamese \n 8 for Thai \n  9 for Chinese \n 10 for Italian \n "
                    ))

        if cuisine == 1:
            cuisine_id = 1
            flag_cuisine = False
        elif cuisine == 2:
            cuisine_id = 2
            flag_cuisine = False
        elif cuisine == 3:
            cuisine_id = 3
            flag_cuisine = False
        elif cuisine == 4:
            cuisine_id = 4
            flag_cuisine = False
        elif cuisine == 5:
            cuisine_id = 5
            flag_cuisine = False
        elif cuisine == 6:
            cuisine_id = 6
            flag_cuisine = False
        elif cuisine == 7:
            cuisine_id = 7
            flag_cuisine = False
        elif cuisine == 8:
            cuisine_id = 8
            flag_cuisine = False
        elif cuisine == 9:
            cuisine_id = 9
            flag_cuisine = False
        elif cuisine == 10:
            cuisine_id = 10
            flag_cuisine = False
        else:
            print("Invalid choice\n")

    recipe = input(
        "Let's start with the recipe now. Press Enter when done-  \n")
    flag = True
    while (flag):
        if (cnc.check_for_Blanks(recipe) == False):
            recipe = input(
                "Let's start with the recipe now. Press Enter when done -  \n")
        else:
            flag = False
    ingredients = input(
        "Enter ingredients for the recipe. Press Enter when done\n")
    flag = True
    while (flag):
        if (cnc.check_for_Blanks(ingredients) == False):
            ingredients = input(
                "Enter ingredients for the recipe .Press Enter when done \n")
        else:
            flag = False
    prep_time = input("Enter preparation time (in minutes) for the recipe.\n")
    flag = True
    while (flag):
        if (cnc.check_for_Blanks(prep_time) == False):
            prep_time = input(
                "Enter preparation time (in minutes) for the recipe.\n")
        else:
            prep_time = prep_time.strip()
            try:
                prep_time = int(prep_time)
                flag = False
            except ValueError:
                print("Please enter a numeric value\n")
                prep_time = input(
                    "Enter preparation time (in minutes) for the recipe.\n")

    cook_time = input("Enter cook time (in minutes)  for the recipe.\n")
    flag = True
    while (flag):
        if (cnc.check_for_Blanks(cook_time) == False):
            cook_time = input("Enter cook time (in minutes) for the recipe.\n")
        else:
            cook_time = cook_time.strip()
            try:
                cook_time = int(cook_time)
                flag = False
            except ValueError:
                print("Please enter a numeric value\n")
                cook_time = input(
                    "Enter cook time (in minutes) (in minutes) for the recipe.\n"
                )

    ready_time = input("Enter ready time (in minutes) for the recipe.\n")
    flag = True
    while (flag):
        if (cnc.check_for_Blanks(ready_time) == False):
            ready_time = input(
                "Enter ready time (in minutes) for the recipe.\n")
        else:
            ready_time = ready_time.strip()
            try:
                ready_time = int(ready_time)
                flag = False
            except ValueError:
                print("Please enter a numeric value\n")
                ready_time = input(
                    "Enter ready time (in minutes) (in minutes) for the recipe.\n"
                )
            else:
                flag = False
    servings = (input("Enter servings for the recipe.\n"))
    flag = True
    while (flag):
        if (cnc.check_for_Blanks(servings) == False):
            servings = (input("Enter servings for the recipe.\n"))
        else:
            servings = servings.strip()
            try:
                servings = int(servings)
                flag = False
            except ValueError:
                print("Please enter a numeric value\n")
                servings = (input("Enter servings for the recipe.\n"))
    flag = True
    nutrition_val = input("Enter nutrition value (in cal)  for the recipe.\n")
    while (flag):
        if (cnc.check_for_Blanks(nutrition_val) == False):
            nutrition_val = input(
                "Enter nutrition value (in cal)  for the recipe.\n")
        else:
            nutrition_val = nutrition_val.strip()
            try:
                nutrition_val = int(nutrition_val)
                flag = False
            except ValueError:
                print("Please enter a numeric value\n")
                nutrition_val = input(
                    "Enter nutrition value (in cal)  for the recipe.\n")
    sql = "INSERT INTO `recipe` (`recipe_name`,`user_id`,`category_id`,`cuisine_id`,`recipe` , `ingredients`, `prep_time` , `cook_time` ,  `ready_time`,`servings`,`nutrition_val` ) VALUES (%s, %s ,%s, %s,%s, %s,%s, %s,%s,%s,%s)"
    cnc.c.execute(sql, (recipe_name, cnc.user_id, category_id, cuisine_id,
                        recipe, ingredients, prep_time, cook_time, ready_time,
                        servings, nutrition_val))
    cnc.conn.commit()
    print('*' * 120)
    print("Thank you for contributing\n")
    print('*' * 120)