import sqlite3
con = sqlite3.connect(‘project.db’)
mycursor = con.cursor()
def add_restaurant(name, address) :
sql = “insert into restaurants (name,address) values(’%s’,’%s’)” % (name, address)
mycursor.execute (sql)
con.commit ( )
print(“Restaurant added!”)
def list_restaurants():
sql = “select * from restaurants”
mycursor.execute (sql)
return mycursor.fetchall ( )
def list_food_types() :
sql = “select * from food_types”
mycursor.execute (sql)
return mycursor.fetchall ( )
def add_food_types(val) → object:
“”"
:rtype: object
"""
sql = "insert into food_types(name,price,category_id) values(%s,%s,%s)"
mycursor.execute (sql, val)
mydb.commit ( )
def list_foods() :
sql = “select p.id,p.name,p.price, c.name, c.description from products p inner join categories c on p.category_id = c.id”
mycursor.execute (sql)
return mycursor.fetchall ( )
def list_foods_bay_cat_id(val, mycursor=None) :
sql = “select p.id,p.name,p.price, c.name, c.description from products p inner join categories c on p.category_id = c.id where c.id = %s”
mycursor.execute (sql, val)
return mycursor.fetchall ( )
def list_categories() :
sql = “select p.id,p.name,p.price, c.name, c.description from products p inner join categories c on p.category_id = c.id where c.id = %s”
mycursor.execute (sql, val)
return mycursor.fetchall ( )
pass
def add_category(val) → object:
“”"
:rtype: object
"""
sql = "insert into list_categories(name,price,category_id) values(%s,%s,%s)"
mycursor.execute (sql, val)
mydb.commit ( )
while True :
choice = int (input ("[1]RESTAURANTS\n[2]FOOD_TYPES\n[3]FOODS\n[0]EXIT\n"))
if choice == 1 :
choiceIn = int (
input ("[1]ADD RESTAURANT\n[2]LIST RESTAURANTS\n[3]EDIT RESTAURANT\n[4]DELETE RESTAURANT\n[0]BACK\n"))
if choiceIn == 1:
name = input (“Insert name\n”)
address = (input (‘Insert address\n’))
add_restaurant(name, address)
elif choiceIn == 2 :
result = list_restaurants ( )
for prod in result :
print ("ID: “, prod[0], “Name :”, prod[1], " Address: “, prod[2])
elif choice == 2 :
choiceIn = int (input (”[1]ADD_CATEGORY\nCATEGORY\n[2]LIST CATEGORIES\n[3]EDIT CATEGORY\n[4]DELETE CATEGORY\n[0]BACK\n”))
if choiceIn == 1 :
name = input (“Insert name\n”)
description = input (“Insert description\n”)
val = (name, description)
add_category (sql, val)
elif choiceIn == 2 :
result = list_categories (sql, val)
for cat in result :
print (cat)
1 post - 1 participant