Cs Project
Cs Project
import mysql.connector as ms
import sys
mycon=
ms.connect(host='{}'.format(hname),user='{}'.format(un),passwd='{}'.format(p
w),database='{}'.format(db))
if mycon.is_connected==False:
print("Error in Connecting")
cur=mycon.cursor()
print('''Choose a Number to Procceed
1. Add New Recipe
2. View Recipe
3. Delete Recipe
4. Update Recipe
5.Exit\n''')
if inp==1:
print("Adding a New Recipe to the List")
elif inp==2:
print('''1. View All Record
2. View Selected Record''')
view=int(input("Enter Number: "))
if view==1:
cur.execute("select* from recipe")
data=cur.fetchall()
for row in data:
print("------------------------------------------------------------","\n"
"FOOD:",row[0],'\n'
"INGREDIENTS:",row[1],'\n'
"EQUIPMENTS:",row[2],'\n'
"INSTRUCTIONS:",row[3],'\n'
"RATINGS:",row[4],"\n",
"------------------------------------------------------------")
print("Press Enter To Continue")
input()
elif view==2:
cur.execute("select* from recipe")
data=cur.fetchall()
avail=0
l=input("Enter Food: ")
for row in data:
if row[0]==l:
avail=1
print("------------------------------------------------------------","\n"
"FOOD:",row[0],'\n'
"INGREDIENTS:",row[1],'\n'
"EQUIPMENTS:",row[2],'\n'
"INSTRUCTIONS:",row[3],'\n'
"RATINGS:",row[4],"\n",
"------------------------------------------------------------")
else:
if avail==0:
print("record not found")
print("Press Enter To Continue")
input()
elif inp==3:
print("Deleting a Record")
cur.execute("select* from recipe")
data=cur.fetchall()
for row in data:
print("------------------------------------------------------------","\n"
"FOOD:",row[0],'\n'
"INGREDIENTS:",row[1],'\n'
"EQUIPMENTS:",row[2],'\n'
"INSTRUCTIONS:",row[3],'\n'
"RATINGS:",row[4],"\n",
"------------------------------------------------------------")
fid=input("Enter Food: ").lower()
delete=0
for row in data:
if row[0]==fid:
delete=1
qry="delete from recipe where food_name='{}'".format(fid)
cur.execute(qry)
mycon.commit()
print()
if delete==1:
print("Record Deleted Successfully")
else:
print("Record Not Available")
print()
cur.execute("select* from recipe")
data=cur.fetchall()
for row in data:
print("-----------------------------------------------------------","\n"
"FOOD:",row[0],'\n'
"INGREDIENTS:",row[1],'\n'
"EQUIPMENTS:",row[2],'\n'
"INSTRUCTIONS:",row[3],'\n'
"RATINGS:",row[4],"\n",
"-----------------------------------------------------------")
print("Press Enter To Continue")
input()
elif inp==4:
print("Updating a Record")
fid =(input("Enter Food: "))
qry = "Select * from recipe where food_name = '{}' order by
food_name".format(fid)
cur.execute(qry)
row = cur.fetchone()
count = cur.rowcount
print(count," record is searched successfully.")
print("-----------------------------------------------------------","\n"
"FOOD:",row[0],'\n'
"INGREDIENTS:",row[1],'\n'
"EQUIPMENTS:",row[2],'\n'
"INSTRUCTIONS:",row[3],'\n'
"RATINGS:",row[4],"\n",
"-----------------------------------------------------------")
food=input("Enter Food(new) or .(old): ")
ing=input("Enter Ingredients(new) or .(old): ")
eq=input("Enter Equipments(new) or .(old): ")
ins=input("Enter Instructions(new) or .(old): ")
if food == '.':
food = row[0]
if ing == '.':
ing = row[1]
if eq == '.':
eq = row[2]
if ins == '.':
ins = row[3]
qry="update recipe set food_name = '{}', ingredients = '{}', equipments =
'{}',\
instructions = '{}'where food_name = '{}'".format(food,ing,eq,ins,fid)
cur.execute(qry)
mycon.commit()
count = cur.rowcount
print(count," record is updated successfully.")
print("Press Enter to continue.")
input()
elif inp==5:
mycon.close()
print("Terminating Program")
sys.exit(0)
else:
print("Wrong Input Try Again")
print("Press Enter to continue.")
input()