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