Quantcast
Channel: GitHub Classroom - GitHub Community
Viewing all articles
Browse latest Browse all 55

Creating application to order foods, sql db was created

$
0
0

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

Read full topic


Viewing all articles
Browse latest Browse all 55

Trending Articles


Grand galla med gull og glitter


Psykiater Tonny Westergaard


Jav Uncensored - Tokyo-Hot n1002 Miyu Kitagawa


Moriya Suwako (Touhou)


BRODERET KLOKKESTRENG MED ORDSPROG 14 X 135 CM.


Naruto Shippuden Episode 471 Subtitle Indonesia


Fin gl. teske i sølv - 2 tårnet - stemplet


Kaffefilterholder fra Knabstrup


Anders Agger i Herstedvester


Onkel Joakims Lykkemønt *3 stk* *** Perfekt Stand ***


Sælges: Coral Beta/Flat (Højttaler-enheder)


Starwars landspeeder 7110


NMB48 – Durian Shounen (Dance Version) [2015.07.15]


Le bonheur | question de l'autre


Scope.dk som agent?


Akemi Homura & Kaname Madoka (Puella Magi Madoka Magica)


Tidemands taffel-marmelade julen1934+julen 1937+julen 1938.


Re: KZUBR MIG/MMA 300 zamena tranzistora


Analyse 0 mundtlig eksamen


DIY - Hæklet bil og flyvemaskine