| Line 21... |
Line 21... |
| 21 |
import traceback
|
21 |
import traceback
|
| 22 |
from itertools import groupby
|
22 |
from itertools import groupby
|
| 23 |
import urllib
|
23 |
import urllib
|
| 24 |
import urllib2
|
24 |
import urllib2
|
| 25 |
import json
|
25 |
import json
|
| 26 |
import collections
|
- |
|
| 27 |
try:
|
- |
|
| 28 |
import ordereddict
|
- |
|
| 29 |
except:
|
- |
|
| 30 |
pass
|
- |
|
| 31 |
|
26 |
|
| 32 |
con = None
|
27 |
con = None
|
| 33 |
|
28 |
|
| 34 |
DataService.initialize(db_hostname="localhost")
|
29 |
DataService.initialize(db_hostname="localhost")
|
| 35 |
mc = MemCache("127.0.0.1")
|
30 |
mc = MemCache("127.0.0.1")
|
| Line 39... |
Line 34... |
| 39 |
COLLECTION_MAP = {
|
34 |
COLLECTION_MAP = {
|
| 40 |
'ExceptionalNlc':'skuBundleId',
|
35 |
'ExceptionalNlc':'skuBundleId',
|
| 41 |
'SkuDealerPrices':'skuBundleId',
|
36 |
'SkuDealerPrices':'skuBundleId',
|
| 42 |
'SkuDiscountInfo':'skuBundleId',
|
37 |
'SkuDiscountInfo':'skuBundleId',
|
| 43 |
'SkuSchemeDetails':'skuBundleId',
|
38 |
'SkuSchemeDetails':'skuBundleId',
|
| 44 |
'DealPoints':'skuBundleId',
|
39 |
'DealPoints':'skuBundleId'
|
| 45 |
'FeaturedDeals': 'skuBundleId'
|
- |
|
| 46 |
}
|
40 |
}
|
| 47 |
|
41 |
|
| 48 |
def get_mongo_connection(host='localhost', port=27017):
|
42 |
def get_mongo_connection(host='localhost', port=27017):
|
| 49 |
global con
|
43 |
global con
|
| 50 |
if con is None:
|
44 |
if con is None:
|
| Line 349... |
Line 343... |
| 349 |
temp.append(temp_map)
|
343 |
temp.append(temp_map)
|
| 350 |
brandPrefMap[(x.brand).strip().upper()] = temp
|
344 |
brandPrefMap[(x.brand).strip().upper()] = temp
|
| 351 |
|
345 |
|
| 352 |
for x in session.query(user_actions).filter_by(user_id=userId).all():
|
346 |
for x in session.query(user_actions).filter_by(user_id=userId).all():
|
| 353 |
actionsMap[x.store_product_id] = 1 if x.action == 'like' else 0
|
347 |
actionsMap[x.store_product_id] = 1 if x.action == 'like' else 0
|
| 354 |
all_deals = list(get_mongo_connection().Catalog.Deals.find({"$and":outer_query},{'_id':1,'category_id':1,'brand':1,'totalPoints':1,'bestSellerPoints':1,'nlcPoints':1,'rank':1,'available_price':1,'dealType':1,'source_id':1,'brand_id':1,'skuBundleId':1,'dp':1, 'showDp':1, 'gross_price':1}).sort([('totalPoints',pymongo.DESCENDING),('bestSellerPoints',pymongo.DESCENDING),('nlcPoints',pymongo.DESCENDING),('rank',pymongo.DESCENDING)]))
|
348 |
all_deals = list(get_mongo_connection().Catalog.Deals.find({"$and":outer_query},{'_id':1,'category_id':1,'brand':1,'totalPoints':1,'bestSellerPoints':1,'nlcPoints':1,'rank':1,'available_price':1,'dealType':1,'source_id':1,'brand_id':1,'skuBundleId':1,'dp':1, 'showDp':1}).sort([('totalPoints',pymongo.DESCENDING),('bestSellerPoints',pymongo.DESCENDING),('nlcPoints',pymongo.DESCENDING),('rank',pymongo.DESCENDING)]))
|
| - |
|
349 |
all_category_deals = []
|
| 355 |
mobile_deals = []
|
350 |
mobile_deals = []
|
| 356 |
tablet_deals = []
|
351 |
tablet_deals = []
|
| 357 |
for deal in all_deals:
|
352 |
for deal in all_deals:
|
| 358 |
if actionsMap.get(deal['_id']) == 0:
|
353 |
if actionsMap.get(deal['_id']) == 0:
|
| 359 |
fav_weight =.25
|
354 |
fav_weight =.25
|
| Line 389... |
Line 384... |
| 389 |
mobile_deals.append(deal)
|
384 |
mobile_deals.append(deal)
|
| 390 |
elif deal['category_id'] ==5:
|
385 |
elif deal['category_id'] ==5:
|
| 391 |
tablet_deals.append(deal)
|
386 |
tablet_deals.append(deal)
|
| 392 |
else:
|
387 |
else:
|
| 393 |
continue
|
388 |
continue
|
| - |
|
389 |
all_category_deals.append(deal)
|
| 394 |
|
390 |
|
| 395 |
session.close()
|
391 |
session.close()
|
| 396 |
|
- |
|
| 397 |
mobile_deals = sorted(mobile_deals, key = lambda x: (x['persPoints'],x['totalPoints'],x['bestSellerPoints'], x['nlcPoints'], x['rank']),reverse=True)
|
- |
|
| 398 |
tablet_deals = sorted(tablet_deals, key = lambda x: (x['persPoints'],x['totalPoints'],x['bestSellerPoints'], x['nlcPoints'], x['rank']),reverse=True)
|
- |
|
| 399 |
|
- |
|
| 400 |
try:
|
- |
|
| 401 |
if mc.get("featured_deals") is None:
|
- |
|
| 402 |
__populateFeaturedDeals()
|
- |
|
| 403 |
featuredDeals = mc.get("featured_deals")
|
- |
|
| 404 |
|
- |
|
| 405 |
except Exception as e:
|
- |
|
| 406 |
print traceback.print_exc()
|
- |
|
| 407 |
featuredDeals = {3:{},5:{}}
|
- |
|
| 408 |
print featuredDeals
|
- |
|
| 409 |
|
- |
|
| 410 |
sortedMapMobiles = {}
|
- |
|
| 411 |
rankMapMobiles = {}
|
- |
|
| 412 |
rankMobiles = 0
|
- |
|
| 413 |
|
- |
|
| 414 |
blockedRanksMobiles = []
|
- |
|
| 415 |
blockedSkuBundlesMobiles = []
|
- |
|
| 416 |
blockedInfoMobiles = {}
|
- |
|
| 417 |
|
- |
|
| 418 |
featuredDealsMobiles = featuredDeals.get(3)
|
- |
|
| 419 |
|
- |
|
| 420 |
for k, v in featuredDealsMobiles.iteritems():
|
- |
|
| 421 |
if v.get('category_id') == 3:
|
- |
|
| 422 |
blockedRanksMobiles.append(k-1)
|
- |
|
| 423 |
blockedSkuBundlesMobiles.append(v.get('skuBundleId'))
|
- |
|
| 424 |
|
- |
|
| 425 |
print "Blocked ranks ", blockedRanksMobiles
|
- |
|
| 426 |
print "Blocked bundles ", blockedSkuBundlesMobiles
|
- |
|
| 427 |
|
- |
|
| 428 |
for sorted_deal in mobile_deals:
|
- |
|
| 429 |
while(True):
|
- |
|
| 430 |
if rankMobiles in blockedRanksMobiles:
|
- |
|
| 431 |
print "skipping rank ",rankMobiles
|
- |
|
| 432 |
rankMobiles = rankMobiles +1
|
- |
|
| 433 |
else:
|
- |
|
| 434 |
break
|
- |
|
| 435 |
|
- |
|
| 436 |
if sorted_deal['skuBundleId'] in blockedSkuBundlesMobiles:
|
- |
|
| 437 |
if blockedInfoMobiles.has_key(sorted_deal['skuBundleId']):
|
- |
|
| 438 |
blockedInfoMobiles.get(sorted_deal['skuBundleId']).append(sorted_deal)
|
- |
|
| 439 |
else:
|
- |
|
| 440 |
blockedInfoMobiles[sorted_deal['skuBundleId']] = [sorted_deal]
|
- |
|
| 441 |
continue
|
- |
|
| 442 |
|
- |
|
| 443 |
if sortedMapMobiles.get(sorted_deal['skuBundleId']) is None:
|
- |
|
| 444 |
sortedMapMobiles[sorted_deal['skuBundleId']] = {rankMobiles:[sorted_deal]}
|
- |
|
| 445 |
rankMapMobiles[rankMobiles] = (sortedMapMobiles[sorted_deal['skuBundleId']].values())[0]
|
- |
|
| 446 |
rankMobiles = rankMobiles +1
|
- |
|
| 447 |
else:
|
- |
|
| 448 |
for temp_list in sortedMapMobiles.get(sorted_deal['skuBundleId']).itervalues():
|
- |
|
| 449 |
temp_list.append(sorted_deal)
|
- |
|
| 450 |
rankMapMobiles[(sortedMapMobiles.get(sorted_deal['skuBundleId']).keys())[0]] = temp_list
|
- |
|
| 451 |
|
- |
|
| 452 |
for rank in blockedRanksMobiles:
|
- |
|
| 453 |
print "Adding rank ",rank
|
- |
|
| 454 |
rankMapMobiles[rank] = blockedInfoMobiles.get((featuredDealsMobiles.get(rank+1)).get('skuBundleId'))
|
- |
|
| 455 |
print rankMapMobiles[rank]
|
- |
|
| 456 |
|
- |
|
| 457 |
|
- |
|
| 458 |
sortedMapTablets = {}
|
- |
|
| 459 |
rankMapTablets = {}
|
- |
|
| 460 |
rankTablets = 0
|
- |
|
| 461 |
|
- |
|
| 462 |
blockedRanksTablets = []
|
- |
|
| 463 |
blockedSkuBundlesTablets = []
|
- |
|
| 464 |
blockedInfoTablets = {}
|
- |
|
| 465 |
|
- |
|
| 466 |
featuredDealsTablets = featuredDeals.get(5)
|
- |
|
| 467 |
|
- |
|
| 468 |
|
- |
|
| 469 |
for k, v in featuredDealsTablets.iteritems():
|
- |
|
| 470 |
if v.get('category_id') == 5:
|
- |
|
| 471 |
blockedRanksTablets.append(k-1)
|
- |
|
| 472 |
blockedSkuBundlesTablets.append(v.get('skuBundleId'))
|
- |
|
| 473 |
|
- |
|
| 474 |
print "Blocked ranks ", blockedRanksTablets
|
- |
|
| 475 |
print "Blocked bundles ", blockedSkuBundlesTablets
|
- |
|
| 476 |
|
- |
|
| 477 |
for sorted_deal in tablet_deals:
|
- |
|
| 478 |
while(True):
|
- |
|
| 479 |
if rankTablets in blockedRanksTablets:
|
- |
|
| 480 |
print "skipping rank ",rankTablets
|
- |
|
| 481 |
rankTablets = rankTablets +1
|
- |
|
| 482 |
else:
|
- |
|
| 483 |
break
|
- |
|
| 484 |
|
- |
|
| 485 |
if sorted_deal['skuBundleId'] in blockedSkuBundlesTablets:
|
- |
|
| 486 |
if blockedInfoTablets.has_key(sorted_deal['skuBundleId']):
|
- |
|
| 487 |
blockedInfoTablets.get(sorted_deal['skuBundleId']).append(sorted_deal)
|
- |
|
| 488 |
else:
|
- |
|
| 489 |
blockedInfoTablets[sorted_deal['skuBundleId']] = [sorted_deal]
|
- |
|
| 490 |
continue
|
- |
|
| 491 |
|
- |
|
| 492 |
if sortedMapTablets.get(sorted_deal['skuBundleId']) is None:
|
- |
|
| 493 |
sortedMapTablets[sorted_deal['skuBundleId']] = {rankTablets:[sorted_deal]}
|
- |
|
| 494 |
rankMapTablets[rankTablets] = (sortedMapTablets[sorted_deal['skuBundleId']].values())[0]
|
- |
|
| 495 |
rankTablets = rankTablets +1
|
- |
|
| 496 |
else:
|
- |
|
| 497 |
for temp_list in sortedMapTablets.get(sorted_deal['skuBundleId']).itervalues():
|
- |
|
| 498 |
temp_list.append(sorted_deal)
|
- |
|
| 499 |
rankMapTablets[(sortedMapTablets.get(sorted_deal['skuBundleId']).keys())[0]] = temp_list
|
- |
|
| 500 |
|
- |
|
| 501 |
for rank in blockedRanksTablets:
|
- |
|
| 502 |
print "Adding rank ",rank
|
- |
|
| 503 |
rankMapTablets[rank] = blockedInfoTablets.get((featuredDealsTablets.get(rank+1)).get('skuBundleId'))
|
- |
|
| 504 |
print rankMapTablets[rank]
|
- |
|
| 505 |
|
- |
|
| 506 |
|
- |
|
| 507 |
|
- |
|
| 508 |
|
- |
|
| 509 |
mem_cache_val = {3:mobile_deals, 5:tablet_deals, "3_rankMap": rankMapMobiles,"5_rankMap": rankMapTablets }
|
392 |
mem_cache_val = {3:mobile_deals, 5:tablet_deals, 0:all_deals}
|
| 510 |
mc.set(str(userId), mem_cache_val)
|
393 |
mc.set(str(userId), mem_cache_val)
|
| 511 |
|
394 |
|
| 512 |
|
395 |
|
| 513 |
def __populateFeaturedDeals():
|
396 |
def __populateFeaturedDeals():
|
| 514 |
print "Populating featured deals....."
|
397 |
all_category_fd = []
|
| 515 |
featuredDealsMobiles = {}
|
398 |
mobile_fd = []
|
| 516 |
featuredDealsTablets = {}
|
399 |
tablet_fd = []
|
| 517 |
activeFeaturedDeals = get_mongo_connection().Catalog.FeaturedDeals.find({'startDate':{'$lte':to_java_date(datetime.now())},'endDate':{'$gte':to_java_date(datetime.now())}}).sort([('rank',pymongo.DESCENDING)])
|
400 |
activeFeaturedDeals = get_mongo_connection().Catalog.FeaturedDeals.find({'startDate':{'$lte':to_java_date(datetime.now())},'endDate':{'$gte':to_java_date(datetime.now())}}).sort({'rank':pymongo.ASCENDING})
|
| 518 |
for activeFeaturedDeal in activeFeaturedDeals:
|
401 |
for activeFeaturedDeal in activeFeaturedDeals:
|
| - |
|
402 |
for k,v in activeFeaturedDeal['rankDetails']:
|
| 519 |
deals = get_mongo_connection().Catalog.Deals.find({"skuBundleId":activeFeaturedDeal.get('skuBundleId'),"$or":[{"showDeal":1}, {"prepaidDeal":1}]})
|
403 |
featuredDeal = FeaturedDeals(activeFeaturedDeal['sku'], int(k), activeFeaturedDeal['thresholdPrice'], int(v))
|
| 520 |
for deal in deals:
|
404 |
if featuredDeal.category_id == 0:
|
| 521 |
if deal.get('available_price') <= activeFeaturedDeal.get('thresholdPrice'):
|
405 |
all_category_fd.append(featuredDeal)
|
| 522 |
f_deal = {'skuBundleId':activeFeaturedDeal.get('skuBundleId'), 'thresholdPrice':activeFeaturedDeal.get('thresholdPrice'), 'rank':activeFeaturedDeal.get('rank'),'category_id':activeFeaturedDeal.get('category_id')}
|
- |
|
| 523 |
if activeFeaturedDeal.get('category_id') == 3:
|
406 |
elif featuredDeal.category_id == 3:
|
| 524 |
featuredDealsMobiles[activeFeaturedDeal.get('rank')] = f_deal
|
407 |
mobile_fd.append(featuredDeal)
|
| 525 |
else:
|
408 |
elif featuredDeal.category_id == 5:
|
| 526 |
featuredDealsTablets[activeFeaturedDeal.get('rank')] = f_deal
|
409 |
tablet_fd.append(featuredDeal)
|
| 527 |
break
|
410 |
else:
|
| 528 |
|
411 |
continue
|
| - |
|
412 |
mc.set("featured_deals_category_"+str(0), all_category_fd, 3600)
|
| 529 |
mc.set("featured_deals", {3:featuredDealsMobiles,5:featuredDealsTablets}, 600)
|
413 |
mc.set("featured_deals_category_"+str(3), mobile_fd, 3600)
|
| 530 |
print mc.get("featured_deals")
|
414 |
mc.set("featured_deals_category_"+str(5), tablet_fd, 3600)
|
| 531 |
|
415 |
|
| 532 |
def getNewDeals(userId, category_id, offset, limit, sort, direction, filterData=None):
|
416 |
def getNewDeals(userId, category_id, offset, limit, sort, direction, filterData=None):
|
| 533 |
if not bool(mc.get("category_cash_back")):
|
417 |
if not bool(mc.get("category_cash_back")):
|
| 534 |
populateCashBack()
|
418 |
populateCashBack()
|
| 535 |
|
419 |
|
| - |
|
420 |
try:
|
| - |
|
421 |
if mc.get("featured_deals_category_"+str(category_id)) is None:
|
| - |
|
422 |
__populateFeaturedDeals()
|
| - |
|
423 |
except:
|
| - |
|
424 |
pass
|
| - |
|
425 |
|
| - |
|
426 |
rank = 1
|
| 536 |
dealsListMap = []
|
427 |
dealsListMap = []
|
| 537 |
user_specific_deals = mc.get(str(userId))
|
428 |
user_specific_deals = mc.get(str(userId))
|
| 538 |
if user_specific_deals is None:
|
429 |
if user_specific_deals is None:
|
| 539 |
__populateCache(userId)
|
430 |
__populateCache(userId)
|
| 540 |
user_specific_deals = mc.get(str(userId))
|
431 |
user_specific_deals = mc.get(str(userId))
|
| 541 |
else:
|
432 |
else:
|
| 542 |
print "Getting user deals from cache"
|
433 |
print "Getting user deals from cache"
|
| 543 |
category_specific_deals = user_specific_deals.get(category_id)
|
434 |
category_specific_deals = user_specific_deals.get(category_id)
|
| 544 |
|
435 |
|
| 545 |
insert_featured_deals = False
|
- |
|
| 546 |
if sort is None or direction is None:
|
436 |
if sort is None or direction is None:
|
| 547 |
insert_featured_deals = True
|
- |
|
| 548 |
rankMap = user_specific_deals.get(str(category_id)+"_rankMap")
|
437 |
sorted_deals = sorted(category_specific_deals, key = lambda x: (x['persPoints'],x['totalPoints'],x['bestSellerPoints'], x['nlcPoints'], x['rank']),reverse=True)
|
| 549 |
else:
|
438 |
else:
|
| 550 |
if sort == "bestSellerPoints":
|
439 |
if sort == "bestSellerPoints":
|
| 551 |
sorted_deals = sorted(category_specific_deals, key = lambda x: (x['bestSellerPoints'], x['rank'], x['nlcPoints']),reverse=True)
|
440 |
sorted_deals = sorted(category_specific_deals, key = lambda x: (x['bestSellerPoints'], x['rank'], x['nlcPoints']),reverse=True)
|
| 552 |
else:
|
441 |
else:
|
| 553 |
if direction == -1:
|
442 |
if direction == -1:
|
| Line 556... |
Line 445... |
| 556 |
rev = False
|
445 |
rev = False
|
| 557 |
sorted_deals = sorted(category_specific_deals, key = lambda x: (x['available_price']),reverse=rev)
|
446 |
sorted_deals = sorted(category_specific_deals, key = lambda x: (x['available_price']),reverse=rev)
|
| 558 |
|
447 |
|
| 559 |
|
448 |
|
| 560 |
print "============================"
|
449 |
print "============================"
|
| 561 |
filtered_deals = []
|
- |
|
| 562 |
if filterData is not None:
|
450 |
if filterData is not None:
|
| 563 |
try:
|
451 |
try:
|
| 564 |
filtered_deals = filterDeals(category_specific_deals, filterData)
|
452 |
sorted_deals = filterDeals(sorted_deals, filterData)
|
| 565 |
except:
|
453 |
except:
|
| 566 |
traceback.print_exc()
|
454 |
traceback.print_exc()
|
| 567 |
|
455 |
|
| 568 |
if not insert_featured_deals:
|
456 |
|
| 569 |
sortedMap = {}
|
457 |
sortedMap = {}
|
| 570 |
rankMap = {}
|
458 |
rankMap = {}
|
| 571 |
rank = 0
|
459 |
rank = 0
|
| 572 |
for sorted_deal in sorted_deals:
|
460 |
for sorted_deal in sorted_deals:
|
| 573 |
|
- |
|
| 574 |
if len(filtered_deals) > 0 and sorted_deal['skuBundleId'] not in filtered_deals:
|
- |
|
| 575 |
continue
|
- |
|
| 576 |
|
- |
|
| 577 |
if sortedMap.get(sorted_deal['skuBundleId']) is None:
|
461 |
if sortedMap.get(sorted_deal['skuBundleId']) is None:
|
| 578 |
sortedMap[sorted_deal['skuBundleId']] = {rank:[sorted_deal]}
|
462 |
sortedMap[sorted_deal['skuBundleId']] = {rank:[sorted_deal]}
|
| 579 |
rankMap[rank] = (sortedMap[sorted_deal['skuBundleId']].values())[0]
|
463 |
rankMap[rank] = (sortedMap[sorted_deal['skuBundleId']].values())[0]
|
| 580 |
rank = rank +1
|
464 |
rank = rank +1
|
| 581 |
else:
|
465 |
else:
|
| 582 |
for temp_list in sortedMap.get(sorted_deal['skuBundleId']).itervalues():
|
466 |
for temp_list in sortedMap.get(sorted_deal['skuBundleId']).itervalues():
|
| 583 |
temp_list.append(sorted_deal)
|
467 |
temp_list.append(sorted_deal)
|
| 584 |
rankMap[(sortedMap.get(sorted_deal['skuBundleId']).keys())[0]] = temp_list
|
468 |
rankMap[(sortedMap.get(sorted_deal['skuBundleId']).keys())[0]] = temp_list
|
| 585 |
else:
|
- |
|
| 586 |
filterMap = {}
|
- |
|
| 587 |
rank = 0
|
- |
|
| 588 |
if len(filtered_deals) > 0:
|
- |
|
| 589 |
try:
|
469 |
|
| 590 |
od = collections.OrderedDict(sorted(rankMap.items()))
|
- |
|
| 591 |
except:
|
- |
|
| 592 |
od = ordereddict.OrderedDict(sorted(rankMap.items()))
|
- |
|
| 593 |
for k, v in od.iteritems():
|
- |
|
| 594 |
if v[0].get('skuBundleId') in filtered_deals:
|
- |
|
| 595 |
filterMap[rank] = v
|
- |
|
| 596 |
rank =rank+1
|
- |
|
| 597 |
rankMap = filterMap
|
- |
|
| 598 |
|
- |
|
| 599 |
for dealList in [rankMap.get(k, []) for k in range(offset, offset+limit)]:
|
470 |
for dealList in [rankMap.get(k, []) for k in range(offset, offset+limit)]:
|
| 600 |
temp = []
|
471 |
temp = []
|
| 601 |
for d in dealList:
|
472 |
for d in dealList:
|
| 602 |
item = list(get_mongo_connection().Catalog.MasterData.find({'_id':d['_id']}))
|
473 |
item = list(get_mongo_connection().Catalog.MasterData.find({'_id':d['_id']}))
|
| 603 |
if len(item) ==0:
|
474 |
if len(item) ==0:
|
| Line 677... |
Line 548... |
| 677 |
brandsFiltered = deals
|
548 |
brandsFiltered = deals
|
| 678 |
for deal in deals:
|
549 |
for deal in deals:
|
| 679 |
if str(int(deal['brand_id'])) in toFilter:
|
550 |
if str(int(deal['brand_id'])) in toFilter:
|
| 680 |
brandsFiltered.append(deal)
|
551 |
brandsFiltered.append(deal)
|
| 681 |
if len(dealFiltered) == 0:
|
552 |
if len(dealFiltered) == 0:
|
| 682 |
return [trend['skuBundleId'] for trend in brandsFiltered]
|
553 |
return brandsFiltered
|
| 683 |
return [i['skuBundleId'] for i in dealFiltered for j in brandsFiltered if i['_id']==j['_id']]
|
554 |
return [i for i in dealFiltered for j in brandsFiltered if i['_id']==j['_id']]
|
| 684 |
|
555 |
|
| 685 |
|
556 |
|
| 686 |
def getDeals(userId, category_id, offset, limit, sort, direction):
|
557 |
def getDeals(userId, category_id, offset, limit, sort, direction):
|
| 687 |
if not bool(mc.get("category_cash_back")):
|
558 |
if not bool(mc.get("category_cash_back")):
|
| 688 |
populateCashBack()
|
559 |
populateCashBack()
|
| Line 1108... |
Line 979... |
| 1108 |
return data
|
979 |
return data
|
| 1109 |
|
980 |
|
| 1110 |
def getAllFeaturedDeals(offset, limit):
|
981 |
def getAllFeaturedDeals(offset, limit):
|
| 1111 |
data = []
|
982 |
data = []
|
| 1112 |
collection = get_mongo_connection().Catalog.FeaturedDeals
|
983 |
collection = get_mongo_connection().Catalog.FeaturedDeals
|
| 1113 |
cursor = collection.find({})
|
984 |
cursor = collection.find({'endDate':{'$gte':to_java_date(datetime.now())}}).skip(offset).limit(limit)
|
| 1114 |
for val in cursor:
|
985 |
for val in cursor:
|
| 1115 |
master = list(get_mongo_connection().Catalog.MasterData.find({'skuBundleId':val['skuBundleId']}))
|
986 |
master = list(get_mongo_connection().Catalog.MasterData.find({'_id':val['sku']}))
|
| 1116 |
if len(master) > 0:
|
987 |
if len(master) > 0:
|
| 1117 |
val['brand'] = master[0]['brand']
|
988 |
val['brand'] = master[0]['brand']
|
| 1118 |
val['source_product_name'] = master[0]['source_product_name']
|
989 |
val['source_product_name'] = master[0]['source_product_name']
|
| 1119 |
val['skuBundleId'] = master[0]['skuBundleId']
|
990 |
val['skuBundleId'] = master[0]['skuBundleId']
|
| 1120 |
val['category'] = 'Mobiles' if val['category_id'] == 3 else 'Tablets'
|
- |
|
| 1121 |
else:
|
991 |
else:
|
| 1122 |
val['brand'] = ""
|
992 |
val['brand'] = ""
|
| 1123 |
val['source_product_name'] = ""
|
993 |
val['source_product_name'] = ""
|
| 1124 |
val['skuBundleId'] = ""
|
994 |
val['skuBundleId'] = ""
|
| 1125 |
val['category'] = ""
|
- |
|
| 1126 |
data.append(val)
|
995 |
data.append(val)
|
| 1127 |
return data
|
996 |
return data
|
| 1128 |
|
997 |
|
| 1129 |
def addFeaturedDeal(data, multi):
|
998 |
def addFeaturedDeal(data, multi):
|
| 1130 |
collection = get_mongo_connection().Catalog.FeaturedDeals
|
- |
|
| 1131 |
cursor = collection.find({'skuBundleId':data['skuBundleId']})
|
- |
|
| 1132 |
master = get_mongo_connection().Catalog.MasterData.find_one({'skuBundleId':data['skuBundleId']})
|
- |
|
| 1133 |
if master is None:
|
999 |
if multi !=1:
|
| 1134 |
return {0:"BundleId is wrong"}
|
1000 |
collection = get_mongo_connection().Catalog.FeaturedDeals
|
| 1135 |
data['category_id'] = master['category_id']
|
- |
|
| 1136 |
exist = collection.find({'rank':data['rank'],'category_id':data['category_id']})
|
1001 |
cursor = collection.find({'sku':data['sku'],'startDate':{'$lte':data['startDate']},'endDate':{'$gte':data['endDate']}})
|
| 1137 |
if cursor.count() > 0:
|
1002 |
if cursor.count() > 0:
|
| 1138 |
return {0:"SkuBundleId information already present."}
|
1003 |
return {0:"Sku information already present."}
|
| - |
|
1004 |
else:
|
| 1139 |
elif exist.count() >0:
|
1005 |
collection.insert(data)
|
| - |
|
1006 |
get_mongo_connection().Catalog.MasterData.update({'_id':data['sku']},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=False)
|
| 1140 |
return {0:"Rank already assigned bundleId %s"%(exist[0]['skuBundleId'])}
|
1007 |
return {1:"Data added successfully"}
|
| 1141 |
else:
|
1008 |
else:
|
| - |
|
1009 |
skuIds = __getBundledSkusfromSku(data['sku'])
|
| - |
|
1010 |
for sku in skuIds:
|
| - |
|
1011 |
data['sku'] = sku.get('_id')
|
| - |
|
1012 |
collection = get_mongo_connection().Catalog.FeaturedDeals
|
| - |
|
1013 |
cursor = collection.find({'sku':data['sku'],'startDate':{'$lte':data['startDate']},'endDate':{'$gte':data['endDate']}})
|
| - |
|
1014 |
if cursor.count() > 0:
|
| - |
|
1015 |
continue
|
| - |
|
1016 |
else:
|
| - |
|
1017 |
data.pop('_id',None)
|
| 1142 |
collection.insert(data)
|
1018 |
collection.insert(data)
|
| - |
|
1019 |
get_mongo_connection().Catalog.MasterData.update({'skuBundleId':sku.get('skuBundleId')},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=True)
|
| 1143 |
return {1:"Data added successfully"}
|
1020 |
return {1:"Data added successfully"}
|
| 1144 |
|
1021 |
|
| 1145 |
def searchCollection(class_name, sku, skuBundleId):
|
1022 |
def searchCollection(class_name, sku, skuBundleId):
|
| 1146 |
data = []
|
1023 |
data = []
|
| 1147 |
collection = get_mongo_connection().Catalog[class_name]
|
1024 |
collection = get_mongo_connection().Catalog[class_name]
|
| Line 1833... |
Line 1710... |
| 1833 |
returnObj = []
|
1710 |
returnObj = []
|
| 1834 |
for deal in all_deals:
|
1711 |
for deal in all_deals:
|
| 1835 |
item = list(get_mongo_connection().Catalog.MasterData.find({'_id':deal['_id']}))
|
1712 |
item = list(get_mongo_connection().Catalog.MasterData.find({'_id':deal['_id']}))
|
| 1836 |
returnObj.append(getItemObjForStaticDeals(item[0]))
|
1713 |
returnObj.append(getItemObjForStaticDeals(item[0]))
|
| 1837 |
return returnObj
|
1714 |
return returnObj
|
| 1838 |
|
- |
|
| 1839 |
def searchDummyDeals(search_term , limit):
|
- |
|
| 1840 |
data = []
|
- |
|
| 1841 |
uniqueMap = {}
|
- |
|
| 1842 |
if search_term is not None:
|
- |
|
| 1843 |
terms = search_term.split(' ')
|
- |
|
| 1844 |
outer_query = []
|
- |
|
| 1845 |
for term in terms:
|
- |
|
| 1846 |
outer_query.append({"source_product_name":re.compile(term, re.IGNORECASE)})
|
- |
|
| 1847 |
try:
|
- |
|
| 1848 |
collection = get_mongo_connection().Catalog.MasterData.find({"$and":outer_query,'source_id':{'$in':SOURCE_MAP.keys()}})
|
- |
|
| 1849 |
for record in collection:
|
- |
|
| 1850 |
data.append(record)
|
- |
|
| 1851 |
except:
|
- |
|
| 1852 |
pass
|
- |
|
| 1853 |
else:
|
- |
|
| 1854 |
collection = get_mongo_connection().Catalog.MasterData.find({'source_id':{'$in':SOURCE_MAP.keys()}})
|
- |
|
| 1855 |
for record in collection:
|
- |
|
| 1856 |
data.append(record)
|
- |
|
| 1857 |
for x in data:
|
- |
|
| 1858 |
if not uniqueMap.has_key(x['skuBundleId']):
|
- |
|
| 1859 |
uniqueMap[x['skuBundleId']] = {'source_product_name':x['source_product_name'],'skuBundleId':x['skuBundleId']}
|
- |
|
| 1860 |
return uniqueMap.values()[0:limit]
|
- |
|
| 1861 |
|
- |
|
| 1862 |
|
- |
|
| 1863 |
|
- |
|
| 1864 |
|
- |
|
| 1865 |
|
- |
|
| 1866 |
|
1715 |
|
| 1867 |
def main():
|
1716 |
def main():
|
| 1868 |
#generateRedirectUrl(101,1)
|
1717 |
#generateRedirectUrl(101,1)
|
| 1869 |
print datetime.now()
|
- |
|
| 1870 |
x= getNewDeals(47, 3, 0, 500, None, None, None)
|
- |
|
| 1871 |
print datetime.now()
|
1718 |
print getDummyDeals(3, 0, 10)
|
| 1872 |
#print addPayout("10", "55db82c0bcabd7fc59e0a71")
|
1719 |
#print addPayout("10", "55db82c0bcabd7fc59e0a71")
|
| 1873 |
#data = {'skuBundleId':32111,'rank':200,'thresholdPrice':10000,'startDate':to_java_date(datetime.now()),'endDate':to_java_date(datetime.now)}
|
- |
|
| 1874 |
#print addFeaturedDeal(data, None)
|
- |
|
| 1875 |
#getAllFeaturedDeals(0, 50)
|
- |
|
| 1876 |
|
1720 |
|
| 1877 |
|
1721 |
|
| 1878 |
|
1722 |
|
| 1879 |
if __name__=='__main__':
|
1723 |
if __name__=='__main__':
|
| 1880 |
main()
|
1724 |
main()
|