| Line 71... |
Line 71... |
| 71 |
except Exception, e:
|
71 |
except Exception, e:
|
| 72 |
print e
|
72 |
print e
|
| 73 |
return None
|
73 |
return None
|
| 74 |
return con
|
74 |
return con
|
| 75 |
|
75 |
|
| - |
|
76 |
def getNetPriceForItem(itemId, source_id, category_id ,price):
|
| - |
|
77 |
cash_back_type = 0
|
| - |
|
78 |
cash_back = 0
|
| - |
|
79 |
try:
|
| - |
|
80 |
cashBack = getCashBack(itemId, source_id, category_id, mc, options.mongoHost)
|
| - |
|
81 |
if not cashBack or cashBack.get('cash_back_status')!=1:
|
| - |
|
82 |
cash_back_type = 0
|
| - |
|
83 |
cash_back = 0
|
| - |
|
84 |
|
| - |
|
85 |
else:
|
| - |
|
86 |
if cashBack['cash_back_type'] in (1,2):
|
| - |
|
87 |
|
| - |
|
88 |
if cashBack.get('maxCashBack') is not None:
|
| - |
|
89 |
|
| - |
|
90 |
if cashBack.get('cash_back_type') ==1 and (float(cashBack.get('cash_back'))*price)/100 > cashBack.get('maxCashBack'):
|
| - |
|
91 |
cashBack['cash_back_type'] = 2
|
| - |
|
92 |
cashBack['cash_back'] = cashBack['maxCashBack']
|
| - |
|
93 |
elif cashBack.get('cash_back_type') ==2 and cashBack.get('cash_back') > cashBack.get('maxCashBack'):
|
| - |
|
94 |
cashBack['cash_back'] = cashBack['maxCashBack']
|
| - |
|
95 |
else:
|
| - |
|
96 |
pass
|
| - |
|
97 |
|
| - |
|
98 |
|
| - |
|
99 |
|
| - |
|
100 |
cash_back_type = cashBack['cash_back_type']
|
| - |
|
101 |
cash_back = float(cashBack['cash_back'])
|
| - |
|
102 |
except Exception as cashBackEx:
|
| - |
|
103 |
pass
|
| - |
|
104 |
|
| - |
|
105 |
if cash_back_type ==1:
|
| - |
|
106 |
return (price - float(cash_back)*price/100)
|
| - |
|
107 |
elif cash_back_type ==2:
|
| - |
|
108 |
return (price - cash_back)
|
| - |
|
109 |
else:
|
| - |
|
110 |
return price
|
| - |
|
111 |
|
| - |
|
112 |
|
| 76 |
def getSoupObject(url):
|
113 |
def getSoupObject(url):
|
| 77 |
print "Getting soup object for"
|
114 |
print "Getting soup object for"
|
| 78 |
print url
|
115 |
print url
|
| 79 |
global RETRY_COUNT
|
116 |
global RETRY_COUNT
|
| 80 |
RETRY_COUNT = 1
|
117 |
RETRY_COUNT = 1
|
| Line 128... |
Line 165... |
| 128 |
product = list(get_mongo_connection().Catalog.MasterData.find({'source_id':5,'identifier':scin}))
|
165 |
product = list(get_mongo_connection().Catalog.MasterData.find({'source_id':5,'identifier':scin}))
|
| 129 |
if len(product) > 0:
|
166 |
if len(product) > 0:
|
| 130 |
if product[0].get('ignorePricing') ==1:
|
167 |
if product[0].get('ignorePricing') ==1:
|
| 131 |
continue
|
168 |
continue
|
| 132 |
if productInfo['inStock'] ==1:
|
169 |
if productInfo['inStock'] ==1:
|
| - |
|
170 |
netPriceAfterCashBack = getNetPriceForItem(product[0]['_id'], SOURCE_MAP.get('SHOPCLUES.COM'), product[0]['category_id'], productInfo['price'])
|
| 133 |
get_mongo_connection().Catalog.MasterData.update({'_id':product[0]['_id']},{"$set":{'rank':rank, 'available_price':productInfo['price'], \
|
171 |
get_mongo_connection().Catalog.MasterData.update({'_id':product[0]['_id']},{"$set":{'rank':rank, 'available_price':productInfo['price'], \
|
| 134 |
'in_stock':productInfo['inStock'], 'codAvailable':productInfo['isCod'], \
|
172 |
'in_stock':productInfo['inStock'], 'codAvailable':productInfo['isCod'], \
|
| 135 |
'coupon':productInfo['coupon'], 'updatedOn':to_java_date(datetime.now()),'priceUpdatedOn':to_java_date(datetime.now())}})
|
173 |
'coupon':productInfo['coupon'], 'updatedOn':to_java_date(datetime.now()),'priceUpdatedOn':to_java_date(datetime.now())}})
|
| 136 |
get_mongo_connection().Catalog.Deals.update({'_id':product[0]['_id']}, {'$set' : {'rank':rank,'available_price':productInfo['price'] , 'in_stock':productInfo['inStock'],'codAvailable':productInfo['isCod']}})
|
174 |
get_mongo_connection().Catalog.Deals.update({'_id':product[0]['_id']}, {'$set' : {'rank':rank,'available_price':productInfo['price'] , 'in_stock':productInfo['inStock'],'codAvailable':productInfo['isCod'],'netPriceAfterCashBack':netPriceAfterCashBack}})
|
| 137 |
else:
|
175 |
else:
|
| - |
|
176 |
netPriceAfterCashBack = getNetPriceForItem(product[0]['_id'], SOURCE_MAP.get('SHOPCLUES.COM'), product[0]['category_id'], product[0]['available_price'])
|
| 138 |
get_mongo_connection().Catalog.MasterData.update({'_id':product[0]['_id']}, {'$set' : {'updatedOn':to_java_date(datetime.now()),'in_stock':0,'priceUpdatedOn':to_java_date(datetime.now())}})
|
177 |
get_mongo_connection().Catalog.MasterData.update({'_id':product[0]['_id']}, {'$set' : {'updatedOn':to_java_date(datetime.now()),'in_stock':0,'priceUpdatedOn':to_java_date(datetime.now())}})
|
| 139 |
get_mongo_connection().Catalog.Deals.update({'_id':product[0]['_id']}, {'$set' : {'in_stock':0}})
|
178 |
get_mongo_connection().Catalog.Deals.update({'_id':product[0]['_id']}, {'$set' : {'in_stock':0,'netPriceAfterCashBack':netPriceAfterCashBack}})
|
| 140 |
|
179 |
|
| 141 |
try:
|
180 |
try:
|
| 142 |
recomputeDeal(product[0])
|
181 |
recomputeDeal(product[0])
|
| 143 |
except:
|
182 |
except:
|
| 144 |
print "Unable to compute deal for %s"%(product[0]['skuBundleId'])
|
183 |
print "Unable to compute deal for %s"%(product[0]['skuBundleId'])
|
| Line 191... |
Line 230... |
| 191 |
|
230 |
|
| 192 |
def recomputeDeal(item):
|
231 |
def recomputeDeal(item):
|
| 193 |
"""Lets recompute deal for this bundle"""
|
232 |
"""Lets recompute deal for this bundle"""
|
| 194 |
print "Recomputing for bundleId %d" %(item.get('skuBundleId'))
|
233 |
print "Recomputing for bundleId %d" %(item.get('skuBundleId'))
|
| 195 |
skuBundleId = item['skuBundleId']
|
234 |
skuBundleId = item['skuBundleId']
|
| 196 |
item['dealFlag'] = 0
|
- |
|
| 197 |
item['dealType'] = 0
|
235 |
|
| 198 |
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']}))
|
- |
|
| 199 |
if len(manualDeals) > 0:
|
- |
|
| 200 |
item['dealFlag'] = 1
|
- |
|
| 201 |
item['dealType'] =manualDeals[0]['dealType']
|
- |
|
| 202 |
similarItems = list(get_mongo_connection().Catalog.Deals.find({'skuBundleId':skuBundleId}).sort([('available_price',pymongo.ASCENDING)]))
|
236 |
similarItems = list(get_mongo_connection().Catalog.Deals.find({'skuBundleId':skuBundleId}).sort([('netPriceAfterCashBack',pymongo.ASCENDING)]))
|
| 203 |
bestPrice = float("inf")
|
237 |
bestPrice = float("inf")
|
| 204 |
bestOne = None
|
238 |
bestOne = None
|
| 205 |
bestSellerPoints = 0
|
239 |
bestSellerPoints = 0
|
| 206 |
toUpdate = []
|
240 |
toUpdate = []
|
| 207 |
prepaidBestPrice = float("inf")
|
241 |
prepaidBestPrice = float("inf")
|
| Line 215... |
Line 249... |
| 215 |
get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0, 'prepaidDeal':0 }})
|
249 |
get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0, 'prepaidDeal':0 }})
|
| 216 |
continue
|
250 |
continue
|
| 217 |
if similarItem['source_id'] == SOURCE_MAP.get('SHOPCLUES.COM') and similarItem['rank']==0:
|
251 |
if similarItem['source_id'] == SOURCE_MAP.get('SHOPCLUES.COM') and similarItem['rank']==0:
|
| 218 |
get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0,'prepaidDeal':0 }})
|
252 |
get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0,'prepaidDeal':0 }})
|
| 219 |
continue
|
253 |
continue
|
| 220 |
if similarItem['available_price'] < bestPrice:
|
254 |
if similarItem.get('netPriceAfterCashBack') < bestPrice:
|
| 221 |
bestOne = similarItem
|
255 |
bestOne = similarItem
|
| 222 |
bestPrice = similarItem['available_price']
|
256 |
bestPrice = similarItem.get('netPriceAfterCashBack')
|
| 223 |
bestSellerPoints = similarItem['bestSellerPoints']
|
257 |
bestSellerPoints = similarItem['bestSellerPoints']
|
| 224 |
elif similarItem['available_price'] == bestPrice and bestSellerPoints < similarItem['bestSellerPoints']:
|
258 |
elif similarItem.get('netPriceAfterCashBack') == bestPrice and bestSellerPoints < similarItem['bestSellerPoints']:
|
| 225 |
bestOne = similarItem
|
259 |
bestOne = similarItem
|
| 226 |
bestPrice = similarItem['available_price']
|
260 |
bestPrice = similarItem.get('netPriceAfterCashBack')
|
| 227 |
bestSellerPoints = similarItem['bestSellerPoints']
|
261 |
bestSellerPoints = similarItem['bestSellerPoints']
|
| 228 |
else:
|
262 |
else:
|
| 229 |
pass
|
263 |
pass
|
| 230 |
else:
|
264 |
else:
|
| 231 |
if mc.get("negative_deals") is None:
|
265 |
if mc.get("negative_deals") is None:
|
| Line 234... |
Line 268... |
| 234 |
get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0, 'prepaidDeal':0 }})
|
268 |
get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0, 'prepaidDeal':0 }})
|
| 235 |
continue
|
269 |
continue
|
| 236 |
if similarItem['source_id'] == SOURCE_MAP.get('SHOPCLUES.COM') and similarItem['rank']==0:
|
270 |
if similarItem['source_id'] == SOURCE_MAP.get('SHOPCLUES.COM') and similarItem['rank']==0:
|
| 237 |
get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0,'prepaidDeal':0 }})
|
271 |
get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0,'prepaidDeal':0 }})
|
| 238 |
continue
|
272 |
continue
|
| 239 |
if similarItem['source_id'] == SOURCE_MAP.get('PAYTM.COM'):
|
- |
|
| 240 |
similarItem['available_price'] = similarItem['gross_price']
|
- |
|
| 241 |
if similarItem['available_price'] < prepaidBestPrice:
|
273 |
if similarItem.get('netPriceAfterCashBack') < prepaidBestPrice:
|
| 242 |
prepaidBestOne = similarItem
|
274 |
prepaidBestOne = similarItem
|
| 243 |
prepaidBestPrice = similarItem['available_price']
|
275 |
prepaidBestPrice = similarItem.get('netPriceAfterCashBack')
|
| 244 |
prepaidBestSellerPoints = similarItem['bestSellerPoints']
|
276 |
prepaidBestSellerPoints = similarItem['bestSellerPoints']
|
| 245 |
elif similarItem['available_price'] == prepaidBestPrice and prepaidBestSellerPoints < similarItem['bestSellerPoints']:
|
277 |
elif similarItem.get('netPriceAfterCashBack') == prepaidBestPrice and prepaidBestSellerPoints < similarItem['bestSellerPoints']:
|
| 246 |
prepaidBestOne = similarItem
|
278 |
prepaidBestOne = similarItem
|
| 247 |
prepaidBestPrice = similarItem['available_price']
|
279 |
prepaidBestPrice = similarItem.get('netPriceAfterCashBack')
|
| 248 |
prepaidBestSellerPoints = similarItem['bestSellerPoints']
|
280 |
prepaidBestSellerPoints = similarItem['bestSellerPoints']
|
| 249 |
else:
|
281 |
else:
|
| 250 |
pass
|
282 |
pass
|
| 251 |
if bestOne is not None or prepaidBestOne is not None:
|
283 |
if bestOne is not None or prepaidBestOne is not None:
|
| 252 |
for similarItem in similarItems:
|
284 |
for similarItem in similarItems:
|
| Line 254... |
Line 286... |
| 254 |
if bestOne is not None:
|
286 |
if bestOne is not None:
|
| 255 |
toUpdate.remove(bestOne['_id'])
|
287 |
toUpdate.remove(bestOne['_id'])
|
| 256 |
get_mongo_connection().Catalog.Deals.update({ '_id' : bestOne['_id'] }, {'$set':{'showDeal':1,'prepaidDeal':0 }})
|
288 |
get_mongo_connection().Catalog.Deals.update({ '_id' : bestOne['_id'] }, {'$set':{'showDeal':1,'prepaidDeal':0 }})
|
| 257 |
if prepaidBestOne is not None:
|
289 |
if prepaidBestOne is not None:
|
| 258 |
if bestOne is not None:
|
290 |
if bestOne is not None:
|
| 259 |
if prepaidBestOne['available_price'] < bestOne['available_price']:
|
291 |
if prepaidBestOne.get('netPriceAfterCashBack') < bestOne.get('netPriceAfterCashBack'):
|
| 260 |
toUpdate.remove(prepaidBestOne['_id'])
|
292 |
toUpdate.remove(prepaidBestOne['_id'])
|
| 261 |
get_mongo_connection().Catalog.Deals.update({ '_id' : prepaidBestOne['_id'] }, {'$set':{'showDeal':0,'prepaidDeal':1 }})
|
293 |
get_mongo_connection().Catalog.Deals.update({ '_id' : prepaidBestOne['_id'] }, {'$set':{'showDeal':0,'prepaidDeal':1 }})
|
| 262 |
else:
|
294 |
else:
|
| 263 |
toUpdate.remove(prepaidBestOne['_id'])
|
295 |
toUpdate.remove(prepaidBestOne['_id'])
|
| 264 |
get_mongo_connection().Catalog.Deals.update({ '_id' : prepaidBestOne['_id'] }, {'$set':{'showDeal':0,'prepaidDeal':1 }})
|
296 |
get_mongo_connection().Catalog.Deals.update({ '_id' : prepaidBestOne['_id'] }, {'$set':{'showDeal':0,'prepaidDeal':1 }})
|
| 265 |
if len(toUpdate) > 0:
|
297 |
if len(toUpdate) > 0:
|
| 266 |
get_mongo_connection().Catalog.Deals.update({ '_id' : { "$in": toUpdate } }, {'$set':{'showDeal':0,'prepaidDeal':0 }},upsert=False, multi=True)
|
298 |
get_mongo_connection().Catalog.Deals.update({ '_id' : { "$in": toUpdate } }, {'$set':{'showDeal':0,'prepaidDeal':0 }},upsert=False, multi=True)
|
| 267 |
|
299 |
|
| - |
|
300 |
|
| - |
|
301 |
|
| 268 |
|
302 |
|
| 269 |
def bundleNewProduct(existingProduct, toBundle):
|
303 |
def bundleNewProduct(existingProduct, toBundle):
|
| 270 |
global bundledProducts
|
304 |
global bundledProducts
|
| 271 |
global exceptionList
|
305 |
global exceptionList
|
| 272 |
print "Adding new product"
|
306 |
print "Adding new product"
|
| Line 286... |
Line 320... |
| 286 |
existingProduct['url'] = toBundle.url
|
320 |
existingProduct['url'] = toBundle.url
|
| 287 |
existingProduct['showVideo'] = 0
|
321 |
existingProduct['showVideo'] = 0
|
| 288 |
existingProduct['shippingCost'] = 0
|
322 |
existingProduct['shippingCost'] = 0
|
| 289 |
existingProduct['quantity'] = 1
|
323 |
existingProduct['quantity'] = 1
|
| 290 |
existingProduct['videoLink'] = ""
|
324 |
existingProduct['videoLink'] = ""
|
| - |
|
325 |
existingProduct['showNetPrice'] = 0
|
| 291 |
get_mongo_connection().Catalog.MasterData.insert(existingProduct)
|
326 |
get_mongo_connection().Catalog.MasterData.insert(existingProduct)
|
| 292 |
newBundled = __NewBundled(toBundle, existingProduct)
|
327 |
newBundled = __NewBundled(toBundle, existingProduct)
|
| 293 |
bundledProducts.append(newBundled)
|
328 |
bundledProducts.append(newBundled)
|
| 294 |
return {1:'Data added successfully.'}
|
329 |
return {1:'Data added successfully.'}
|
| 295 |
except Exception as e:
|
330 |
except Exception as e:
|