| 13829 |
kshitij.so |
1 |
import urllib2
|
|
|
2 |
import simplejson as json
|
|
|
3 |
import pymongo
|
| 20347 |
kshitij.so |
4 |
from dtr.utils.utils import to_java_date, getNlcPoints, transformUrl, DEAL_PRIORITY
|
| 13918 |
kshitij.so |
5 |
from datetime import datetime, timedelta
|
| 13829 |
kshitij.so |
6 |
from operator import itemgetter
|
| 20313 |
kshitij.so |
7 |
from shop2020.model.v1.catalog.script import AmazonAsyncScraper
|
| 16410 |
kshitij.so |
8 |
from dtr.utils import FlipkartScraper,NewFlipkartScraper, ShopCluesScraper, \
|
| 17013 |
manish.sha |
9 |
PaytmOfferScraper, PaytmScraper, HomeShop18Scraper
|
| 14324 |
kshitij.so |
10 |
from dtr.storage.MemCache import MemCache
|
| 14334 |
kshitij.so |
11 |
from functools import partial
|
|
|
12 |
import threading
|
| 14760 |
kshitij.so |
13 |
from dtr.utils.utils import getCashBack
|
| 14794 |
kshitij.so |
14 |
import traceback
|
| 15174 |
kshitij.so |
15 |
from shop2020.config.client.ConfigClient import ConfigClient
|
| 16065 |
kshitij.so |
16 |
import chardet
|
| 16415 |
kshitij.so |
17 |
from dtr.CouponMaster import addToPaytmMaster
|
| 19210 |
kshitij.so |
18 |
from math import floor
|
| 13829 |
kshitij.so |
19 |
|
| 15174 |
kshitij.so |
20 |
config_client = ConfigClient()
|
|
|
21 |
host_memCache = config_client.get_property('mem_cache_host_dtr')
|
|
|
22 |
host = config_client.get_property('mongo_dtr_host')
|
| 14324 |
kshitij.so |
23 |
|
| 18722 |
kshitij.so |
24 |
saholicPricingHost = config_client.get_property('dtr_pricing_host')
|
|
|
25 |
|
| 15174 |
kshitij.so |
26 |
mc = MemCache(host_memCache)
|
|
|
27 |
|
|
|
28 |
|
| 15902 |
kshitij.so |
29 |
con = None
|
| 17043 |
kshitij.so |
30 |
SOURCE_MAP = {'AMAZON':1,'FLIPKART':2,'SNAPDEAL':3,'SAHOLIC':4, 'SHOPCLUES.COM':5,'PAYTM.COM':6,'HOMESHOP18':7}
|
| 13829 |
kshitij.so |
31 |
|
|
|
32 |
headers = {
|
|
|
33 |
'User-agent':'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11',
|
|
|
34 |
'Accept' : 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
|
|
|
35 |
'Accept-Language' : 'en-US,en;q=0.8',
|
|
|
36 |
'Accept-Charset' : 'ISO-8859-1,utf-8;q=0.7,*;q=0.3'
|
|
|
37 |
}
|
|
|
38 |
|
| 20313 |
kshitij.so |
39 |
amScraper = AmazonAsyncScraper.Products("AKIAII3SGRXBJDPCHSGQ", "B92xTbNBTYygbGs98w01nFQUhbec1pNCkCsKVfpg", "AF6E3O0VE0X4D")
|
|
|
40 |
marketplaceId = 'A21TJRUUN4KGV'
|
| 15608 |
kshitij.so |
41 |
|
| 15174 |
kshitij.so |
42 |
def get_mongo_connection(port=27017):
|
| 13829 |
kshitij.so |
43 |
global con
|
|
|
44 |
if con is None:
|
|
|
45 |
print "Establishing connection %s host and port %d" %(host,port)
|
|
|
46 |
try:
|
|
|
47 |
con = pymongo.MongoClient(host, port)
|
|
|
48 |
except Exception, e:
|
|
|
49 |
print e
|
|
|
50 |
return None
|
|
|
51 |
return con
|
|
|
52 |
|
| 19153 |
kshitij.so |
53 |
def calculateCashBack(data, inputPrice):
|
|
|
54 |
try:
|
|
|
55 |
cashBack = getCashBack(data['_id'], data['source_id'], data['category_id'], mc, 'localhost')
|
|
|
56 |
print "CashBack is ",cashBack
|
|
|
57 |
if not cashBack or cashBack.get('cash_back_status')!=1:
|
|
|
58 |
data['cash_back_type'] = 0
|
|
|
59 |
data['cash_back'] = 0
|
|
|
60 |
else:
|
|
|
61 |
if cashBack['cash_back_type'] in (1,2):
|
|
|
62 |
|
|
|
63 |
if cashBack.get('maxCashBack') is not None:
|
|
|
64 |
|
|
|
65 |
if cashBack.get('cash_back_type') ==1 and (float(cashBack.get('cash_back'))*data['available_price'])/100 > cashBack.get('maxCashBack'):
|
|
|
66 |
cashBack['cash_back_type'] = 2
|
|
|
67 |
cashBack['cash_back'] = cashBack['maxCashBack']
|
|
|
68 |
elif cashBack.get('cash_back_type') ==2 and cashBack.get('cash_back') > cashBack.get('maxCashBack'):
|
|
|
69 |
cashBack['cash_back'] = cashBack['maxCashBack']
|
|
|
70 |
else:
|
|
|
71 |
pass
|
|
|
72 |
|
|
|
73 |
data['cash_back_type'] = cashBack['cash_back_type']
|
|
|
74 |
data['cash_back'] = float(cashBack['cash_back'])
|
|
|
75 |
else:
|
|
|
76 |
data['cash_back_type'] = 0
|
|
|
77 |
data['cash_back'] = 0
|
|
|
78 |
except Exception as cashBackEx:
|
|
|
79 |
traceback.print_exc()
|
|
|
80 |
print "Error calculating cashback."
|
|
|
81 |
data['cash_back_type'] = 0
|
|
|
82 |
data['cash_back'] = 0
|
|
|
83 |
|
|
|
84 |
if data['cash_back_type'] == 1:
|
| 19210 |
kshitij.so |
85 |
data['netPriceAfterCashBack'] = inputPrice - floor(float(inputPrice)*data['cash_back']/100)
|
| 19153 |
kshitij.so |
86 |
elif data['cash_back_type'] == 2:
|
|
|
87 |
data['netPriceAfterCashBack'] = inputPrice - data['cash_back']
|
|
|
88 |
else:
|
|
|
89 |
data['netPriceAfterCashBack'] = inputPrice
|
|
|
90 |
|
|
|
91 |
return data
|
|
|
92 |
|
| 14828 |
kshitij.so |
93 |
def returnLatestPrice(data, source_id, ignoreLastUpdated = True):
|
| 13918 |
kshitij.so |
94 |
now = datetime.now()
|
| 13829 |
kshitij.so |
95 |
if source_id == 1:
|
|
|
96 |
try:
|
| 20313 |
kshitij.so |
97 |
if data['identifier'] is None or len(data['identifier'].strip()) !=10:
|
| 13829 |
kshitij.so |
98 |
return {}
|
| 13918 |
kshitij.so |
99 |
|
| 19153 |
kshitij.so |
100 |
if data['dealFlag'] ==1 and data['dealType'] ==1:
|
|
|
101 |
data['marketPlaceUrl'] = data['dealUrl'].strip()
|
|
|
102 |
|
|
|
103 |
|
| 16500 |
kshitij.so |
104 |
if data.get('ignorePricing') ==1:
|
| 16117 |
kshitij.so |
105 |
return {'_id':data['_id'],'available_price':data['available_price'],'in_stock':data['in_stock'],'source_id':1,'source_product_name':data['source_product_name'],'marketPlaceUrl':data['marketPlaceUrl'],'thumbnail':data['thumbnail'],'coupon':data['coupon'], 'codAvailable':data['codAvailable'], 'tagline': data['tagline'], 'offer': data['offer']}
|
| 15615 |
kshitij.so |
106 |
|
| 13918 |
kshitij.so |
107 |
try:
|
| 14828 |
kshitij.so |
108 |
if ignoreLastUpdated and data['priceUpdatedOn'] > to_java_date(now - timedelta(minutes=5)):
|
| 13918 |
kshitij.so |
109 |
print "sku id is already updated",data['_id']
|
| 16117 |
kshitij.so |
110 |
return {'_id':data['_id'],'available_price':data['available_price'],'in_stock':data['in_stock'],'source_id':1,'source_product_name':data['source_product_name'],'marketPlaceUrl':data['marketPlaceUrl'],'thumbnail':data['thumbnail'],'coupon':data['coupon'], 'codAvailable':data['codAvailable'], 'tagline': data['tagline'], 'offer': data['offer']}
|
| 13918 |
kshitij.so |
111 |
except:
|
|
|
112 |
pass
|
|
|
113 |
|
|
|
114 |
|
| 13829 |
kshitij.so |
115 |
lowestPrice = 0.0
|
| 20313 |
kshitij.so |
116 |
asinPricingMap = amScraper.get_competitive_pricing_for_asin(marketplaceId, [data['identifier'].strip().upper()])
|
| 20314 |
kshitij.so |
117 |
print "asinPricingMap ",asinPricingMap
|
| 20313 |
kshitij.so |
118 |
lowestPrice = asinPricingMap.get(data['identifier'].strip().upper())
|
| 13929 |
kshitij.so |
119 |
print "LowestPrice ",lowestPrice
|
| 13829 |
kshitij.so |
120 |
inStock = 0
|
|
|
121 |
if lowestPrice > 0:
|
|
|
122 |
inStock = 1
|
|
|
123 |
if lowestPrice > 0:
|
| 13971 |
kshitij.so |
124 |
get_mongo_connection().Catalog.MasterData.update({'_id':data['_id']}, {'$set' : {'available_price':lowestPrice,'updatedOn':to_java_date(now),'priceUpdatedOn':to_java_date(now),'in_stock':inStock}}, multi=True)
|
| 16024 |
kshitij.so |
125 |
get_mongo_connection().Catalog.Deals.update({'_id':data['_id']}, {'$set' : {'available_price':lowestPrice , 'in_stock':inStock,'dealType':data['dealType'],'codAvailable':data['codAvailable']}}, multi=True)
|
| 13829 |
kshitij.so |
126 |
else:
|
| 13929 |
kshitij.so |
127 |
lowestPrice = data['available_price']
|
| 13977 |
kshitij.so |
128 |
get_mongo_connection().Catalog.MasterData.update({'_id':data['_id']}, {'$set' : {'updatedOn':to_java_date(now),'in_stock':0,'priceUpdatedOn':to_java_date(now)}}, multi=True)
|
| 16024 |
kshitij.so |
129 |
get_mongo_connection().Catalog.Deals.update({'_id':data['_id']}, {'$set' : {'in_stock':0,'dealType':data['dealType'],'codAvailable':data['codAvailable']}}, multi=True)
|
| 13918 |
kshitij.so |
130 |
|
| 16117 |
kshitij.so |
131 |
return {'_id':data['_id'],'available_price':lowestPrice,'in_stock':inStock,'source_id':1,'source_product_name':data['source_product_name'],'marketPlaceUrl':data['marketPlaceUrl'],'thumbnail':data['thumbnail'], 'coupon':data['coupon'], 'codAvailable':data['codAvailable'], 'tagline': data['tagline'], 'offer': data['offer']}
|
| 14834 |
kshitij.so |
132 |
except Exception as e:
|
|
|
133 |
print "Exception for _id %d and source %s"%(data['_id'], source_id)
|
|
|
134 |
print e
|
| 16117 |
kshitij.so |
135 |
return {'_id':data['_id'],'available_price':data['available_price'],'in_stock':data['in_stock'],'source_id':1,'source_product_name':data['source_product_name'],'marketPlaceUrl':data['marketPlaceUrl'],'thumbnail':data['thumbnail'], 'coupon':data['coupon'], 'codAvailable':data['codAvailable'], 'tagline': data['tagline'], 'offer': data['offer']}
|
| 13829 |
kshitij.so |
136 |
|
| 14203 |
kshitij.so |
137 |
elif source_id ==4:
|
| 14207 |
kshitij.so |
138 |
|
| 14203 |
kshitij.so |
139 |
try:
|
| 14212 |
kshitij.so |
140 |
if data['identifier'] is None or len(data['identifier'].strip())==0:
|
|
|
141 |
return {}
|
|
|
142 |
|
| 16500 |
kshitij.so |
143 |
if data.get('ignorePricing') ==1:
|
| 18739 |
kshitij.so |
144 |
return {'_id':data['_id'],'available_price':data['available_price'],'in_stock':data['in_stock'],'source_id':4,'source_product_name':data['source_product_name'],'marketPlaceUrl':data['marketPlaceUrl'],'thumbnail':data['thumbnail'], 'coupon':data['coupon'], 'codAvailable':data['codAvailable'], 'tagline': data['tagline'], 'offer': data['offer'], 'packQuantity':data['quantity']}
|
| 16500 |
kshitij.so |
145 |
|
| 18722 |
kshitij.so |
146 |
# try:
|
|
|
147 |
# if ignoreLastUpdated and data['priceUpdatedOn'] > to_java_date(now - timedelta(minutes=5)):
|
|
|
148 |
# print "sku id is already updated",data['_id']
|
|
|
149 |
# return {'_id':data['_id'],'available_price':data['available_price'],'in_stock':data['in_stock'],'source_id':4,'source_product_name':data['source_product_name'],'marketPlaceUrl':data['marketPlaceUrl'],'thumbnail':data['thumbnail'], 'coupon':data['coupon'], 'codAvailable':data['codAvailable'], 'tagline': data['tagline'], 'offer': data['offer']}
|
|
|
150 |
# except:
|
|
|
151 |
# pass
|
|
|
152 |
#
|
|
|
153 |
url = "http://"+saholicPricingHost+":8080/mobileapi/dtr-pricing?id=%s"%(data['identifier'])
|
| 14212 |
kshitij.so |
154 |
lowestPrice = 0.0
|
|
|
155 |
instock = 0
|
|
|
156 |
req = urllib2.Request(url,headers=headers)
|
|
|
157 |
response = urllib2.urlopen(req)
|
|
|
158 |
json_input = response.read()
|
|
|
159 |
response.close()
|
|
|
160 |
priceInfo = json.loads(json_input)
|
| 17456 |
kshitij.so |
161 |
print "PriceInfo ",data['identifier']
|
|
|
162 |
print priceInfo
|
| 14212 |
kshitij.so |
163 |
lowestPrice = priceInfo['response']['sellingPrice']
|
| 18722 |
kshitij.so |
164 |
cheapestBulkPrice = None
|
|
|
165 |
try:
|
|
|
166 |
bulkPricing = priceInfo['response']['bulkPricing']
|
|
|
167 |
for k,v in bulkPricing.iteritems():
|
|
|
168 |
if cheapestBulkPrice is None:
|
|
|
169 |
cheapestBulkPrice = v
|
|
|
170 |
continue
|
|
|
171 |
if cheapestBulkPrice > v:
|
|
|
172 |
cheapestBulkPrice = v
|
|
|
173 |
except:
|
|
|
174 |
cheapestBulkPrice = 0
|
|
|
175 |
|
| 14212 |
kshitij.so |
176 |
if lowestPrice > 0:
|
|
|
177 |
instock = 1
|
|
|
178 |
if instock == 1:
|
|
|
179 |
get_mongo_connection().Catalog.MasterData.update({'_id':data['_id']}, {'$set' : {'available_price':lowestPrice,'updatedOn':to_java_date(now),'priceUpdatedOn':to_java_date(now),'in_stock':instock}}, multi=True)
|
| 16024 |
kshitij.so |
180 |
get_mongo_connection().Catalog.Deals.update({'_id':data['_id']}, {'$set' : {'available_price':lowestPrice , 'in_stock':instock,'codAvailable':data['codAvailable']}}, multi=True)
|
| 14212 |
kshitij.so |
181 |
else:
|
|
|
182 |
lowestPrice = data['available_price']
|
|
|
183 |
get_mongo_connection().Catalog.MasterData.update({'_id':data['_id']}, {'$set' : {'updatedOn':to_java_date(now),'in_stock':instock,'priceUpdatedOn':to_java_date(now)}}, multi=True)
|
| 16024 |
kshitij.so |
184 |
get_mongo_connection().Catalog.Deals.update({'_id':data['_id']}, {'$set' : {'in_stock':instock,'codAvailable':data['codAvailable']}}, multi=True)
|
| 14212 |
kshitij.so |
185 |
|
| 18739 |
kshitij.so |
186 |
return {'_id':data['_id'],'available_price':lowestPrice,'in_stock':instock,'source_id':4,'source_product_name':data['source_product_name'],'marketPlaceUrl':data['marketPlaceUrl'],'thumbnail':data['thumbnail'],'coupon':data['coupon'], 'codAvailable':data['codAvailable'],'tagline': data['tagline'], 'offer': data['offer'], 'cheapestBulkPrice': cheapestBulkPrice, 'packQuantity':data['quantity']}
|
| 14834 |
kshitij.so |
187 |
|
|
|
188 |
except Exception as e:
|
|
|
189 |
print "Exception for _id %d and source %s"%(data['_id'], source_id)
|
|
|
190 |
print e
|
| 18739 |
kshitij.so |
191 |
return {'_id':data['_id'],'available_price':data['available_price'],'in_stock':data['in_stock'],'source_id':4,'source_product_name':data['source_product_name'],'marketPlaceUrl':data['marketPlaceUrl'],'thumbnail':data['thumbnail'],'coupon':data['coupon'], 'codAvailable':data['codAvailable'],'tagline': data['tagline'], 'offer': data['offer'],'packQuantity':data['quantity']}
|
| 14203 |
kshitij.so |
192 |
|
| 14207 |
kshitij.so |
193 |
|
| 13829 |
kshitij.so |
194 |
elif source_id ==3:
|
|
|
195 |
try:
|
| 13918 |
kshitij.so |
196 |
if data['identifier'] is None or len(data['identifier'].strip())==0:
|
| 13829 |
kshitij.so |
197 |
return {}
|
| 13918 |
kshitij.so |
198 |
|
| 16500 |
kshitij.so |
199 |
if data.get('ignorePricing') ==1:
|
| 16206 |
kshitij.so |
200 |
print "Ignored items returning for %d"%(data['_id'])
|
| 16265 |
kshitij.so |
201 |
return {'_id':data['_id'],'available_price':data['available_price'],'in_stock':data['in_stock'],'source_id':3,'source_product_name':data['source_product_name'],'marketPlaceUrl':data['marketPlaceUrl'],'thumbnail':data['thumbnail'],'coupon':data['coupon'], 'codAvailable':data['codAvailable'], 'tagline': data['tagline'], 'offer': data['offer']}
|
| 16206 |
kshitij.so |
202 |
|
| 13918 |
kshitij.so |
203 |
try:
|
| 14828 |
kshitij.so |
204 |
if ignoreLastUpdated and data['priceUpdatedOn'] > to_java_date(now - timedelta(minutes=5)):
|
| 13920 |
kshitij.so |
205 |
print "sku id is already updated",data['_id']
|
| 16205 |
kshitij.so |
206 |
return {'_id':data['_id'],'available_price':data['available_price'],'in_stock':data['in_stock'],'source_id':3,'source_product_name':data['source_product_name'],'marketPlaceUrl':data['marketPlaceUrl'],'thumbnail':data['thumbnail'],'coupon':data['coupon'], 'codAvailable':data['codAvailable'],'tagline': data['tagline'], 'offer': data['offer']}
|
| 13919 |
kshitij.so |
207 |
|
|
|
208 |
except Exception as e:
|
| 13920 |
kshitij.so |
209 |
print "Exception snapdeal"
|
| 13919 |
kshitij.so |
210 |
print e
|
| 13918 |
kshitij.so |
211 |
|
| 20382 |
kshitij.so |
212 |
url="https://m.snapdeal.com/snap/product/getRefreshProductDetails?supc=%s"%(data['identifier'])
|
| 13829 |
kshitij.so |
213 |
req = urllib2.Request(url,headers=headers)
|
|
|
214 |
response = urllib2.urlopen(req)
|
| 16065 |
kshitij.so |
215 |
snapdeal_data = response.read()
|
|
|
216 |
encoding = chardet.detect(snapdeal_data)
|
|
|
217 |
try:
|
|
|
218 |
snapdeal_data = snapdeal_data.decode(encoding.get('encoding'))
|
|
|
219 |
except:
|
|
|
220 |
snapdeal_data = snapdeal_data.decode(encoding.get('latin-1'))
|
| 20382 |
kshitij.so |
221 |
vendor_data = json.loads(snapdeal_data)
|
| 14188 |
kshitij.so |
222 |
response.close()
|
| 13829 |
kshitij.so |
223 |
lowestOfferPrice = 0
|
|
|
224 |
inStock = 0
|
| 15253 |
kshitij.so |
225 |
buyBoxPrice = 0
|
|
|
226 |
isBuyBox = 1
|
| 15819 |
kshitij.so |
227 |
try:
|
| 20382 |
kshitij.so |
228 |
buyBoxStock = int(vendor_data['vendorDtlSRO']['vendorDetailInventoryPricingSRO']['buyableInventory'])
|
|
|
229 |
soldOut = vendor_data['vendorDtlSRO']['vendorDetailInventoryPricingSRO']['soldOut']
|
|
|
230 |
inStock = 1 if not soldOut else 0
|
| 15819 |
kshitij.so |
231 |
if buyBoxStock >0:
|
| 20382 |
kshitij.so |
232 |
buyBoxPrice = float(vendor_data['vendorDtlSRO']['finalPrice'])
|
|
|
233 |
|
|
|
234 |
lowestOfferPrice = float(vendor_data['auxiliarySellerInfo']['priceStartRange'])
|
| 15819 |
kshitij.so |
235 |
except:
|
|
|
236 |
pass
|
| 13829 |
kshitij.so |
237 |
|
|
|
238 |
print lowestOfferPrice
|
|
|
239 |
print inStock
|
|
|
240 |
print "*************"
|
| 15253 |
kshitij.so |
241 |
|
|
|
242 |
if buyBoxPrice != lowestOfferPrice:
|
|
|
243 |
isBuyBox = 0
|
|
|
244 |
|
| 13829 |
kshitij.so |
245 |
if inStock == 1:
|
| 15253 |
kshitij.so |
246 |
get_mongo_connection().Catalog.MasterData.update({'_id':data['_id']}, {'$set' : {'available_price':lowestOfferPrice,'updatedOn':to_java_date(now),'priceUpdatedOn':to_java_date(now),'in_stock':inStock,'buyBoxFlag':isBuyBox}}, multi=True)
|
| 16024 |
kshitij.so |
247 |
get_mongo_connection().Catalog.Deals.update({'_id':data['_id']}, {'$set' : {'available_price':lowestOfferPrice , 'in_stock':inStock,'codAvailable':data['codAvailable']}}, multi=True)
|
| 13829 |
kshitij.so |
248 |
else:
|
| 13929 |
kshitij.so |
249 |
lowestOfferPrice = data['available_price']
|
| 15253 |
kshitij.so |
250 |
get_mongo_connection().Catalog.MasterData.update({'_id':data['_id']}, {'$set' : {'updatedOn':to_java_date(now),'in_stock':inStock,'priceUpdatedOn':to_java_date(now),'buyBoxFlag':isBuyBox}}, multi=True)
|
| 16024 |
kshitij.so |
251 |
get_mongo_connection().Catalog.Deals.update({'_id':data['_id']}, {'$set' : {'in_stock':inStock,'codAvailable':data['codAvailable']}}, multi=True)
|
| 13918 |
kshitij.so |
252 |
|
| 16117 |
kshitij.so |
253 |
return {'_id':data['_id'],'available_price':lowestOfferPrice,'in_stock':inStock,'source_id':3,'source_product_name':data['source_product_name'],'marketPlaceUrl':data['marketPlaceUrl'],'thumbnail':data['thumbnail'],'coupon':data['coupon'], 'codAvailable':data['codAvailable'], 'tagline': data['tagline'], 'offer': data['offer']}
|
| 14834 |
kshitij.so |
254 |
except Exception as e:
|
| 15266 |
kshitij.so |
255 |
print traceback.print_exc()
|
| 14834 |
kshitij.so |
256 |
print "Exception for _id %d and source %s"%(data['_id'], source_id)
|
|
|
257 |
print e
|
| 16117 |
kshitij.so |
258 |
return {'_id':data['_id'],'available_price':data['available_price'],'in_stock':data['in_stock'],'source_id':3,'source_product_name':data['source_product_name'],'marketPlaceUrl':data['marketPlaceUrl'],'thumbnail':data['thumbnail'],'coupon':data['coupon'], 'codAvailable':data['codAvailable'], 'tagline': data['tagline'], 'offer': data['offer']}
|
| 13829 |
kshitij.so |
259 |
|
|
|
260 |
elif source_id == 2:
|
|
|
261 |
try:
|
| 13918 |
kshitij.so |
262 |
if data['identifier'] is None or len(data['identifier'].strip())==0:
|
| 13829 |
kshitij.so |
263 |
return {}
|
| 13918 |
kshitij.so |
264 |
|
| 16500 |
kshitij.so |
265 |
if data.get('ignorePricing') ==1:
|
| 15608 |
kshitij.so |
266 |
print "Ignored items returning for %d"%(data['_id'])
|
| 16117 |
kshitij.so |
267 |
return {'_id':data['_id'],'available_price':data['available_price'],'in_stock':data['in_stock'],'source_id':2,'source_product_name':data['source_product_name'],'marketPlaceUrl':data['marketPlaceUrl'],'thumbnail':data['thumbnail'],'coupon':data['coupon'], 'codAvailable':data['codAvailable'], 'tagline': data['tagline'], 'offer': data['offer']}
|
| 15608 |
kshitij.so |
268 |
|
| 13918 |
kshitij.so |
269 |
try:
|
| 14828 |
kshitij.so |
270 |
if ignoreLastUpdated and data['priceUpdatedOn'] > to_java_date(now - timedelta(minutes=5)):
|
| 13918 |
kshitij.so |
271 |
print "sku id is already updated",data['_id']
|
| 16117 |
kshitij.so |
272 |
return {'_id':data['_id'],'available_price':data['available_price'],'in_stock':data['in_stock'],'source_id':2,'source_product_name':data['source_product_name'],'marketPlaceUrl':data['marketPlaceUrl'],'thumbnail':data['thumbnail'],'coupon':data['coupon'], 'codAvailable':data['codAvailable'], 'tagline': data['tagline'], 'offer': data['offer']}
|
| 13918 |
kshitij.so |
273 |
except:
|
|
|
274 |
pass
|
|
|
275 |
|
|
|
276 |
lowestSp = 0
|
|
|
277 |
inStock = 0
|
| 15253 |
kshitij.so |
278 |
buyBoxPrice = 0
|
|
|
279 |
isBuyBox = 0
|
| 14189 |
kshitij.so |
280 |
scraperProductPage = NewFlipkartScraper.FlipkartProductPageScraper()
|
| 14121 |
kshitij.so |
281 |
try:
|
| 17262 |
kshitij.so |
282 |
result = scraperProductPage.read(data['identifier'])
|
|
|
283 |
print result
|
|
|
284 |
if result.get('lowestSp')!=0:
|
|
|
285 |
lowestSp = result.get('lowestSp')
|
|
|
286 |
inStock = result.get('inStock')
|
|
|
287 |
buyBoxPrice = result.get('buyBoxPrice')
|
| 14121 |
kshitij.so |
288 |
except:
|
|
|
289 |
print "Unable to scrape product page ",data['identifier']
|
| 13829 |
kshitij.so |
290 |
print lowestSp
|
|
|
291 |
print inStock
|
| 15253 |
kshitij.so |
292 |
if buyBoxPrice is not None and buyBoxPrice == lowestSp:
|
|
|
293 |
isBuyBox = 1
|
| 13829 |
kshitij.so |
294 |
if lowestSp > 0:
|
| 15253 |
kshitij.so |
295 |
get_mongo_connection().Catalog.MasterData.update({'_id':data['_id']}, {'$set' : {'available_price':lowestSp,'updatedOn':to_java_date(now),'priceUpdatedOn':to_java_date(now),'in_stock':inStock,'buyBoxFlag':isBuyBox}}, multi=True)
|
| 16024 |
kshitij.so |
296 |
get_mongo_connection().Catalog.Deals.update({'_id':data['_id']}, {'$set' : {'available_price':lowestSp , 'in_stock':inStock,'codAvailable':data['codAvailable']}}, multi=True)
|
| 13829 |
kshitij.so |
297 |
else:
|
| 13929 |
kshitij.so |
298 |
lowestSp = data['available_price']
|
| 15253 |
kshitij.so |
299 |
get_mongo_connection().Catalog.MasterData.update({'_id':data['_id']}, {'$set' : {'updatedOn':to_java_date(now),'in_stock':inStock,'priceUpdatedOn':to_java_date(now),'buyBoxFlag':isBuyBox}}, multi=True)
|
| 16024 |
kshitij.so |
300 |
get_mongo_connection().Catalog.Deals.update({'_id':data['_id']}, {'$set' : {'in_stock':inStock,'codAvailable':data['codAvailable']}}, multi=True)
|
| 13918 |
kshitij.so |
301 |
|
| 16117 |
kshitij.so |
302 |
return {'_id':data['_id'],'available_price':lowestSp,'in_stock':inStock,'source_id':2,'source_product_name':data['source_product_name'],'marketPlaceUrl':data['marketPlaceUrl'],'thumbnail':data['thumbnail'],'coupon':data['coupon'], 'codAvailable':data['codAvailable'], 'tagline': data['tagline'], 'offer': data['offer']}
|
| 14342 |
kshitij.so |
303 |
|
| 14834 |
kshitij.so |
304 |
except Exception as e:
|
|
|
305 |
print "Exception for _id %d and source %s"%(data['_id'], source_id)
|
|
|
306 |
print e
|
| 16117 |
kshitij.so |
307 |
return {'_id':data['_id'],'available_price':data['available_price'],'in_stock':data['in_stock'],'source_id':2,'source_product_name':data['source_product_name'],'marketPlaceUrl':data['marketPlaceUrl'],'thumbnail':data['thumbnail'],'coupon':data['coupon'], 'codAvailable':data['codAvailable'], 'tagline': data['tagline'], 'offer': data['offer']}
|
| 15902 |
kshitij.so |
308 |
|
|
|
309 |
elif source_id == 5:
|
|
|
310 |
try:
|
| 16500 |
kshitij.so |
311 |
if data.get('ignorePricing') ==1:
|
| 15902 |
kshitij.so |
312 |
print "Ignored items returning for %d"%(data['_id'])
|
| 16117 |
kshitij.so |
313 |
return {'_id':data['_id'],'available_price':data['available_price'],'in_stock':data['in_stock'],'source_id':5,'source_product_name':data['source_product_name'],'marketPlaceUrl':data['marketPlaceUrl'],'thumbnail':data['thumbnail'],'coupon':data['coupon'], 'codAvailable':data['codAvailable'], 'tagline': data['tagline'], 'offer': data['offer']}
|
| 15902 |
kshitij.so |
314 |
|
|
|
315 |
try:
|
|
|
316 |
if ignoreLastUpdated and data['priceUpdatedOn'] > to_java_date(now - timedelta(minutes=5)):
|
|
|
317 |
print "sku id is already updated",data['_id']
|
| 16117 |
kshitij.so |
318 |
return {'_id':data['_id'],'available_price':data['available_price'],'in_stock':data['in_stock'],'source_id':5,'source_product_name':data['source_product_name'],'marketPlaceUrl':data['marketPlaceUrl'],'thumbnail':data['thumbnail'],'coupon':data['coupon'], 'codAvailable':data['codAvailable'], 'tagline': data['tagline'], 'offer': data['offer']}
|
| 15902 |
kshitij.so |
319 |
except:
|
|
|
320 |
pass
|
|
|
321 |
|
|
|
322 |
|
|
|
323 |
url = data['marketPlaceUrl']
|
|
|
324 |
lowestPrice = 0.0
|
|
|
325 |
try:
|
|
|
326 |
sc = ShopCluesScraper.ShopCluesScraper()
|
| 15951 |
kshitij.so |
327 |
url = transformUrl(url, 5)
|
| 15902 |
kshitij.so |
328 |
productInfo = sc.read(url)
|
|
|
329 |
except Exception as e:
|
| 16177 |
kshitij.so |
330 |
traceback.print_exc()
|
| 16176 |
kshitij.so |
331 |
productInfo = {}
|
| 16022 |
kshitij.so |
332 |
productInfo['price'] = 0.0
|
|
|
333 |
productInfo['inStock'] = 0
|
|
|
334 |
productInfo['isCod'] = 0
|
| 16178 |
kshitij.so |
335 |
productInfo['coupon'] = ""
|
| 16022 |
kshitij.so |
336 |
|
| 15902 |
kshitij.so |
337 |
print "LowestPrice ",productInfo['price']
|
|
|
338 |
if productInfo['price'] > 0 and productInfo['inStock']==1:
|
|
|
339 |
get_mongo_connection().Catalog.MasterData.update({'_id':data['_id']}, {'$set' : {'available_price':productInfo['price'],'coupon':productInfo['coupon'],'codAvailable':productInfo['isCod'],'updatedOn':to_java_date(now),'priceUpdatedOn':to_java_date(now),'in_stock':productInfo['inStock']}})
|
| 16024 |
kshitij.so |
340 |
get_mongo_connection().Catalog.Deals.update({'_id':data['_id']}, {'$set' : {'available_price':productInfo['price'] , 'in_stock':productInfo['inStock'],'dealType':data['dealType'], 'rank':data['rank'],'codAvailable':productInfo['isCod']}})
|
| 15902 |
kshitij.so |
341 |
else:
|
|
|
342 |
lowestPrice = data['available_price']
|
|
|
343 |
get_mongo_connection().Catalog.MasterData.update({'_id':data['_id']}, {'$set' : {'updatedOn':to_java_date(now),'in_stock':0,'priceUpdatedOn':to_java_date(now)}})
|
| 16024 |
kshitij.so |
344 |
get_mongo_connection().Catalog.Deals.update({'_id':data['_id']}, {'$set' : {'in_stock':0,'dealType':data['dealType'],'rank':data['rank'],'codAvailable':productInfo['isCod']}})
|
| 15902 |
kshitij.so |
345 |
|
| 16117 |
kshitij.so |
346 |
return {'_id':data['_id'],'available_price':productInfo['price'],'in_stock':productInfo['inStock'],'source_id':5,'source_product_name':data['source_product_name'],'marketPlaceUrl':data['marketPlaceUrl'],'thumbnail':data['thumbnail'], 'coupon':productInfo['coupon'],'codAvailable':productInfo['isCod'], 'tagline': data['tagline'], 'offer': data['offer']}
|
| 15902 |
kshitij.so |
347 |
except Exception as e:
|
|
|
348 |
print "Exception for _id %d and source %s"%(data['_id'], source_id)
|
| 16177 |
kshitij.so |
349 |
traceback.print_exc()
|
| 16117 |
kshitij.so |
350 |
return {'_id':data['_id'],'available_price':data['available_price'],'in_stock':data['in_stock'],'source_id':5,'source_product_name':data['source_product_name'],'marketPlaceUrl':data['marketPlaceUrl'],'thumbnail':data['thumbnail'],'coupon':data['coupon'], 'codAvailable':data['codAvailable'], 'tagline': data['tagline'], 'offer': data['offer']}
|
| 16410 |
kshitij.so |
351 |
|
|
|
352 |
elif source_id == 6:
|
|
|
353 |
try:
|
| 16500 |
kshitij.so |
354 |
if data.get('ignorePricing') ==1:
|
| 16410 |
kshitij.so |
355 |
print "Ignored items returning for %d"%(data['_id'])
|
| 16491 |
kshitij.so |
356 |
return {'_id':data['_id'],'available_price':data['available_price'],'in_stock':data['in_stock'],'source_id':6,'source_product_name':data['source_product_name'],'marketPlaceUrl':data['marketPlaceUrl'],'thumbnail':data['thumbnail'],'coupon':data['coupon'], 'codAvailable':data['codAvailable'], 'tagline': data['tagline'], 'offer': data['offer'],'gross_price':data.get('gross_price')}
|
| 16410 |
kshitij.so |
357 |
|
|
|
358 |
try:
|
|
|
359 |
if ignoreLastUpdated and data['priceUpdatedOn'] > to_java_date(now - timedelta(minutes=5)):
|
|
|
360 |
print "sku id is already updated",data['_id']
|
| 16491 |
kshitij.so |
361 |
return {'_id':data['_id'],'available_price':data['available_price'],'in_stock':data['in_stock'],'source_id':6,'source_product_name':data['source_product_name'],'marketPlaceUrl':data['marketPlaceUrl'],'thumbnail':data['thumbnail'],'coupon':data['coupon'], 'codAvailable':data['codAvailable'], 'tagline': data['tagline'], 'offer': data['offer'],'gross_price':data.get('gross_price')}
|
| 16410 |
kshitij.so |
362 |
except:
|
|
|
363 |
pass
|
|
|
364 |
|
|
|
365 |
paytmScraper = PaytmScraper.PaytmScraper()
|
|
|
366 |
url = "https://catalog.paytm.com/v1/mobile/product/%s"%(data['identifier'].strip())
|
|
|
367 |
try:
|
|
|
368 |
result = paytmScraper.read(url)
|
| 18282 |
kshitij.so |
369 |
print result
|
| 16410 |
kshitij.so |
370 |
effective_price = result.get('offerPrice')
|
| 16462 |
kshitij.so |
371 |
gross_price = effective_price
|
| 18282 |
kshitij.so |
372 |
shareUrl = result.get('shareUrl')
|
|
|
373 |
if shareUrl is None:
|
|
|
374 |
shareUrl = data['marketPlaceUrl']
|
| 16410 |
kshitij.so |
375 |
coupon = ""
|
|
|
376 |
try:
|
|
|
377 |
offers = PaytmOfferScraper.fetchOffers(result['offerUrl'])
|
|
|
378 |
bestOffer = {}
|
|
|
379 |
for offer_data in offers.get('codes'):
|
| 16415 |
kshitij.so |
380 |
if effective_price > offer_data.get('effective_price'):
|
| 16410 |
kshitij.so |
381 |
effective_price = offer_data.get('effective_price')
|
|
|
382 |
bestOffer = offer_data
|
|
|
383 |
coupon = bestOffer.get('code')
|
|
|
384 |
except:
|
|
|
385 |
pass
|
| 16469 |
kshitij.so |
386 |
|
|
|
387 |
"""Temp fix"""
|
|
|
388 |
if len(coupon) > 0:
|
|
|
389 |
result['codAvailable'] = 0
|
|
|
390 |
|
| 16410 |
kshitij.so |
391 |
available_price = effective_price
|
|
|
392 |
if result['inStock']:
|
|
|
393 |
inStock = 1
|
| 18282 |
kshitij.so |
394 |
get_mongo_connection().Catalog.MasterData.update({'_id':data['_id']}, {'$set' : {'available_price':available_price,'updatedOn':to_java_date(datetime.now()),'priceUpdatedOn':to_java_date(datetime.now()),'in_stock':1,'buyBoxFlag':1,'codAvailable':result.get('codAvailable'),'coupon':coupon,'gross_price':gross_price,'marketPlaceUrl':shareUrl}})
|
| 16462 |
kshitij.so |
395 |
get_mongo_connection().Catalog.Deals.update({'_id':data['_id']}, {'$set' : {'available_price':available_price , 'in_stock':1,'codAvailable':result.get('codAvailable'),'gross_price':gross_price}})
|
| 16410 |
kshitij.so |
396 |
else:
|
|
|
397 |
inStock = 0
|
| 18282 |
kshitij.so |
398 |
get_mongo_connection().Catalog.MasterData.update({'_id':data['_id']}, {'$set' : {'updatedOn':to_java_date(datetime.now()),'in_stock':0,'priceUpdatedOn':to_java_date(datetime.now()),'buyBoxFlag':1,'codAvailable':result.get('codAvailable'),'coupon':coupon,'marketPlaceUrl':shareUrl}})
|
| 16415 |
kshitij.so |
399 |
get_mongo_connection().Catalog.Deals.update({'_id':data['_id']}, {'$set' : {'in_stock':0,'codAvailable':result.get('codAvailable')}})
|
| 16410 |
kshitij.so |
400 |
|
|
|
401 |
except:
|
|
|
402 |
inStock = 0
|
|
|
403 |
get_mongo_connection().Catalog.MasterData.update({'_id':data['_id']}, {'$set' : {'updatedOn':to_java_date(datetime.now()),'in_stock':0,'priceUpdatedOn':to_java_date(datetime.now()),'buyBoxFlag':1}})
|
|
|
404 |
get_mongo_connection().Catalog.Deals.update({'_id':data['_id']}, {'$set' : {'in_stock':0}})
|
|
|
405 |
|
|
|
406 |
|
| 18282 |
kshitij.so |
407 |
return {'_id':data['_id'],'available_price':available_price,'in_stock':inStock,'source_id':6,'source_product_name':data['source_product_name'],'marketPlaceUrl':shareUrl,'thumbnail':data['thumbnail'], 'coupon':coupon,'codAvailable':result['codAvailable'], 'tagline': data['tagline'], 'offer': data['offer'],'gross_price':gross_price}
|
| 16410 |
kshitij.so |
408 |
except Exception as e:
|
|
|
409 |
print "Exception for _id %d and source %s"%(data['_id'], source_id)
|
|
|
410 |
traceback.print_exc()
|
| 16462 |
kshitij.so |
411 |
return {'_id':data['_id'],'available_price':data['available_price'],'in_stock':data['in_stock'],'source_id':6,'source_product_name':data['source_product_name'],'marketPlaceUrl':data['marketPlaceUrl'],'thumbnail':data['thumbnail'],'coupon':data['coupon'], 'codAvailable':data['codAvailable'], 'tagline': data['tagline'], 'offer': data['offer'],'gross_price':data.get('gross_price')}
|
| 17013 |
manish.sha |
412 |
|
|
|
413 |
elif source_id ==7:
|
|
|
414 |
try:
|
|
|
415 |
if data['identifier'] is None or len(data['identifier'].strip())==0:
|
|
|
416 |
return {}
|
|
|
417 |
|
|
|
418 |
if data.get('ignorePricing') ==1:
|
|
|
419 |
print "Ignored items returning for %d"%(data['_id'])
|
|
|
420 |
return {'_id':data['_id'],'available_price':data['available_price'],'in_stock':data['in_stock'],'source_id':7,'source_product_name':data['source_product_name'],'marketPlaceUrl':data['marketPlaceUrl'],'thumbnail':data['thumbnail'],'coupon':data['coupon'], 'codAvailable':data['codAvailable'], 'tagline': data['tagline'], 'offer': data['offer']}
|
|
|
421 |
|
|
|
422 |
try:
|
|
|
423 |
if ignoreLastUpdated and data['priceUpdatedOn'] > to_java_date(now - timedelta(minutes=5)):
|
|
|
424 |
print "sku id is already updated",data['_id']
|
|
|
425 |
return {'_id':data['_id'],'available_price':data['available_price'],'in_stock':data['in_stock'],'source_id':7,'source_product_name':data['source_product_name'],'marketPlaceUrl':data['marketPlaceUrl'],'thumbnail':data['thumbnail'],'coupon':data['coupon'], 'codAvailable':data['codAvailable'],'tagline': data['tagline'], 'offer': data['offer']}
|
|
|
426 |
|
|
|
427 |
except Exception as e:
|
|
|
428 |
print "Exception snapdeal"
|
|
|
429 |
print e
|
|
|
430 |
|
|
|
431 |
response = None
|
|
|
432 |
|
|
|
433 |
try:
|
| 17043 |
kshitij.so |
434 |
scraper = HomeShop18Scraper.HomeShop18Scraper()
|
| 17013 |
manish.sha |
435 |
response = scraper.read('http://m.homeshop18.com/product.mobi?productId=%s'%(str(data['identifier'])))
|
|
|
436 |
except Exception as e:
|
|
|
437 |
print e
|
| 17043 |
kshitij.so |
438 |
scraper = HomeShop18Scraper.HomeShop18Scraper()
|
| 17013 |
manish.sha |
439 |
response = scraper.read('http://m.homeshop18.com/product.mobi?productId=%s'%(str(data['identifier'])))
|
|
|
440 |
|
|
|
441 |
lowestOfferPrice = 0
|
|
|
442 |
inStock = 0
|
|
|
443 |
|
|
|
444 |
if response is not None:
|
| 17043 |
kshitij.so |
445 |
lowestOfferPrice = float(response['price']+response['shippingCharge'])
|
| 17013 |
manish.sha |
446 |
inStock = response['inStock']
|
|
|
447 |
|
|
|
448 |
print lowestOfferPrice
|
|
|
449 |
print inStock
|
|
|
450 |
print "*************"
|
|
|
451 |
|
| 17036 |
kshitij.so |
452 |
if lowestOfferPrice ==0:
|
|
|
453 |
inStock = 0
|
| 17013 |
manish.sha |
454 |
|
| 17036 |
kshitij.so |
455 |
|
| 17013 |
manish.sha |
456 |
if inStock == 1:
|
| 17036 |
kshitij.so |
457 |
get_mongo_connection().Catalog.MasterData.update({'_id':data['_id']}, {'$set' : {'available_price':lowestOfferPrice,'updatedOn':to_java_date(now),'priceUpdatedOn':to_java_date(now),'in_stock':inStock}}, multi=True)
|
| 17013 |
manish.sha |
458 |
get_mongo_connection().Catalog.Deals.update({'_id':data['_id']}, {'$set' : {'available_price':lowestOfferPrice , 'in_stock':inStock,'codAvailable':data['codAvailable']}}, multi=True)
|
|
|
459 |
else:
|
|
|
460 |
lowestOfferPrice = data['available_price']
|
| 17036 |
kshitij.so |
461 |
get_mongo_connection().Catalog.MasterData.update({'_id':data['_id']}, {'$set' : {'updatedOn':to_java_date(now),'in_stock':inStock,'priceUpdatedOn':to_java_date(now)}}, multi=True)
|
| 17013 |
manish.sha |
462 |
get_mongo_connection().Catalog.Deals.update({'_id':data['_id']}, {'$set' : {'in_stock':inStock,'codAvailable':data['codAvailable']}}, multi=True)
|
|
|
463 |
|
|
|
464 |
return {'_id':data['_id'],'available_price':lowestOfferPrice,'in_stock':inStock,'source_id':7,'source_product_name':data['source_product_name'],'marketPlaceUrl':data['marketPlaceUrl'],'thumbnail':data['thumbnail'],'coupon':data['coupon'], 'codAvailable':data['codAvailable'], 'tagline': data['tagline'], 'offer': data['offer']}
|
|
|
465 |
except Exception as e:
|
|
|
466 |
print traceback.print_exc()
|
|
|
467 |
print "Exception for _id %d and source %s"%(data['_id'], source_id)
|
|
|
468 |
print e
|
|
|
469 |
return {'_id':data['_id'],'available_price':data['available_price'],'in_stock':data['in_stock'],'source_id':7,'source_product_name':data['source_product_name'],'marketPlaceUrl':data['marketPlaceUrl'],'thumbnail':data['thumbnail'],'coupon':data['coupon'], 'codAvailable':data['codAvailable'], 'tagline': data['tagline'], 'offer': data['offer']}
|
| 15902 |
kshitij.so |
470 |
|
| 13829 |
kshitij.so |
471 |
else:
|
|
|
472 |
return {}
|
| 15902 |
kshitij.so |
473 |
|
|
|
474 |
|
| 13918 |
kshitij.so |
475 |
|
| 16498 |
kshitij.so |
476 |
def recomputePoints(deal):
|
| 15253 |
kshitij.so |
477 |
try:
|
| 16498 |
kshitij.so |
478 |
nlcPoints = getNlcPoints(deal)
|
| 15253 |
kshitij.so |
479 |
except:
|
| 16498 |
kshitij.so |
480 |
traceback.print_exc()
|
| 15253 |
kshitij.so |
481 |
nlcPoints = deal['nlcPoints']
|
| 16498 |
kshitij.so |
482 |
|
|
|
483 |
bundleDealPoints = list(get_mongo_connection().Catalog.DealPoints.find({'skuBundleId':deal['skuBundleId'],'startDate':{'$lte':to_java_date(datetime.now())},'endDate':{'$gte':to_java_date(datetime.now())}}))
|
|
|
484 |
if len(bundleDealPoints) > 0:
|
|
|
485 |
manualDealThresholdPrice = bundleDealPoints[0]['dealThresholdPrice']
|
|
|
486 |
dealPoints = bundleDealPoints[0]['dealPoints']
|
| 15253 |
kshitij.so |
487 |
else:
|
|
|
488 |
dealPoints = 0
|
| 16498 |
kshitij.so |
489 |
manualDealThresholdPrice = None
|
| 16508 |
kshitij.so |
490 |
|
|
|
491 |
if deal['available_price'] > manualDealThresholdPrice:
|
|
|
492 |
dealPoints = 0
|
|
|
493 |
|
| 16498 |
kshitij.so |
494 |
|
|
|
495 |
if dealPoints != deal['dealPoints'] or manualDealThresholdPrice != deal['manualDealThresholdPrice'] or nlcPoints != deal['nlcPoints']:
|
|
|
496 |
get_mongo_connection().Catalog.Deals.update({'_id':deal['_id']},{"$set":{'totalPoints':deal['totalPoints'] - deal['nlcPoints'] + nlcPoints - deal['dealPoints'] +dealPoints , 'nlcPoints': nlcPoints, 'dealPoints': dealPoints, 'manualDealThresholdPrice': manualDealThresholdPrice}})
|
| 15253 |
kshitij.so |
497 |
|
| 15266 |
kshitij.so |
498 |
|
|
|
499 |
def populateNegativeDeals():
|
|
|
500 |
negativeDeals = get_mongo_connection().Catalog.NegativeDeals.find().distinct('sku')
|
|
|
501 |
mc.set("negative_deals", negativeDeals, 600)
|
|
|
502 |
|
|
|
503 |
def recomputeDeal(item):
|
| 16017 |
kshitij.so |
504 |
|
| 13918 |
kshitij.so |
505 |
"""Lets recompute deal for this bundle"""
|
| 15266 |
kshitij.so |
506 |
print "Recomputing for bundleId",item.get('skuBundleId')
|
|
|
507 |
skuBundleId = item['skuBundleId']
|
| 13829 |
kshitij.so |
508 |
|
| 19153 |
kshitij.so |
509 |
similarItems = list(get_mongo_connection().Catalog.Deals.find({'skuBundleId':skuBundleId}).sort([('netPriceAfterCashBack',pymongo.ASCENDING)]))
|
| 13918 |
kshitij.so |
510 |
bestPrice = float("inf")
|
|
|
511 |
bestOne = None
|
|
|
512 |
toUpdate = []
|
| 16017 |
kshitij.so |
513 |
prepaidBestPrice = float("inf")
|
|
|
514 |
prepaidBestOne = None
|
| 13918 |
kshitij.so |
515 |
for similarItem in similarItems:
|
| 16498 |
kshitij.so |
516 |
try:
|
|
|
517 |
recomputePoints(similarItem)
|
|
|
518 |
except:
|
|
|
519 |
traceback.print_exc()
|
| 16017 |
kshitij.so |
520 |
if similarItem['codAvailable'] ==1:
|
|
|
521 |
if mc.get("negative_deals") is None:
|
|
|
522 |
populateNegativeDeals()
|
| 16172 |
kshitij.so |
523 |
if similarItem['in_stock'] == 0 or similarItem['_id'] in mc.get("negative_deals"):
|
| 16017 |
kshitij.so |
524 |
get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0, 'prepaidDeal':0 }})
|
|
|
525 |
continue
|
| 17674 |
kshitij.so |
526 |
if similarItem['source_id'] == SOURCE_MAP.get('SHOPCLUES.COM') and similarItem['rank']==0 and similarItem['category_id']!=6:
|
| 16017 |
kshitij.so |
527 |
get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0,'prepaidDeal':0 }})
|
|
|
528 |
continue
|
| 19153 |
kshitij.so |
529 |
if similarItem['netPriceAfterCashBack'] < bestPrice:
|
| 16017 |
kshitij.so |
530 |
bestOne = similarItem
|
| 19153 |
kshitij.so |
531 |
bestPrice = similarItem['netPriceAfterCashBack']
|
| 20347 |
kshitij.so |
532 |
elif similarItem['netPriceAfterCashBack'] == bestPrice:
|
|
|
533 |
|
|
|
534 |
try:
|
|
|
535 |
if (DEAL_PRIORITY.index(int(similarItem['source_id'])) > DEAL_PRIORITY.index(int(bestOne['source_id']))):
|
|
|
536 |
continue
|
|
|
537 |
except:
|
|
|
538 |
traceback.print_exc()
|
|
|
539 |
|
| 16017 |
kshitij.so |
540 |
bestOne = similarItem
|
| 19153 |
kshitij.so |
541 |
bestPrice = similarItem['netPriceAfterCashBack']
|
| 16017 |
kshitij.so |
542 |
else:
|
|
|
543 |
pass
|
| 13918 |
kshitij.so |
544 |
else:
|
| 16017 |
kshitij.so |
545 |
if mc.get("negative_deals") is None:
|
|
|
546 |
populateNegativeDeals()
|
| 16172 |
kshitij.so |
547 |
if similarItem['in_stock'] == 0 or similarItem['_id'] in mc.get("negative_deals"):
|
| 16017 |
kshitij.so |
548 |
get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0, 'prepaidDeal':0 }})
|
|
|
549 |
continue
|
| 17751 |
kshitij.so |
550 |
if similarItem['source_id'] == SOURCE_MAP.get('SHOPCLUES.COM') and similarItem['rank']==0 and similarItem['category_id']!=6:
|
| 16017 |
kshitij.so |
551 |
get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0,'prepaidDeal':0 }})
|
|
|
552 |
continue
|
| 19153 |
kshitij.so |
553 |
if similarItem['netPriceAfterCashBack'] < prepaidBestPrice:
|
| 16017 |
kshitij.so |
554 |
prepaidBestOne = similarItem
|
| 19153 |
kshitij.so |
555 |
prepaidBestPrice = similarItem['netPriceAfterCashBack']
|
| 20347 |
kshitij.so |
556 |
elif similarItem['netPriceAfterCashBack'] == prepaidBestPrice:
|
|
|
557 |
|
|
|
558 |
try:
|
| 20366 |
kshitij.so |
559 |
if (DEAL_PRIORITY.index(int(similarItem['source_id'])) > DEAL_PRIORITY.index(int(prepaidBestOne['source_id']))):
|
| 20347 |
kshitij.so |
560 |
continue
|
|
|
561 |
except:
|
|
|
562 |
traceback.print_exc()
|
|
|
563 |
|
| 16017 |
kshitij.so |
564 |
prepaidBestOne = similarItem
|
| 19153 |
kshitij.so |
565 |
prepaidBestPrice = similarItem['netPriceAfterCashBack']
|
| 16017 |
kshitij.so |
566 |
else:
|
|
|
567 |
pass
|
| 16024 |
kshitij.so |
568 |
if bestOne is not None or prepaidBestOne is not None:
|
| 13918 |
kshitij.so |
569 |
for similarItem in similarItems:
|
|
|
570 |
toUpdate.append(similarItem['_id'])
|
| 16023 |
kshitij.so |
571 |
if bestOne is not None:
|
|
|
572 |
toUpdate.remove(bestOne['_id'])
|
|
|
573 |
get_mongo_connection().Catalog.Deals.update({ '_id' : bestOne['_id'] }, {'$set':{'showDeal':1,'prepaidDeal':0 }})
|
|
|
574 |
if prepaidBestOne is not None:
|
| 16069 |
kshitij.so |
575 |
if bestOne is not None:
|
| 19153 |
kshitij.so |
576 |
if prepaidBestOne['netPriceAfterCashBack'] < bestOne['netPriceAfterCashBack']:
|
| 16069 |
kshitij.so |
577 |
toUpdate.remove(prepaidBestOne['_id'])
|
|
|
578 |
get_mongo_connection().Catalog.Deals.update({ '_id' : prepaidBestOne['_id'] }, {'$set':{'showDeal':0,'prepaidDeal':1 }})
|
| 16072 |
kshitij.so |
579 |
else:
|
|
|
580 |
toUpdate.remove(prepaidBestOne['_id'])
|
|
|
581 |
get_mongo_connection().Catalog.Deals.update({ '_id' : prepaidBestOne['_id'] }, {'$set':{'showDeal':0,'prepaidDeal':1 }})
|
| 13918 |
kshitij.so |
582 |
if len(toUpdate) > 0:
|
| 16017 |
kshitij.so |
583 |
get_mongo_connection().Catalog.Deals.update({ '_id' : { "$in": toUpdate } }, {'$set':{'showDeal':0,'prepaidDeal':0 }},upsert=False, multi=True)
|
|
|
584 |
|
| 14342 |
kshitij.so |
585 |
print "Done with recomputing"
|
| 13829 |
kshitij.so |
586 |
|
|
|
587 |
def getLatestPrice(skuBundleId, source_id):
|
|
|
588 |
temp = []
|
|
|
589 |
itemIds = list(get_mongo_connection().Catalog.MasterData.find({'skuBundleId':skuBundleId,'source_id' : source_id}))
|
| 16026 |
kshitij.so |
590 |
item = None
|
| 13829 |
kshitij.so |
591 |
for item in itemIds:
|
| 14309 |
kshitij.so |
592 |
item['dealFlag'] = 0
|
|
|
593 |
item['dealType'] = 0
|
| 16510 |
kshitij.so |
594 |
item['dealUrl'] = ""
|
| 17674 |
kshitij.so |
595 |
if item['source_id'] ==5 and item['rank'] == 0 and item['category_id']!=6:
|
| 15912 |
kshitij.so |
596 |
continue
|
| 15187 |
kshitij.so |
597 |
if item['source_id'] ==3:
|
|
|
598 |
item['marketPlaceUrl'] = item['marketPlaceUrl']+'?supc='+item.get('identifier')
|
| 14309 |
kshitij.so |
599 |
manualDeals = list(get_mongo_connection().Catalog.ManualDeals.find({'startDate':{'$lte':to_java_date(datetime.now())},'endDate':{'$gte':to_java_date(datetime.now())},'source_id':source_id, 'sku':item['_id']}))
|
|
|
600 |
if len(manualDeals) > 0:
|
|
|
601 |
item['dealFlag'] = 1
|
| 14760 |
kshitij.so |
602 |
item['dealType'] =manualDeals[0]['dealType']
|
| 16510 |
kshitij.so |
603 |
item['dealUrl'] = manualDeals[0]['dealUrl']
|
| 14760 |
kshitij.so |
604 |
info = returnLatestPrice(item, source_id)
|
| 19153 |
kshitij.so |
605 |
if item['source_id'] != SOURCE_MAP.get('PAYTM.COM'):
|
|
|
606 |
data = calculateCashBack(item, info['available_price'])
|
|
|
607 |
else:
|
|
|
608 |
if info['codAvailable'] ==0:
|
|
|
609 |
data = calculateCashBack(item, info['gross_price'])
|
| 14760 |
kshitij.so |
610 |
else:
|
| 19153 |
kshitij.so |
611 |
data = calculateCashBack(item, info['available_price']) #No need, can be done in if with or clause.
|
|
|
612 |
|
|
|
613 |
info['cash_back'] = data['cash_back']
|
|
|
614 |
info['cash_back_type'] = data['cash_back_type']
|
|
|
615 |
info['netPriceAfterCashBack'] = data['netPriceAfterCashBack']
|
|
|
616 |
info['showNetPrice'] = data['showNetPrice']
|
| 19317 |
kshitij.so |
617 |
info['category_id'] = item['category_id']
|
|
|
618 |
info['subCategoryId'] = item['subCategoryId']
|
| 21442 |
kshitij.so |
619 |
info['identifier'] = str(item['identifier'])
|
| 19153 |
kshitij.so |
620 |
get_mongo_connection().Catalog.Deals.update({'_id':item['_id']},{"$set":{'netPriceAfterCashBack':info['netPriceAfterCashBack']}})
|
| 14760 |
kshitij.so |
621 |
temp.append(info)
|
| 16026 |
kshitij.so |
622 |
if item is not None:
|
|
|
623 |
try:
|
|
|
624 |
thread = threading.Thread(target=recomputeDeal, args = (item,))
|
|
|
625 |
thread.daemon = True
|
|
|
626 |
thread.start()
|
|
|
627 |
except:
|
|
|
628 |
print traceback.print_exc()
|
|
|
629 |
print "Unable to compute deal for ",skuBundleId
|
| 13829 |
kshitij.so |
630 |
return temp
|
|
|
631 |
|
| 13864 |
kshitij.so |
632 |
def getLatestPriceById(id):
|
|
|
633 |
item = list(get_mongo_connection().Catalog.MasterData.find({'_id':id}))
|
| 14309 |
kshitij.so |
634 |
item[0]['dealFlag'] = 0
|
|
|
635 |
item[0]['dealType'] = 0
|
| 16510 |
kshitij.so |
636 |
item[0]['dealUrl'] = ""
|
|
|
637 |
|
| 14309 |
kshitij.so |
638 |
manualDeals = list(get_mongo_connection().Catalog.ManualDeals.find({'startDate':{'$lte':to_java_date(datetime.now())},'endDate':{'$gte':to_java_date(datetime.now())},'source_id':item[0]['source_id'], 'sku':item[0]['_id']}))
|
|
|
639 |
if len(manualDeals) > 0:
|
|
|
640 |
item[0]['dealFlag'] = 1
|
| 15266 |
kshitij.so |
641 |
item[0]['dealType'] =manualDeals[0]['dealType']
|
| 16510 |
kshitij.so |
642 |
item[0]['dealUrl'] = manualDeals[0]['dealUrl']
|
| 14367 |
kshitij.so |
643 |
|
| 14431 |
kshitij.so |
644 |
info = returnLatestPrice(item[0], item[0]['source_id'])
|
| 19153 |
kshitij.so |
645 |
if item[0]['source_id'] != SOURCE_MAP.get('PAYTM.COM'):
|
|
|
646 |
data = calculateCashBack(item[0], info['available_price'])
|
|
|
647 |
else:
|
|
|
648 |
if info['codAvailable'] ==0:
|
|
|
649 |
data = calculateCashBack(item[0], info['gross_price'])
|
|
|
650 |
else:
|
|
|
651 |
data = calculateCashBack(item[0], info['available_price']) #No need, can be done in if with or clause.
|
|
|
652 |
|
|
|
653 |
info['cash_back'] = data['cash_back']
|
|
|
654 |
info['cash_back_type'] = data['cash_back_type']
|
|
|
655 |
info['netPriceAfterCashBack'] = data['netPriceAfterCashBack']
|
|
|
656 |
info['showNetPrice'] = data['showNetPrice']
|
|
|
657 |
get_mongo_connection().Catalog.Deals.update({'_id':item[0]['_id']},{"$set":{'netPriceAfterCashBack':info['netPriceAfterCashBack']}})
|
| 14794 |
kshitij.so |
658 |
print info
|
| 14367 |
kshitij.so |
659 |
try:
|
| 15273 |
kshitij.so |
660 |
thread = threading.Thread(target=recomputeDeal, args = (item[0],))
|
| 14367 |
kshitij.so |
661 |
thread.daemon = True
|
|
|
662 |
thread.start()
|
|
|
663 |
except:
|
|
|
664 |
print "Unable to compute deal for ",item[0]['skuBundleId']
|
| 14431 |
kshitij.so |
665 |
return info
|
| 13829 |
kshitij.so |
666 |
|
| 14828 |
kshitij.so |
667 |
def updatePriceForNotificationBundles(skuBundleId):
|
| 15266 |
kshitij.so |
668 |
itemIds = list(get_mongo_connection().Catalog.MasterData.find({'skuBundleId':skuBundleId,'priceUpdatedOn':{'$lte':to_java_date(datetime.now() - timedelta(minutes=2))},'source_id':{"$in":SOURCE_MAP.values()}}))
|
| 14828 |
kshitij.so |
669 |
for item in itemIds:
|
| 14833 |
kshitij.so |
670 |
print item['_id']
|
| 14828 |
kshitij.so |
671 |
item['dealFlag'] = 0
|
|
|
672 |
item['dealType'] = 0
|
| 16510 |
kshitij.so |
673 |
item['dealUrl'] = ""
|
| 14828 |
kshitij.so |
674 |
manualDeals = list(get_mongo_connection().Catalog.ManualDeals.find({'startDate':{'$lte':to_java_date(datetime.now())},'endDate':{'$gte':to_java_date(datetime.now())},'source_id':item['source_id'], 'sku':item['_id']}))
|
|
|
675 |
if len(manualDeals) > 0:
|
|
|
676 |
item['dealFlag'] = 1
|
|
|
677 |
item['dealType'] =manualDeals[0]['dealType']
|
| 16510 |
kshitij.so |
678 |
item['dealUrl'] = manualDeals[0]['dealUrl']
|
| 14828 |
kshitij.so |
679 |
info = returnLatestPrice(item, item['source_id'],False)
|
|
|
680 |
print info
|
|
|
681 |
|
| 13829 |
kshitij.so |
682 |
def main():
|
| 15956 |
kshitij.so |
683 |
print datetime.now()
|
| 20313 |
kshitij.so |
684 |
print "returned %s"%(str(getLatestPriceById(23014)))
|
| 15956 |
kshitij.so |
685 |
print datetime.now()
|
| 13829 |
kshitij.so |
686 |
if __name__=='__main__':
|
| 13971 |
kshitij.so |
687 |
main()
|
|
|
688 |
|