From 3cab1d734ccd53ddbc2a430e80d391733b464a84 Mon Sep 17 00:00:00 2001 From: AnkitMajee <76817118+AnkitMajee@users.noreply.github.com> Date: Tue, 2 Aug 2022 23:47:55 +0530 Subject: [PATCH] Some Python files --- contact.py | 52 ++++++++++++++ coupon.py | 191 ++++++++++++++++++++++++++++++++++++++++++++++++++ menu.py | 178 ++++++++++++++++++++++++++++++++++++++++++++++ pay.py | 93 ++++++++++++++++++++++++ print.py | 188 +++++++++++++++++++++++++++++++++++++++++++++++++ purchase.html | 109 ++++++++++++++++++++++++++++ tablebook.py | 92 ++++++++++++++++++++++++ test.py | 7 ++ 8 files changed, 910 insertions(+) create mode 100644 contact.py create mode 100644 coupon.py create mode 100644 menu.py create mode 100644 pay.py create mode 100644 print.py create mode 100644 purchase.html create mode 100644 tablebook.py create mode 100644 test.py diff --git a/contact.py b/contact.py new file mode 100644 index 0000000..ce4bb5c --- /dev/null +++ b/contact.py @@ -0,0 +1,52 @@ +#!"C:/Users/Rahul1234/anaconda3/python.exe" +import cgi +import mysql.connector as conn +def htmlTop(): + print("""Content-type:text/html\n\n + + + + + + Form Submit + + """) + +def htmlTail(): + print(""" + """) + +def getData(): + formData = cgi.FieldStorage() + name = formData.getvalue('Name') + eid = formData.getvalue('Email') + msg = formData.getvalue('Message') + return name,eid,msg + +def connectDB(): + db = conn.connect(host='localhost',user='root',passwd='',db='kph') + cursor = db.cursor() + return db,cursor + +def createUserList(name,eid,msg): + user = [] + user.append([name,eid,msg]) + return user +def insertUser(db,cursor,user): + for each in user: + sql = "insert into contact(name,emailid,message) values('{0}','{1}','{2}')".format(each[0],each[1],each[2]) + cursor.execute(sql) + db.commit() + +if __name__ == "__main__": + try: + htmlTop() + db,cursor = connectDB() + name,eid,msg = getData() + user = createUserList(name,eid,msg) + insertUser(db,cursor,user) + print("

Thank You for Contacting Us

Redirecting You to Home Page...

") + htmlTail() + except: + cgi.print_exception() + diff --git a/coupon.py b/coupon.py new file mode 100644 index 0000000..aca0790 --- /dev/null +++ b/coupon.py @@ -0,0 +1,191 @@ +#!"C:/Users/Rahul1234/anaconda3/python.exe" +import cgi +import mysql.connector as conn +db = conn.connect(host='localhost',user='root',passwd='',db='kph') +cursor = db.cursor() +print("""Content-type:text/html\n\n + + + + + Kolkata Pizza Hub | Coupons + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

We are launching complete online food order system for restaurent and takeaway Only at the rate
₹195

+
+
+
+
+
+

Best Buy Coupons

+ + +
+ + + + + + + + + + + + + +""") \ No newline at end of file diff --git a/menu.py b/menu.py new file mode 100644 index 0000000..4fa7d0e --- /dev/null +++ b/menu.py @@ -0,0 +1,178 @@ +#!"C:/Users/Rahul1234/anaconda3/python.exe" +import cgi +import mysql.connector as conn +print("""Content-type:text/html\n\n + + + Kolkata Pizza Hub | Order Menu + + + + + + + + + + + + + + + + + + + + +
+ +

Pizza

+ +
+ + + + + + + + + + """) + +try: + db = conn.connect(host='localhost',user='root',passwd='',db='kph') + cursor = db.cursor() + sql = "select * from pizza" + cursor.execute(sql) + pizzaNameList = cursor.fetchall() + sql = "select * from topping" + cursor.execute(sql) + toppingList = cursor.fetchall() + for each in pizzaNameList: + print(""" + + + + """.format(each[0],each[1],each[2],each[3],each[4])) + print(""" + """) + print(""" + + + + +
+
{0}
+ +
+ + + + +
+
+ +
+
+
+ + + + +
+ +
₹ {4}/-
+
+
+ """) + for i in toppingList: + print(""" + + + """.format(i[0],i[1],i[2],each[3])) + print("""
+ + +
+ +
+
+
+
+
+
+
+
+
+ + """) +except: + cgi.print_exception() \ No newline at end of file diff --git a/pay.py b/pay.py new file mode 100644 index 0000000..3536122 --- /dev/null +++ b/pay.py @@ -0,0 +1,93 @@ +#!"C:/Users/Rahul1234/anaconda3/python.exe" +import cgi +import mysql.connector as conn +def htmlTop(): + print("""Content-type:text/html\n\n + + + +Kolkata Pizza Hub | Table Booking + + + + + + + + + + + + + + +""") + +def htmlTail(): + print(""" + """) + +def getData(): + formData = cgi.FieldStorage() + name = formData.getvalue('customer_name') + phno = formData.getvalue('phone_number') + eid = formData.getvalue('email_address') + address = formData.getvalue('address') + return name,phno,eid,address + +def connectDB(): + db = conn.connect(host='localhost',user='root',passwd='',db='kph') + cursor = db.cursor() + return db,cursor + +def createUserList(name,phno,eid,address): + user = [] + user.append([name,phno,eid,address]) + return user +def insertUser(db,cursor,user,orderid): + for each in user: + sql = "update orders SET name = '{0}', phno = {1}, eid = '{2}', address = '{3}' WHERE orders.orderid = {4}".format(each[0],each[1],each[2],each[3],orderid) + #print(sql) + cursor.execute(sql) + db.commit() + +def getDetail(db,cursor): + sql = "select orderid from orders order by orderid DESC LIMIT 1" + cursor.execute(sql) + orderid = str(cursor.fetchone()[0]) + return orderid +if __name__ == "__main__": + try: + htmlTop() + db,cursor = connectDB() + orderid = getDetail(db,cursor) + name,phno,eid,address = getData() + user = createUserList(name,phno,eid,address) + insertUser(db,cursor,user,orderid) + + print('''

Thank You

Your Order has beed successfully placed

Your Order Id is: %s

'''%(orderid)) + htmlTail() + except: + cgi.print_exception() + diff --git a/print.py b/print.py new file mode 100644 index 0000000..1209b46 --- /dev/null +++ b/print.py @@ -0,0 +1,188 @@ +#!"C:/Users/Rahul1234/anaconda3/python.exe" +import cgi +import mysql.connector as conn +from decimal import * +db = conn.connect(host='localhost',user='root',passwd='',db='kph') +a=[] +sizetemp=[] +cursor = db.cursor() +i = 0 + +def htmlTop(): + print("""Content-type:text/html\n\n + + + + Kolkata Pizza Hub | Cart + + + + + + + + + + + + + + + + + + + + +
""") + +def htmlTail(): + print("""
+ """) + +def connectDB(): + db = conn.connect(host='localhost',user='root',passwd='',db='kph') + cursor = db.cursor() + return db,cursor + +def selectPizza(db,cursor,pizzacart): + #print(pizzacart) + for key in pizzacart: + sql = "select pizza_name,price from pizza where id=%s"%(key) + cursor.execute(sql) + pizza = cursor.fetchall() + """for key in pizzacart: + sql = "select label from topping where value=%s"%(key) + cursor.execute(sql) + pizza = cursor.fetchall()""" + #print(pizza) + disp(pizza) + #return pizza + +def disp(pizza): + global i + getcontext().prec = 5 + for each in pizza: + print("""

""".format(each[0])) + if sizetemp[i] == 'r': + print('''

'''.format(each[1])) + a.append(float(each[1])) + elif sizetemp[i] == 'm': + print('''

'''.format(each[1]*Decimal(1.913043))) + a.append(float(each[1]*Decimal(1.3))) + elif sizetemp[i] == 'l': + print('''

'''.format(each[1]*Decimal(2.8478260))) + a.append(float(each[1]*Decimal(1.7))) + #print(str(a)) + i+=1 + #for i in a: + #x+=float(i) + #x+=float(i) + + +def getData(): + formData = cgi.FieldStorage() + value = dict() + + ky = formData.keys() + for each in ky: + temp = formData.getlist(each) + #print(each + " " + str(temp)) + value.update({each:temp}) + test=str(value) + + + + test=test.replace("'","") + sql="insert into orders(orderid,details) values('null','%s')"%(test) + cursor.execute(sql) + return value + +def processing(cart,cursor): + c=0 + for each in cart['pizzaid']: + c+=1 + print(""""""%str(c)) + for i in range(1,25): + if ('size'+str(i)) in cart: + size = cart[('size'+str(i))] + if size==['m']: + #print("Size is Medium") + sizetemp.append('m') + elif size==['l']: + #print("Size is Large") + sizetemp.append('l') + elif size==['r']: + #print("Size is Regular") + sizetemp.append('r') + + #print(sizetemp) + for each in cart['pizzaid']: + pizzacart = dict() + pizzacart.update({each:[]}) + top = '' + #print(each) + if ('size'+str(each)) in cart: + name =cart[('size'+str(each))] + #print(name) + if ('topid'+str(each)) in cart: + top=(cart[('topid'+str(each))]) + #print(cart['topid'+str(each)]) + sql = "insert into cart(pizzaid,size,topid) values('{0}','{1}','{2}')".format(each,name[0],' '.join(top)) + else: + top=' ' + sql = "insert into cart(pizzaid,size,topid) values('{0}','{1}','{2}')".format(each,name[0],top[0]) + #print(top) + #print(pizzacart) + (selectPizza(db,cursor,pizzacart)) + + #print(sql) + cursor.execute(sql) + db.commit() + #return pizzacart + + +if __name__ == "__main__": + try: + cart = dict() + htmlTop() + cart = getData() + #db,cursor = connectDB() + cursor.execute("truncate cart") + db.commit() + pizzacart = processing(cart,cursor) + #pizza = selectPizza(db,cursor,pizzacart) + cursor.close() + print('''

'''%(sum(a))) + print('''

''') + print('''

''') + htmlTail() + except: + cgi.print_exception() + diff --git a/purchase.html b/purchase.html new file mode 100644 index 0000000..50da15b --- /dev/null +++ b/purchase.html @@ -0,0 +1,109 @@ + + + + + + + + My Example + + + + + + + + +
+ +

+ +

+ +

+ +

+ +

+ +

+ +

+ +

+ +

+ +
+ + + + \ No newline at end of file diff --git a/tablebook.py b/tablebook.py new file mode 100644 index 0000000..618e3d3 --- /dev/null +++ b/tablebook.py @@ -0,0 +1,92 @@ +#!"C:/Users/Rahul1234/anaconda3/python.exe" +print('Content-type:text/html\n\n'); + +def htmlTop(): + print(""" + + + +Kolkata Pizza Hub | Table Booking + + + + + + + + + + + + + + + + + + + + +

Booking Successfully Done

""") +import cgi +import mysql.connector as conn +def htmlTail(): + print("""
GoTo Home
+ """) + +def connectDB(): + db = conn.connect(host='localhost',user='root',passwd='',db='kph') + cursor = db.cursor() + return db,cursor + +def getData(): + formData = cgi.FieldStorage() + time = formData.getvalue('time') + date = formData.getvalue('date') + people = formData.getvalue('people') + return time,date,people + +def insertUser(db,cursor,time,date,people): + sql = "insert into booking(time,date,people) values('%s','%s','%s')"%(time,date,people) + cursor.execute(sql) + db.commit() + +def selectUser(db,cursor): + sql="select bookid from booking order by bookid desc limit 1" + cursor.execute(sql) + user=str(cursor.fetchone()[0]) + print("""

Booking ID is: {0}

""".format(user)) + +if __name__ == "__main__": + try: + htmlTop() + db,cursor = connectDB() + time,date,people = getData() + insertUser(db,cursor,time,date,people) + selectUser(db,cursor) + htmlTail() + except: + cgi.print_exception() + diff --git a/test.py b/test.py new file mode 100644 index 0000000..64b9c2a --- /dev/null +++ b/test.py @@ -0,0 +1,7 @@ +#!"C:/Users/Rahul1234/anaconda3/python.exe" +print('Content-type:text/html\n\n'); +a=5 +b=4 +c=a+b +print(c) +