-
Notifications
You must be signed in to change notification settings - Fork 1
/
price_query.py
executable file
·56 lines (56 loc) · 1.33 KB
/
price_query.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
import re
from ner_client import *
def query_db_price(d,h_tup):
nr = NerClient("1PI11CS004","g08")
os = "Android"
org = "Samsung"
product=""
low_price = 0
max_price = 100000
if len(d["os_list"])>0:
os = d['os_list'][0]
if len(d["org"])>0:
org = d["org"][0]
elif os.lower()=="ios":
org="Apple"
elif os.lower() == "windows":
org="Nokia"
if len(d["family"])>0:
family = d["family"][0]
elif os=="Apple":
family="iPhone"
elif os=="Windows":
family="Lumia"
try:
low_price = int(d['start_price'])
max_price = int(d['end_price'])
except:
abcd=0
model = ""
for i in h_tup['updates']:
if i['tag'] == "Model":
model = i['word']
#if model=="":
#print d['start_price'] , d['end_price']
s = nr.get_products(org)
if model!="":
for i in s:
if i['product']==model:
return "The price of " + model + " is " + i['dummy_price']
#print s
#print low_price
#print max_price
res = []
for i in s:
if i["dummy_price"]<max_price and i['dummy_price']>low_price:
res.append(i)
res_string = "The "+ org + " products in your price range are :\n"
count = 1
#str(res)
for i in res:
res_string+=str(count) + ": " + i['product'] + "\n"
count+=1
if count>20:
break
res_string += "\n" + "It has been very well recieved and fits your requirements."
return res_string