| Line 196... |
Line 196... |
| 196 |
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)
|
196 |
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)
|
| 197 |
get_mongo_connection().Catalog.Deals.update({'_id':data['_id']}, {'$set' : {'in_stock':inStock}}, multi=True)
|
197 |
get_mongo_connection().Catalog.Deals.update({'_id':data['_id']}, {'$set' : {'in_stock':inStock}}, multi=True)
|
| 198 |
|
198 |
|
| 199 |
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']}
|
199 |
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']}
|
| 200 |
except Exception as e:
|
200 |
except Exception as e:
|
| - |
|
201 |
print traceback.print_exc()
|
| 201 |
print "Exception for _id %d and source %s"%(data['_id'], source_id)
|
202 |
print "Exception for _id %d and source %s"%(data['_id'], source_id)
|
| 202 |
print e
|
203 |
print e
|
| 203 |
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']}
|
204 |
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']}
|
| 204 |
|
205 |
|
| 205 |
elif source_id == 2:
|
206 |
elif source_id == 2:
|
| Line 261... |
Line 262... |
| 261 |
print e
|
262 |
print e
|
| 262 |
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']}
|
263 |
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']}
|
| 263 |
else:
|
264 |
else:
|
| 264 |
return {}
|
265 |
return {}
|
| 265 |
|
266 |
|
| 266 |
|
- |
|
| 267 |
def populateNegativeDeals():
|
- |
|
| 268 |
negativeDeals = get_mongo_connection().Catalog.NegativeDeals.find().distinct('sku')
|
- |
|
| 269 |
mc.set("negative_deals", negativeDeals, 600)
|
- |
|
| 270 |
|
- |
|
| 271 |
def recomputePoints(item, deal):
|
267 |
def recomputePoints(item, deal):
|
| 272 |
try:
|
268 |
try:
|
| 273 |
nlcPoints = getNlcPoints(item, deal['minNlc'], deal['maxNlc'], deal['available_price'])
|
269 |
nlcPoints = getNlcPoints(item, deal['minNlc'], deal['maxNlc'], deal['available_price'])
|
| 274 |
except:
|
270 |
except:
|
| 275 |
print traceback.print_exc()
|
271 |
print traceback.print_exc()
|
| Line 278... |
Line 274... |
| 278 |
dealPoints = item['dealPoints']
|
274 |
dealPoints = item['dealPoints']
|
| 279 |
else:
|
275 |
else:
|
| 280 |
dealPoints = 0
|
276 |
dealPoints = 0
|
| 281 |
get_mongo_connection().Catalog.Deals.update({'_id':deal['_id']},{"$set":{'totalPoints':deal['totalPoints'] - deal['nlcPoints'] + nlcPoints - deal['dealPoints'] +dealPoints , 'nlcPoints': nlcPoints, 'dealPoints': dealPoints, 'manualDealThresholdPrice': item['manualDealThresholdPrice']}})
|
277 |
get_mongo_connection().Catalog.Deals.update({'_id':deal['_id']},{"$set":{'totalPoints':deal['totalPoints'] - deal['nlcPoints'] + nlcPoints - deal['dealPoints'] +dealPoints , 'nlcPoints': nlcPoints, 'dealPoints': dealPoints, 'manualDealThresholdPrice': item['manualDealThresholdPrice']}})
|
| 282 |
|
278 |
|
| - |
|
279 |
|
| - |
|
280 |
def populateNegativeDeals():
|
| - |
|
281 |
negativeDeals = get_mongo_connection().Catalog.NegativeDeals.find().distinct('sku')
|
| - |
|
282 |
mc.set("negative_deals", negativeDeals, 600)
|
| - |
|
283 |
|
| 283 |
def recomputeDeal(skuBundleId):
|
284 |
def recomputeDeal(item):
|
| 284 |
"""Lets recompute deal for this bundle"""
|
285 |
"""Lets recompute deal for this bundle"""
|
| 285 |
print "Recomputing for bundleId",skuBundleId
|
286 |
print "Recomputing for bundleId",item.get('skuBundleId')
|
| - |
|
287 |
skuBundleId = item['skuBundleId']
|
| 286 |
|
288 |
|
| 287 |
similarItems = list(get_mongo_connection().Catalog.Deals.find({'skuBundleId':skuBundleId}).sort([('available_price',pymongo.ASCENDING)]))
|
289 |
similarItems = list(get_mongo_connection().Catalog.Deals.find({'skuBundleId':skuBundleId}).sort([('available_price',pymongo.ASCENDING)]))
|
| 288 |
bestPrice = float("inf")
|
290 |
bestPrice = float("inf")
|
| 289 |
bestOne = None
|
291 |
bestOne = None
|
| 290 |
bestSellerPoints = 0
|
292 |
bestSellerPoints = 0
|
| 291 |
toUpdate = []
|
293 |
toUpdate = []
|
| 292 |
for similarItem in similarItems:
|
294 |
for similarItem in similarItems:
|
| - |
|
295 |
if similarItem['_id'] == item['_id']:
|
| - |
|
296 |
recomputePoints(item, similarItem)
|
| 293 |
if mc.get("negative_deals") is None:
|
297 |
if mc.get("negative_deals") is None:
|
| 294 |
populateNegativeDeals()
|
298 |
populateNegativeDeals()
|
| 295 |
if similarItem['in_stock'] == 0 or similarItem['maxprice'] is None or similarItem['maxprice'] < similarItem['available_price'] or similarItem['_id'] in mc.get("negative_deals"):
|
299 |
if similarItem['in_stock'] == 0 or similarItem['maxprice'] is None or similarItem['maxprice'] < similarItem['available_price'] or similarItem['_id'] in mc.get("negative_deals"):
|
| 296 |
get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0 }})
|
300 |
get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0 }})
|
| 297 |
continue
|
301 |
continue
|
| Line 319... |
Line 323... |
| 319 |
temp = []
|
323 |
temp = []
|
| 320 |
itemIds = list(get_mongo_connection().Catalog.MasterData.find({'skuBundleId':skuBundleId,'source_id' : source_id}))
|
324 |
itemIds = list(get_mongo_connection().Catalog.MasterData.find({'skuBundleId':skuBundleId,'source_id' : source_id}))
|
| 321 |
for item in itemIds:
|
325 |
for item in itemIds:
|
| 322 |
item['dealFlag'] = 0
|
326 |
item['dealFlag'] = 0
|
| 323 |
item['dealType'] = 0
|
327 |
item['dealType'] = 0
|
| - |
|
328 |
item['dealPoints'] = 0
|
| - |
|
329 |
item['manualDealThresholdPrice'] = None
|
| 324 |
if item['source_id'] ==3:
|
330 |
if item['source_id'] ==3:
|
| 325 |
item['marketPlaceUrl'] = item['marketPlaceUrl']+'?supc='+item.get('identifier')
|
331 |
item['marketPlaceUrl'] = item['marketPlaceUrl']+'?supc='+item.get('identifier')
|
| 326 |
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']}))
|
332 |
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']}))
|
| 327 |
if len(manualDeals) > 0:
|
333 |
if len(manualDeals) > 0:
|
| 328 |
item['dealFlag'] = 1
|
334 |
item['dealFlag'] = 1
|
| 329 |
item['dealType'] =manualDeals[0]['dealType']
|
335 |
item['dealType'] =manualDeals[0]['dealType']
|
| - |
|
336 |
item['dealPoints'] = manualDeals[0]['dealPoints']
|
| - |
|
337 |
item['manualDealThresholdPrice'] = manualDeals[0]['dealThresholdPrice']
|
| 330 |
info = returnLatestPrice(item, source_id)
|
338 |
info = returnLatestPrice(item, source_id)
|
| 331 |
print info
|
339 |
print info
|
| 332 |
try:
|
340 |
try:
|
| 333 |
cashBack = getCashBack(item['_id'], item['source_id'], item['category_id'], mc, 'localhost')
|
341 |
cashBack = getCashBack(item['_id'], item['source_id'], item['category_id'], mc, 'localhost')
|
| 334 |
print "CashBack is ",cashBack
|
342 |
print "CashBack is ",cashBack
|
| Line 348... |
Line 356... |
| 348 |
info['cash_back_type'] = 0
|
356 |
info['cash_back_type'] = 0
|
| 349 |
info['cash_back'] = 0
|
357 |
info['cash_back'] = 0
|
| 350 |
print "info is ",info
|
358 |
print "info is ",info
|
| 351 |
temp.append(info)
|
359 |
temp.append(info)
|
| 352 |
try:
|
360 |
try:
|
| 353 |
thread = threading.Thread(target=recomputeDeal, args = (skuBundleId,))
|
361 |
thread = threading.Thread(target=recomputeDeal, args = (item,))
|
| 354 |
thread.daemon = True
|
362 |
thread.daemon = True
|
| 355 |
thread.start()
|
363 |
thread.start()
|
| 356 |
except:
|
364 |
except:
|
| 357 |
print "Unable to compute deal for ",skuBundleId
|
365 |
print "Unable to compute deal for ",skuBundleId
|
| 358 |
return temp
|
366 |
return temp
|
| 359 |
|
367 |
|
| 360 |
def getLatestPriceById(id):
|
368 |
def getLatestPriceById(id):
|
| 361 |
item = list(get_mongo_connection().Catalog.MasterData.find({'_id':id}))
|
369 |
item = list(get_mongo_connection().Catalog.MasterData.find({'_id':id}))
|
| 362 |
item[0]['dealFlag'] = 0
|
370 |
item[0]['dealFlag'] = 0
|
| 363 |
item[0]['dealType'] = 0
|
371 |
item[0]['dealType'] = 0
|
| - |
|
372 |
item[0]['dealPoints'] = 0
|
| - |
|
373 |
item[0]['manualDealThresholdPrice'] = None
|
| 364 |
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']}))
|
374 |
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']}))
|
| 365 |
if len(manualDeals) > 0:
|
375 |
if len(manualDeals) > 0:
|
| 366 |
item[0]['dealFlag'] = 1
|
376 |
item[0]['dealFlag'] = 1
|
| 367 |
item[0]['dealType'] =manualDeals[0]['dealType']
|
377 |
item[0]['dealType'] =manualDeals[0]['dealType']
|
| - |
|
378 |
item[0]['dealPoints'] = manualDeals[0]['dealPoints']
|
| - |
|
379 |
item[0]['manualDealThresholdPrice'] = manualDeals[0]['dealThresholdPrice']
|
| 368 |
|
380 |
|
| 369 |
info = returnLatestPrice(item[0], item[0]['source_id'])
|
381 |
info = returnLatestPrice(item[0], item[0]['source_id'])
|
| 370 |
print info
|
382 |
print info
|
| 371 |
try:
|
383 |
try:
|
| 372 |
cashBack = getCashBack(item[0]['_id'], item[0]['source_id'], item[0]['category_id'], mc, 'localhost')
|
384 |
cashBack = getCashBack(item[0]['_id'], item[0]['source_id'], item[0]['category_id'], mc, 'localhost')
|
| Line 386... |
Line 398... |
| 386 |
print cashBackEx
|
398 |
print cashBackEx
|
| 387 |
print "Error calculating cashback."
|
399 |
print "Error calculating cashback."
|
| 388 |
info['cash_back_type'] = 0
|
400 |
info['cash_back_type'] = 0
|
| 389 |
info['cash_back'] = 0
|
401 |
info['cash_back'] = 0
|
| 390 |
try:
|
402 |
try:
|
| 391 |
thread = threading.Thread(target=recomputeDeal, args = (item[0]['skuBundleId'],))
|
403 |
thread = threading.Thread(target=recomputeDeal, args = (item[0]))
|
| 392 |
thread.daemon = True
|
404 |
thread.daemon = True
|
| 393 |
thread.start()
|
405 |
thread.start()
|
| 394 |
except:
|
406 |
except:
|
| 395 |
print "Unable to compute deal for ",item[0]['skuBundleId']
|
407 |
print "Unable to compute deal for ",item[0]['skuBundleId']
|
| 396 |
return info
|
408 |
return info
|
| 397 |
|
409 |
|
| 398 |
def updatePriceForNotificationBundles(skuBundleId):
|
410 |
def updatePriceForNotificationBundles(skuBundleId):
|
| 399 |
itemIds = list(get_mongo_connection().Catalog.MasterData.find({'skuBundleId':skuBundleId,'priceUpdatedOn':{'$lte':to_java_date(datetime.now() - timedelta(minutes=3))},'source_id':{"$in":SOURCE_MAP.values()}}))
|
411 |
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()}}))
|
| 400 |
for item in itemIds:
|
412 |
for item in itemIds:
|
| 401 |
print item['_id']
|
413 |
print item['_id']
|
| 402 |
item['dealFlag'] = 0
|
414 |
item['dealFlag'] = 0
|
| 403 |
item['dealType'] = 0
|
415 |
item['dealType'] = 0
|
| - |
|
416 |
item['dealPoints'] = 0
|
| - |
|
417 |
item['manualDealThresholdPrice'] = None
|
| 404 |
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']}))
|
418 |
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']}))
|
| 405 |
if len(manualDeals) > 0:
|
419 |
if len(manualDeals) > 0:
|
| 406 |
item['dealFlag'] = 1
|
420 |
item['dealFlag'] = 1
|
| 407 |
item['dealType'] =manualDeals[0]['dealType']
|
421 |
item['dealType'] =manualDeals[0]['dealType']
|
| - |
|
422 |
item['dealPoints'] = manualDeals[0]['dealPoints']
|
| - |
|
423 |
item['manualDealThresholdPrice'] = manualDeals[0]['dealThresholdPrice']
|
| 408 |
info = returnLatestPrice(item, item['source_id'],False)
|
424 |
info = returnLatestPrice(item, item['source_id'],False)
|
| 409 |
print info
|
425 |
print info
|
| 410 |
|
426 |
|
| 411 |
def main():
|
427 |
def main():
|
| 412 |
print "retuned %s"%(str(getLatestPrice(2313, 4)))
|
428 |
print "retuned %s"%(str(getLatestPriceById(23151)))
|
| 413 |
|
429 |
|
| 414 |
if __name__=='__main__':
|
430 |
if __name__=='__main__':
|
| 415 |
main()
|
431 |
main()
|
| 416 |
|
432 |
|