-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathresponses.py
More file actions
219 lines (208 loc) · 8.68 KB
/
Copy pathresponses.py
File metadata and controls
219 lines (208 loc) · 8.68 KB
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
from ContentBased1 import getFinal
import DatabaseConnection as db
import geturls
import random
import CameraPhones
import PricePhones
import BatteryPhones
def getSpecs(phone_name):
cursor = db.mydb.cursor()
query="SELECT phonefeatures.CPU,phonevariants.Internal,phonevariants.RAM,phonefeatures.RearCamMP,phonefeatures.FrontCamMP,phonefeatures.Battery,phonefeatures.Price FROM `phonefeatures`,phonevariants WHERE ModelName='"+phone_name+"' and phonefeatures.PhoneID=phonevariants.PhoneID"
cursor.execute(query);
result = cursor.fetchall()
print(result)
specs="\n\n<b>Specifications: </b>\n"
specs=specs+"Processor: <b>"+str(result[0][0])+"</b>\n"
if len(result)>1:
specs=specs+"It comes in <b>"+str(len(result))+"</b> different variants:\n"
for i in range(0,len((result))):
specs=specs+"Internal Storage: <b>"+str(result[i][1])+"GB</b> "
specs=specs+"RAM: <b>"+str(result[i][2])+"GB</b>\n"
else:
specs=specs+"Internal Storage: <b>"+str(result[0][1])+"GB</b> "
specs=specs+"RAM: <b>"+str(result[0][2])+"GB</b>\n"
specs=specs+"Rear Camera: <b>"+str(result[0][3])+" MP</b>\n"
specs=specs+"Front Camera: <b>"+str(result[0][4])+" MP</b>\n"
specs=specs+"Battery: <b>"+str(result[0][5])+" MAH</b>\n"
specs=specs+"<b>PRICE: ₹"+str(result[0][6])+"</b>"
"""specs="\n\n"+phone_name+" comes with a <b>"+str(result[0][0])+"</b>\nThe internal storage it offers is <b>"+str(result[0][1])+"GB</b>"
specs=specs+" and supported by <b>"+str(result[0][2])+"GB</b> of RAM\n"
specs=specs+"It has a laser sharp Rear Camera of <b>"+str(result[0][3])+"MP</b> and a <b>"+str(result[0][4])+"MP</b> of Front Camera\n"
specs=specs+"It is powered by a huge <b>"+str(result[0][5])+"MAH</b> of Battery\n"
if len(result)>1:
specs=specs+"It comes in "+str(len(result))+" variants.\n"
specs=specs+"<b>PRICE: ₹"+str(result[0][6])+"</b>"""
return specs
def getBestPhone1():
list = getFinal()
cursor = db.mydb.cursor()
query="SELECT ModelName FROM `phonefeatures` WHERE PhoneID="+str(list[0])
cursor.execute(query);
result = cursor.fetchall()
print(result[0][0])
#urls=geturls.geturllist(result[0][0],"amazon")
urls=['https://www.amazon.in/Redmi-Pro-Black-64GB-Storage/dp/B07DJHXWZZ', 'https://www.amazon.com/Xiaomi-Factory-Unlocked-Smartphone-Version/dp/B07HK4JNV1']
resp=uniqueResponses1()+"<b>"+result[0][0]+"</b>\nYou can find the best buy link here:\n"
phone_name=result[0][0]
phone_name=phone_name.title()
resp=resp.title()
urls="<a href='"+urls[0]+"'><b>"+phone_name+"</b></a>"
resp=resp+urls
specs=getSpecs(phone_name)
return resp+specs
def getBestPhone2(count):
list = getFinal()
cursor = db.mydb.cursor()
result=[]
for i in list:
query="SELECT ModelName,Price FROM `phonefeatures` WHERE PhoneID="+str(i)
query1="select overall from ratings where pid="+str(i)
cursor.execute(query);
response=cursor.fetchall()
cursor.execute(query1)
response1=cursor.fetchall()
#result.append(cursor.fetchall().pop()[0])
result.append("Phone Name: <b>"+response[0][0]+"</b>")
result.append("Price: <b>"+str(response[0][1])+"</b>"+" Overall Rating: <b>"+str(response1[0][0])+"</b>")
#print(cursor.fetchall().pop()[0])
resp = uniqueResponses2()+"\n"
for i in range(0,count*3):
resp = resp + result[i] + "\n"
return resp.title()
def getBestPhone(entities):
if len(entities) == 0:
return getBestPhone1()
elif len(entities) == 1 and entities[0]["entity"]=="count":
print(entities)
qtype = entities[0]["entity"]
qval = entities[0]["value"]
if qtype == "count":
return getBestPhone2(int(qval))
else:
return getPricePhone(entities)
def getBestCameraPhone(entities):
if len(entities) == 0:
result=CameraPhones.camera("both")
print(result[0])
urls=geturls.geturllist(result[0],"amazon")
resp=uniqueResponses1()+result[0]+"\nYou can find the best buy link here:\n\n"
phone_name=result[0]
phone_name=phone_name.title()
resp=resp.title()
urls="<a href='"+urls[0]+"'>"+phone_name+"</a>"
resp=resp+urls+getSpecs(phone_name)
return resp
elif len(entities) == 1:
qval = entities[0]["value"]
if qval == "front":
result=CameraPhones.camera("front")
print(result[0])
urls=geturls.geturllist(result[0],"amazon")
resp="Phone with best front camera is "+result[0]+"\nYou can find the best buy link here:\n\n"
phone_name=result[0]
phone_name=phone_name.title()
resp=resp.title()
urls="<a href='"+urls[0]+"'>"+phone_name+"</a>"
resp=resp+urls
return resp
elif qval == "rear":
result=CameraPhones.camera("rear")
print(result[0])
urls=geturls.geturllist(result[0],"amazon")
resp="Phone with the best rear camera is "+result[0]+"\nYou can find the best buy link here:\n\n"
phone_name=result[0]
phone_name=phone_name.title()
resp=resp.title()
urls="<a href='"+urls[0]+"'>"+phone_name+"</a>"
resp=resp+urls
return resp
def getPricePhone(entities):
if len(entities) == 1:
qval = entities[0]["value"]
if qval[len(qval)-1]=="k":
qval=qval[:len(qval)-1]
qval=qval+"000"
result = PricePhones.getMaxPrice(qval)
resp=uniqueResponses1()+result[0][1];
resp=resp+getSpecs(result[0][1])
resp=resp+"\n"+"You may also like "+result[1][1]+" and "+result[2][1]
return resp
elif len(entities) == 2:
print(entities[0]["value"],"---",entities[1]["value"])
if entities[0]["entity"]=="count" and entities[1]["entity"]=="max_price":
print("Inside if")
topn = entities[0]["value"]
minp = entities[1]["value"]
if minp[len(minp)-1]=="k":
minp=minp[:len(minp)-1]
minp=minp+"000"
result = PricePhones.getMaxPrice(minp)
resp=uniqueResponses1()+result[0][1];
resp=resp+getSpecs(result[0][1])
resp=resp+"\nOther phones you might like are: \n"
i=1
while i<len(result) and i<int(topn):
resp=resp+result[i][1]+"\n"
i=i+1
return resp
elif entities[0]["entity"]=="min_price" and entities[1]["entity"]=="max_price":
maxp = entities[0]["value"]
minp = entities[1]["value"]
if minp[len(minp)-1]=="k":
minp=minp[:len(minp)-1]
minp=minp+"000"
if maxp[len(maxp)-1]=="k":
maxp=maxp[:len(maxp)-1]
maxp=maxp+"000"
result = PricePhones.getMaxMinPrice(maxp,minp)
resp=uniqueResponses1()+result[0][1];
resp=resp+getSpecs(result[0][1])
resp=resp+"\n"+"You may also like \n"
i=1
while i<len(result):
resp=resp+result[i][1]+"\n"
i=i+1
return resp
elif len(entities) == 3 and entities[0]["entity"]=="count" and entities[1]["entity"]=="min_price" and entities[2]["entity"]=="max_price":
topn = entities[0]["value"]
maxp = entities[1]["value"]
minp = entities[2]["value"]
if minp[len(minp)-1]=="k":
minp=minp[:len(minp)-1]
minp=minp+"000"
if maxp[len(maxp)-1]=="k":
maxp=maxp[:len(maxp)-1]
maxp=maxp+"000"
result = PricePhones.getMaxMinPrice(maxp,minp)
resp=uniqueResponses1()+result[0][1];
resp=resp+getSpecs(result[0][1])
resp=resp+"\n"+"You may also like \n"
i=1
while i<len(result) and i<int(topn):
resp=resp+result[i][1]+"\n"
i=i+1
return resp
def getBatterPhone():
result = BatteryPhones.battery()
resp=uniqueResponses1()+result[0];
resp=resp+getSpecs(result[0])
resp=resp+"\n"+"You may also like "+result[1]+" and "+result[2]
return resp
def uniqueResponses1():
resp=[
"You will like ",
"You can go for ",
"You will surely like ",
]
return resp[random.randint(0,len(resp)-1)]
def uniqueResponses2():
resp=[
"This is the list we found for you:",
"These are the phone that you will like:",
"Best suggestions for you:",
"Top phones for you:"
]
return resp[random.randint(0,len(resp)-1)]
#print(getBestPhone1())
#You can find the phone here
#find the phone at