Archive

Archive for February 13, 2020

Python: Cooking App P-5

February 13, 2020 Leave a comment


Learning : Python, Data-Base, SQlite
Subject: Writing a Cooking Application

RECIPES MENU: Once I start reading the Net (blogs and Cooking Books) to see how cookers talking about foods-recipes, I realise that I may need to add something to the DataBase, then I start writing the codes for the “Recipe Menu” and immediately I find the we need to add a new Table; I call it “recipes_steps” it will hold several steps of how to cook a recipe.

DataBase Diagram

Here is the code to create the new Table and adding the record 0 (Zero).
# To create the Table “recipes_steps” .
sql_recipes_steps =”CREATE TABLE if not exists recipes_steps (st_id INTEGER PRIMARY KEY AUTOINCREMENT,r_id integer, rec_steps text )”
c.execute(sql_recipes_steps)
db_conn.commit()

# To add the Record Zero.
c.execute (“INSERT INTO recipes_steps (st_id) VALUES(:st_id)”,{“st_id”:0})
db_conn.commit()

First let’s see the “Recipe Menu” and from there we will write the codes for each item in the menu. As we saw in Ingredients Menu, same functionality should be here to, Listing all Recipes, Adding new one, Editing and Deleting a recipes. We will write the code for each of them, and here is the code for the “Recipes Menu”

 # Recipes Menu - Function
 
def recipes_menu ():
    while True:
        os.system("clear")
        print('\n ===========[ RECIPES MENU ]=============')
        print('  --------------------------------------')
        print(' 1. Show Recipes.')
        print(' 2. Add Recipe.')
        print(' 3. Delete Recipe. ')
        print(' 4. Edit Recipe.')
        print(' 9. Exit')
        uinp= input('\n Enter your Selection: ')

        if uinp == '1':
            show_recipes()
        elif uinp == '2':
            add_recipe()
        elif uinp == '3':
            del_recipe()
        elif uinp == '4':
            edit_recipe()
        elif uinp =='9':
            return
        else:
            print('\n  Please select from the Menu.')


So first thing we will work on “Show Recipes”, once the user select Show Recipes another Menu will be display to give more option as in the screen shot..

To display the Recipes based on the options we have, we will write a function that take a parameter based on the user selection so the user can search for a recipe based on it’s Name, Date or other details. Let’s see the code ..



NOTE THAT: We did nothing with Tags option, after we finish the application we will assume that the Business owner ask to add a new requirement to the application, and we will see the impact of this and who to solve it.


In Next Post we will work on the Adding New Recipe to our Cooking Application.



To Download my Python code (.py) files Click-Here




Follow me on Twitter..




By: Ali Radwani