Archive for March 5, 2020

Python: Cooking App P-8

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

RECIPES MENU: Show Recipe During writing all functions of the application I notes that my “Show Recipe” need to be updated, so in this post we will do some changes on “def show_all_rec(opt)” function.

First, we will change the if opt ==”name” to list all the Recipes Name with ID’s and ask the user to Enter a Recipe ID to show its information.
Here is the code ..

 # Changes on show_all_rec(opt) - if opt =="name"

if opt =="name" :
        #First we will list down all Recipes Names.
        c.execute("select r_id,r_name from recipes where r_id > 0")
        for each_r_name in c.fetchall():
            print(' ID:',each_r_name[0], ' Name:',each_r_name[1])
        get_rec_id = input ('\n Enter the Recipe ID you want to read: ')
        # Get the Recipe information based on ID.
        c.execute("select * from recipes where r_id ={}".format(get_rec_id))
        for each_basic in c.fetchall():
            print('\n  ID: ',each_basic[0])
            print('  Name: ',each_basic[1])
            print('  Date: ',each_basic[2])
            print('  Type: ',each_basic[3])
            print('  Other: ',each_basic[4])

            print('\n  The Recipe Ingredients: ')
            # Get all Recipe Ingredients.
            get_sql = '''


                    INNER JOIN rec_ingredient ON ingredients_list.i_l_id = rec_ingredient.i_l_id
                    where rec_ingredient.r_id = {}


            st = 1
            for each in c.fetchall():
                print('  ',st,': ',each[0])
                st = st + 1

            print('\n\n  Cooking Steps: ')
            # Get the Cooking Steps. 
            c.execute("select * from recipes_steps where recipes_steps.r_id = {}".format(each_basic[0]))
            st = 1
            for each in c.fetchall():
                print('\n    Step-',st,': ',each[2])
                st = st + 1

            print('\n ---------------------------------------------')

Here is the out-put screen :

First we have the Menus, we select 1,1,1 to
get “Show Recipe By Name”

Here is the List of All Recipes and we will enter
the ID of the one we want to see.

Here is the Recipes Information.

Notes That 1. We don’t have any Ingredient (we did not add any) so in coming post we will develop the Edit function to add some Ingredient and change/Update the Recipe Information.
2. We are not using any Validations, so if we enter any dummy data for Date the system will accept it.
3. We are not using any (avoiding Error code) such as Try…except.

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

Follow me on Twitter..

By: Ali Radwani