-
Notifications
You must be signed in to change notification settings - Fork 1
/
print.py
187 lines (169 loc) · 7.85 KB
/
print.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
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
<!DOCTYPE html>
<html lang="en">
<head>
<title>Kolkata Pizza Hub | Cart</title>
<link rel="shortcut icon" href="images/favicon.png" type="image/x-icon">
<!-- for-mobile-apps -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="keywords" content="Kolkata Pizza Hub" />
<script type="application/x-javascript">
addEventListener("load", function() {
setTimeout(hideURLbar, 0);
}, false);
function hideURLbar() {
window.scrollTo(0, 1);
}
</script>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<!-- //for-mobile-apps -->
<link href="css/bootstrap.css" rel="stylesheet" type="text/css" media="all" />
<link href="css/font-awesome.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet" type="text/css" media="all" />
<!--web-fonts-->
<link href="//fonts.googleapis.com/css?family=Montserrat:400,700" rel="stylesheet">
<link href="//fonts.googleapis.com/css?family=Lato:300,400,700" rel="stylesheet">
<link href="//fonts.googleapis.com/css?family=Tangerine:400,700" rel="stylesheet">
<!--//web-fonts-->
<style>
@keyframes glowing {
0% { background-color: #5bc0de; box-shadow: 0 0 3px #5bc0de; }
50% { background-color: #5bded9; box-shadow: 0 0 40px #5bded9; }
100% { background-color: #5bc0de; box-shadow: 0 0 3px #5bc0de; }
}
.button {
-webkit-animation: glowing 1500ms infinite;
-moz-animation: glowing 1500ms infinite;
-o-animation: glowing 1500ms infinite;
animation: glowing 1500ms infinite;
}
</style>
</head>
<body style="background-image: url(images/bg.png);
background-repeat: repeat;
background-size: 20%;
background-color: rgba(184, 219, 38, 0.24);
background-blend-mode: multiply;
padding-bottom: 100px;
min-height: 100vh">
<div class="container"><div class="col-sm-12" style="background-color: rgba(0, 0, 0, 0.3); margin-top: 100px; padding-bottom: 50px">""")
def htmlTail():
print("""</div></div></body>
</html>""")
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("""<div class="col-sm-8 text-left" style="margin-bottom: 10px"><h3><label class="label label-success">You Have ordered {0}</label></h3></div>""".format(each[0]))
if sizetemp[i] == 'r':
print('''<div class="col-sm-4 text-right" style="margin-bottom: 10px"><h4><label class="label label-warning">Cost is ₹ {0}</label></h4></div>'''.format(each[1]))
a.append(float(each[1]))
elif sizetemp[i] == 'm':
print('''<div class="col-sm-4 text-right" style="margin-bottom: 10px"><h4><label class="label label-warning">Cost is ₹ {0}</label></h4></div>'''.format(each[1]*Decimal(1.913043)))
a.append(float(each[1]*Decimal(1.3)))
elif sizetemp[i] == 'l':
print('''<div class="col-sm-4 text-right" style="margin-bottom: 10px"><h4><label class="label label-warning">Cost is ₹ {0}</label></h4></div>'''.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("""<button type="button" class="btn btn-danger col-sm-12 " style="margin-bottom: 10px"><h2>No of Pizza: <span class="badge"><h3>%s</h3></span></h2></button>"""%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('''<div class="col-sm-12 text-center"><h1><label class="label label-info button">Your Total Amount is: ₹ %s0</label></h1></div>'''%(sum(a)))
print('''<div class="col-sm-3 text-right"><h4><a href="menu.py"><label class="label label-primary">Back to Menu</label></a></h4></div>''')
print('''<div class="col-sm-8 text-right"><h4><a href="purchase.html"><label class="label label-primary">Proceed to Pay</label></a></h4></div>''')
htmlTail()
except:
cgi.print_exception()