Subversion Repositories SmartDukaan

Rev

Rev 14628 | Rev 14640 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
14305 amit.gupta 1
from bson.objectid import ObjectId
2
from datetime import datetime, timedelta
3
from dtr.config import PythonPropertyReader
13927 amit.gupta 4
from dtr.main import Store
14531 kshitij.so 5
from dtr.dao import FeaturedDeals
14037 kshitij.so 6
from dtr.storage import DataService
7
from dtr.storage.DataService import price_preferences, brand_preferences, \
14305 amit.gupta 8
    user_actions
14037 kshitij.so 9
from dtr.storage.MemCache import MemCache
14305 amit.gupta 10
from dtr.utils.utils import to_java_date
11
from elixir import *
12
from operator import itemgetter
13
import pymongo
14322 kshitij.so 14
import re
13572 kshitij.so 15
 
16
con = None
13907 kshitij.so 17
cashBackMap = {}
13921 kshitij.so 18
itemCashBackMap = {}
13572 kshitij.so 19
 
14037 kshitij.so 20
DataService.initialize(db_hostname="localhost")
21
mc = MemCache("127.0.0.1")
22
 
14482 kshitij.so 23
SOURCE_MAP = {1:'AMAZON',2:'FLIPKART',3:'SNAPDEAL',4:'SAHOLIC'}
24
 
13572 kshitij.so 25
def get_mongo_connection(host='localhost', port=27017):
26
    global con
27
    if con is None:
28
        print "Establishing connection %s host and port %d" %(host,port)
29
        try:
30
            con = pymongo.MongoClient(host, port)
31
        except Exception, e:
32
            print e
33
            return None
34
    return con
35
 
13907 kshitij.so 36
def populateCashBack():
13921 kshitij.so 37
    print "Populating cashback"
13907 kshitij.so 38
    global cashBackMap
13921 kshitij.so 39
    global itemCashBackMap
40
    cashBackMap = {}
41
    itemCashBackMap = {}
13907 kshitij.so 42
    cashBack = list(get_mongo_connection().Catalog.CategoryCashBack.find())
43
    for row in cashBack:
13970 kshitij.so 44
        temp_map = {}
45
        temp_list = []
13907 kshitij.so 46
        if cashBackMap.has_key(row['source_id']):
47
            arr = cashBackMap.get(row['source_id'])
48
            for val in arr:
49
                temp_list.append(val)
50
            temp_map[row['category_id']] = row
51
            temp_list.append(temp_map)
52
            cashBackMap[row['source_id']] = temp_list 
53
        else:
54
            temp_map[row['category_id']] = row
55
            temp_list.append(temp_map)
56
            cashBackMap[row['source_id']] = temp_list
13921 kshitij.so 57
    itemCashBack = list(get_mongo_connection().Catalog.ItemCashBack.find())
58
    for row in itemCashBack:
59
        if not itemCashBackMap.has_key(row['skuId']):
60
            itemCashBackMap[row['skuId']] = row
13907 kshitij.so 61
 
13572 kshitij.so 62
def addCategoryDiscount(data):
13970 kshitij.so 63
    collection = get_mongo_connection().Catalog.CategoryDiscount
13572 kshitij.so 64
    query = []
65
    data['brand'] = data['brand'].strip().upper()
13970 kshitij.so 66
    data['discountType'] = data['discountType'].upper().strip()
13572 kshitij.so 67
    query.append({"brand":data['brand']})
68
    query.append({"category_id":data['category_id']})
69
    r = collection.find({"$and":query})
70
    if r.count() > 0:
13639 kshitij.so 71
        return {0:"Brand & Category info already present."}
13572 kshitij.so 72
    else:
73
        collection.insert(data)
13970 kshitij.so 74
        get_mongo_connection().Catalog.MasterData.update({'brand':data['brand'],'category_id':data['category_id']},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=True)
13639 kshitij.so 75
        return {1:"Data added successfully"}
13572 kshitij.so 76
 
13970 kshitij.so 77
def updateCategoryDiscount(data,_id):
78
    try:
79
        collection = get_mongo_connection().Catalog.CategoryDiscount
80
        collection.update({'_id':ObjectId(_id)},{"$set":{'min_discount':data['min_discount'],'max_discount':data['max_discount'],'discountType':data['discountType'].upper().strip()}},upsert=False, multi = False)
81
        get_mongo_connection().Catalog.MasterData.update({'brand':data['brand'],'category_id':data['category_id']},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=True)
82
        return {1:"Data updated successfully"}
83
    except:
84
        return {0:"Data not updated."}
85
 
86
 
13572 kshitij.so 87
def getAllCategoryDiscount():
88
    data = []
13970 kshitij.so 89
    collection = get_mongo_connection().Catalog.CategoryDiscount
13572 kshitij.so 90
    cursor = collection.find()
91
    for val in cursor:
92
        data.append(val)
93
    return data
94
 
14553 kshitij.so 95
def __getBundledSkusfromSku(sku):
96
    masterData =  get_mongo_connection().Catalog.MasterData.find_one({"_id":sku},{"skuBundleId":1})
97
    if masterData is not None:
98
        return list(get_mongo_connection().Catalog.MasterData.find({"skuBundleId":masterData.get('skuBundleId')},{'_id':1,'skuBundleId':1}))
99
    else:
100
        return []
13572 kshitij.so 101
 
14553 kshitij.so 102
def addSchemeDetailsForSku(data, multi):
103
    if multi ==1:
104
        skuIds = __getBundledSkusfromSku(data['sku'])
105
        for sku in skuIds:
106
            collection = get_mongo_connection().Catalog.SkuSchemeDetails
107
            data['sku'] = sku.get('_id')
108
            data['addedOn'] = to_java_date(datetime.now())
14558 kshitij.so 109
            data.pop('_id',None)
14553 kshitij.so 110
            collection.insert(data)
111
        get_mongo_connection().Catalog.MasterData.update({'skuBundleId':sku.get('skuBundleId')},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=True)
14559 kshitij.so 112
        return {1:"Data added successfully"}
14553 kshitij.so 113
    else:
114
        collection = get_mongo_connection().Catalog.SkuSchemeDetails
115
        data['addedOn'] = to_java_date(datetime.now())
116
        collection.insert(data)
117
        get_mongo_connection().Catalog.MasterData.update({'_id':data['sku']},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=False)
118
        return {1:"Data added successfully"}
119
 
14069 kshitij.so 120
def getAllSkuWiseSchemeDetails(offset, limit):
13572 kshitij.so 121
    data = []
13970 kshitij.so 122
    collection = get_mongo_connection().Catalog.SkuSchemeDetails
14071 kshitij.so 123
    cursor = collection.find().skip(offset).limit(limit)
13572 kshitij.so 124
    for val in cursor:
14069 kshitij.so 125
        master = list(get_mongo_connection().Catalog.MasterData.find({'_id':val['sku']}))
126
        if len(master) > 0:
127
            val['brand'] = master[0]['brand']
128
            val['source_product_name'] = master[0]['source_product_name']
129
            val['skuBundleId'] = master[0]['skuBundleId']
130
        else:
131
            val['brand'] = ""
132
            val['source_product_name'] = ""
133
            val['skuBundleId'] = ""
13572 kshitij.so 134
        data.append(val)
135
    return data
136
 
14553 kshitij.so 137
def addSkuDiscountInfo(data, multi):
138
    if multi != 1:
139
        collection = get_mongo_connection().Catalog.SkuDiscountInfo
140
        cursor = collection.find({"sku":data['sku']})
141
        if cursor.count() > 0:
142
            return {0:"Sku information already present."}
143
        else:
144
            collection.insert(data)
145
            get_mongo_connection().Catalog.MasterData.update({'_id':data['sku']},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=False)
146
            return {1:"Data added successfully"}
13572 kshitij.so 147
    else:
14553 kshitij.so 148
        skuIds = __getBundledSkusfromSku(data['sku'])
149
        for sku in skuIds:
150
            data['sku'] = sku.get('_id')
151
            collection = get_mongo_connection().Catalog.SkuDiscountInfo
152
            cursor = collection.find({"sku":data['sku']})
153
            if cursor.count() > 0:
154
                continue
155
            else:
14558 kshitij.so 156
                data.pop('_id',None)
14553 kshitij.so 157
                collection.insert(data)
158
        get_mongo_connection().Catalog.MasterData.update({'skuBundleId':sku.get('skuBundleId')},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=True)
13639 kshitij.so 159
        return {1:"Data added successfully"}
13572 kshitij.so 160
 
13970 kshitij.so 161
def getallSkuDiscountInfo(offset, limit):
13572 kshitij.so 162
    data = []
13970 kshitij.so 163
    collection = get_mongo_connection().Catalog.SkuDiscountInfo
164
    cursor = collection.find().skip(offset).limit(limit)
13572 kshitij.so 165
    for val in cursor:
13970 kshitij.so 166
        master = list(get_mongo_connection().Catalog.MasterData.find({'_id':val['sku']}))
167
        if len(master) > 0:
14069 kshitij.so 168
            val['brand'] = master[0]['brand']
169
            val['source_product_name'] = master[0]['source_product_name']
170
            val['skuBundleId'] = master[0]['skuBundleId']
13970 kshitij.so 171
        else:
172
            val['brand'] = ""
173
            val['source_product_name'] = ""
174
            val['skuBundleId'] = ""
13572 kshitij.so 175
        data.append(val)
176
    return data
177
 
13970 kshitij.so 178
def updateSkuDiscount(data,_id):
179
    try:
180
        collection = get_mongo_connection().Catalog.SkuDiscountInfo
181
        collection.update({'_id':ObjectId(_id)},{"$set":{'min_discount':data['min_discount'],'max_discount':data['max_discount'],'discountType':data['discountType'].upper().strip()}},upsert=False, multi = False)
182
        get_mongo_connection().Catalog.MasterData.update({'_id':data['sku']},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=False)
183
        return {1:"Data updated successfully"}
184
    except:
185
        return {0:"Data not updated."}
186
 
187
 
14553 kshitij.so 188
def addExceptionalNlc(data, multi):
189
    if multi!=1:
190
        collection = get_mongo_connection().Catalog.ExceptionalNlc
191
        cursor = collection.find({"sku":data['sku']})
192
        if cursor.count() > 0:
193
            return {0:"Sku information already present."}
194
        else:
195
            collection.insert(data)
196
            get_mongo_connection().Catalog.MasterData.update({'_id':data['sku']},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=False)
197
            return {1:"Data added successfully"}
13572 kshitij.so 198
    else:
14553 kshitij.so 199
        skuIds = __getBundledSkusfromSku(data['sku'])
200
        for sku in skuIds:
201
            data['sku'] = sku.get('_id')
202
            collection = get_mongo_connection().Catalog.ExceptionalNlc
203
            cursor = collection.find({"sku":data['sku']})
204
            if cursor.count() > 0:
205
                continue
206
            else:
14558 kshitij.so 207
                data.pop('_id',None)
14553 kshitij.so 208
                collection.insert(data)
209
        get_mongo_connection().Catalog.MasterData.update({'skuBundleId':sku.get('skuBundleId')},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=True)
13639 kshitij.so 210
        return {1:"Data added successfully"}
14553 kshitij.so 211
 
212
 
13572 kshitij.so 213
 
13970 kshitij.so 214
def getAllExceptionlNlcItems(offset, limit):
13572 kshitij.so 215
    data = []
13970 kshitij.so 216
    collection = get_mongo_connection().Catalog.ExceptionalNlc
14071 kshitij.so 217
    cursor = collection.find().skip(offset).limit(limit)
13572 kshitij.so 218
    for val in cursor:
13970 kshitij.so 219
        master = list(get_mongo_connection().Catalog.MasterData.find({'_id':val['sku']}))
220
        if len(master) > 0:
14069 kshitij.so 221
            val['brand'] = master[0]['brand']
222
            val['source_product_name'] = master[0]['source_product_name']
223
            val['skuBundleId'] = master[0]['skuBundleId']
13970 kshitij.so 224
        else:
225
            val['brand'] = ""
226
            val['source_product_name'] = ""
227
            val['skuBundleId'] = ""
13572 kshitij.so 228
        data.append(val)
229
    return data
230
 
14005 amit.gupta 231
def getMerchantOrdersByUser(userId, page=1, window=50, searchMap={}):
232
    if searchMap is None:
233
        searchMap = {}
13603 amit.gupta 234
    if page==None:
235
        page = 1
236
 
237
    if window==None:
238
        window = 50
239
    result = {}
13582 amit.gupta 240
    skip = (page-1)*window
14005 amit.gupta 241
 
14353 amit.gupta 242
    if userId is not None:
243
        searchMap['userId'] = userId
13603 amit.gupta 244
    collection = get_mongo_connection().Dtr.merchantOrder
14609 amit.gupta 245
    cursor = collection.find(searchMap).sort("orderId",-1)
13603 amit.gupta 246
    total_count = cursor.count()
247
    pages = total_count/window + (0 if total_count%window==0 else 1)  
248
    print "total_count", total_count
249
    if total_count > skip:
13999 amit.gupta 250
        cursor = cursor.skip(skip).limit(window)
13603 amit.gupta 251
        orders = []
252
        for order in cursor:
14002 amit.gupta 253
            del(order["_id"])
254
            orders.append(order)
13603 amit.gupta 255
        result['data'] = orders
256
        result['window'] = window
257
        result['totalCount'] = total_count 
258
        result['currCount'] = cursor.count()
259
        result['totalPages'] = pages
260
        result['currPage'] = page    
261
        return result
262
    else:
263
        return result
13630 kshitij.so 264
 
13927 amit.gupta 265
def getRefunds(userId, page=1, window=10):
266
    if page==None:
267
        page = 1
268
 
269
    if window==None:
13995 amit.gupta 270
        window = 10
13927 amit.gupta 271
    result = {}
272
    skip = (page-1)*window
273
    collection = get_mongo_connection().Dtr.refund
274
    cursor = collection.find({"userId":userId})
275
    total_count = cursor.count()
276
    pages = total_count/window + (0 if total_count%window==0 else 1)  
277
    print "total_count", total_count
278
    if total_count > skip:
13991 amit.gupta 279
        cursor = cursor.skip(skip).limit(window).sort([('batchId',-1)])
13927 amit.gupta 280
        refunds = []
281
        for refund in cursor:
282
            del(refund["_id"])
283
            refunds.append(refund)
284
        result['data'] = refunds
285
        result['window'] = window
286
        result['totalCount'] = total_count 
287
        result['currCount'] = cursor.count()
288
        result['totalPages'] = pages
289
        result['currPage'] = page    
290
        return result
291
    else:
292
        return result
293
 
294
def getPendingRefunds(userId):
13991 amit.gupta 295
    print type(userId)
13927 amit.gupta 296
    result = get_mongo_connection().Dtr.merchantOrder\
297
        .aggregate([
298
                    {'$match':{'subOrders.cashBackStatus':Store.CB_APPROVED, 'userId':userId}},
299
                    {'$unwind':"$subOrders"},
300
                    { 
301
                     '$group':{
302
                               '_id':None,
303
                               'amount': { '$sum':'$subOrders.cashBackAmount'},
304
                               }
305
                     }
13987 amit.gupta 306
                ])['result']
307
 
308
    if len(result)>0:
309
        result = result[0]        
310
        result.pop("_id")
311
    else:
312
        result={}
313
        result['amount'] = 0.0
14305 amit.gupta 314
    result['nextCredit'] = datetime.strftime(next_weekday(datetime.now(), int(PythonPropertyReader.getConfig('CREDIT_DAY_OF_WEEK'))),"%Y-%m-%d %H:%M:%S")
13927 amit.gupta 315
    return result
14037 kshitij.so 316
 
317
def __populateCache(userId):
318
    print "Populating memcache for userId",userId
319
    outer_query = []
320
    outer_query.append({"showDeal":1})
321
    query = {}
322
    query['$gt'] = 0
323
    outer_query.append({'totalPoints':query})
324
    brandPrefMap = {}
325
    pricePrefMap = {}
326
    actionsMap = {}
327
    brand_p = session.query(price_preferences).filter_by(user_id=userId).all()
328
    for x in brand_p:
329
        pricePrefMap[x.category_id] = [x.min_price,x.max_price]
330
    for x in session.query(brand_preferences).filter_by(user_id=userId).all():
331
        temp_map = {}
332
        if brandPrefMap.has_key((x.brand).strip().upper()):
333
            val = brandPrefMap.get((x.brand).strip().upper())
334
            temp_map[x.category_id] = 1 if x.status == 'show' else 0
335
            val.append(temp_map)
336
        else:
337
            temp = []
338
            temp_map[x.category_id] = 1 if x.status == 'show' else 0
339
            temp.append(temp_map)
340
            brandPrefMap[(x.brand).strip().upper()] = temp
341
 
342
    for x in session.query(user_actions).filter_by(user_id=userId).all():
343
        actionsMap[x.store_product_id] = 1 if x.action == 'like' else 0
14323 kshitij.so 344
    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}).sort([('totalPoints',pymongo.DESCENDING),('bestSellerPoints',pymongo.DESCENDING),('nlcPoints',pymongo.DESCENDING),('rank',pymongo.DESCENDING)]))
14037 kshitij.so 345
    all_category_deals = []
346
    mobile_deals = []
347
    tablet_deals = []
348
    for deal in all_deals:
349
        if actionsMap.get(deal['_id']) == 0:
350
            fav_weight =.25
351
        elif actionsMap.get(deal['_id']) == 1:
352
            fav_weight = 1.5
353
        else:
354
            fav_weight = 1
355
 
356
        if brandPrefMap.get(deal['brand'].strip().upper()) is not None:
357
            brand_weight = 1
358
            for brandInfo in brandPrefMap.get(deal['brand'].strip().upper()):
359
                if brandInfo.get(deal['category_id']) is not None:
360
                    if brandInfo.get(deal['category_id']) == 1:
14055 kshitij.so 361
                        brand_weight = 2.0
14037 kshitij.so 362
        else:
363
            brand_weight = 1
364
 
365
        if pricePrefMap.get(deal['category_id']) is not None:
366
 
367
            if deal['available_price'] >= pricePrefMap.get(deal['category_id'])[0] and deal['available_price'] <= pricePrefMap.get(deal['category_id'])[1]:
368
                asp_weight = 1.5
369
            elif  deal['available_price'] >= pricePrefMap.get(deal['category_id'])[0] - 0.5 * pricePrefMap.get(deal['category_id'])[0] and deal['available_price'] <= pricePrefMap.get(deal['category_id'])[1] + 0.5 * pricePrefMap.get(deal['category_id'])[1]:
370
                asp_weight = 1.2
371
            else:
372
                asp_weight = 1
373
        else:
374
            asp_weight = 1
375
 
376
        persPoints = deal['totalPoints'] * fav_weight * brand_weight * asp_weight
377
        deal['persPoints'] = persPoints
378
 
379
        if deal['category_id'] ==3:
380
            mobile_deals.append(deal)
381
        elif deal['category_id'] ==5:
382
            tablet_deals.append(deal)
383
        else:
384
            continue
385
        all_category_deals.append(deal)
386
 
14144 kshitij.so 387
    session.close()
14037 kshitij.so 388
    mem_cache_val = {3:mobile_deals, 5:tablet_deals, 0:all_deals}
389
    mc.set(str(userId), mem_cache_val)
390
 
391
 
14531 kshitij.so 392
def __populateFeaturedDeals():
393
    all_category_fd = []
394
    mobile_fd = []
395
    tablet_fd = []
14550 kshitij.so 396
    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})
14531 kshitij.so 397
    for activeFeaturedDeal in activeFeaturedDeals:
398
        for k,v in activeFeaturedDeal['rankDetails']:
399
            featuredDeal = FeaturedDeals(activeFeaturedDeal['sku'], int(k), activeFeaturedDeal['thresholdPrice'], int(v))
400
            if featuredDeal.category_id == 0:
401
                all_category_fd.append(featuredDeal)
402
            elif featuredDeal.category_id == 3:
403
                mobile_fd.append(featuredDeal)
404
            elif featuredDeal.category_id == 5:
405
                tablet_fd.append(featuredDeal)
406
            else:
407
                continue
14550 kshitij.so 408
    mc.set("featured_deals_category_"+str(0), all_category_fd, 3600)
409
    mc.set("featured_deals_category_"+str(3), mobile_fd, 3600)
410
    mc.set("featured_deals_category_"+str(5), tablet_fd, 3600)
14037 kshitij.so 411
 
412
def getNewDeals(userId, category_id, offset, limit, sort, direction):
13922 kshitij.so 413
    if not bool(cashBackMap):
13921 kshitij.so 414
        populateCashBack()
14037 kshitij.so 415
 
14550 kshitij.so 416
    try:
417
        if mc.get("featured_deals_category_"+str(category_id)) is None:
418
            __populateFeaturedDeals()
419
    except:
420
        pass 
14531 kshitij.so 421
 
13771 kshitij.so 422
    rank = 1
14037 kshitij.so 423
    dealsMap = {}
424
    user_specific_deals = mc.get(str(userId))
425
    if user_specific_deals is None:
426
        __populateCache(userId)
427
        user_specific_deals = mc.get(str(userId))
14038 kshitij.so 428
    else:
429
        print "Getting user deals from cache"
14037 kshitij.so 430
    category_specific_deals = user_specific_deals.get(category_id)
431
 
432
    if sort is None or direction is None:
433
        sorted_deals = sorted(category_specific_deals, key = lambda x: (x['persPoints'],x['totalPoints'],x['bestSellerPoints'], x['nlcPoints'], x['rank']),reverse=True)
434
    else:
435
        if sort == "bestSellerPoints":
436
            sorted_deals = sorted(category_specific_deals, key = lambda x: (x['bestSellerPoints'], x['rank'], x['nlcPoints']),reverse=True)
437
        else:
438
            if direction == -1:
439
                rev = True
440
            else:
441
                rev = False
442
            sorted_deals = sorted(category_specific_deals, key = lambda x: (x['available_price']),reverse=rev)
443
 
444
    for d in sorted_deals[offset:offset+limit]:
445
        item = list(get_mongo_connection().Catalog.MasterData.find({'_id':d['_id']}))
446
        if not dealsMap.has_key(item[0]['identifier']):
447
            item[0]['dealRank'] = rank
448
            item[0]['persPoints'] = d['persPoints']
14322 kshitij.so 449
            if d['dealType'] == 1 and d['source_id'] ==1:
450
                item[0]['marketPlaceUrl'] = "http://www.amazon.in/dp/%s"%(item[0]['identifier'].strip()) 
14037 kshitij.so 451
            try:
452
                cashBack = __getCashBack(item[0]['_id'], item[0]['source_id'], item[0]['category_id'])
453
                if not cashBack or cashBack.get('cash_back_status')!=1:
454
                    item[0]['cash_back_type'] = 0
455
                    item[0]['cash_back'] = 0
456
                else:
457
                    item[0]['cash_back_type'] = cashBack['cash_back_type']
458
                    item[0]['cash_back'] = cashBack['cash_back']
459
            except:
460
                print "Error in adding cashback to deals"
461
                item[0]['cash_back_type'] = 0
462
                item[0]['cash_back'] = 0
463
            dealsMap[item[0]['identifier']] = item[0]
464
 
465
            rank +=1
466
    return sorted(dealsMap.values(), key=itemgetter('dealRank'))
467
 
468
 
469
def getDeals(userId, category_id, offset, limit, sort, direction):
470
    if not bool(cashBackMap):
471
        populateCashBack()
472
    rank = 1
13771 kshitij.so 473
    deals = {}
13910 kshitij.so 474
    outer_query = []
475
    outer_query.append({"showDeal":1})
476
    query = {}
477
    query['$gt'] = 0
478
    outer_query.append({'totalPoints':query})
479
    if category_id in (3,5):
480
        outer_query.append({'category_id':category_id})
13803 kshitij.so 481
    if sort is None or direction is None:
482
        direct = -1
13910 kshitij.so 483
        print outer_query
484
        data = list(get_mongo_connection().Catalog.Deals.find({"$and":outer_query}).sort([('totalPoints',direct),('bestSellerPoints',direct),('nlcPoints',direct),('rank',direct)]).skip(offset).limit(limit))
13795 kshitij.so 485
    else:
13910 kshitij.so 486
        print outer_query
13803 kshitij.so 487
        direct = direction
13910 kshitij.so 488
        if sort == "bestSellerPoints":
489
            print "yes,sorting by bestSellerPoints"
490
            data = list(get_mongo_connection().Catalog.Deals.find({"$and":outer_query}).sort([('bestSellerPoints',direct),('rank',direct),('nlcPoints',direct)]).skip(offset).limit(limit))
491
        else:
492
            data = list(get_mongo_connection().Catalog.Deals.find({"$and":outer_query}).sort([(sort,direct)]).skip(offset).limit(limit))
13771 kshitij.so 493
    for d in data:
494
        item = list(get_mongo_connection().Catalog.MasterData.find({'_id':d['_id']}))
495
        if not deals.has_key(item[0]['identifier']):
13921 kshitij.so 496
            item[0]['dealRank'] = rank
497
            try:
498
                cashBack = __getCashBack(item[0]['_id'], item[0]['source_id'], item[0]['category_id'])
499
                if not cashBack or cashBack.get('cash_back_status')!=1:
13928 kshitij.so 500
                    item[0]['cash_back_type'] = 0
501
                    item[0]['cash_back'] = 0
13921 kshitij.so 502
                else:
13928 kshitij.so 503
                    item[0]['cash_back_type'] = cashBack['cash_back_type']
504
                    item[0]['cash_back'] = cashBack['cash_back']
13921 kshitij.so 505
            except:
506
                print "Error in adding cashback to deals"
13928 kshitij.so 507
                item[0]['cash_back_type'] = 0
508
                item[0]['cash_back'] = 0
13771 kshitij.so 509
            deals[item[0]['identifier']] = item[0]
13921 kshitij.so 510
 
13771 kshitij.so 511
            rank +=1
13785 kshitij.so 512
    return sorted(deals.values(), key=itemgetter('dealRank'))
513
 
514
def getItem(skuId):
14113 kshitij.so 515
    if not bool(cashBackMap):
516
        populateCashBack()
13795 kshitij.so 517
    try:
518
        skuData = list(get_mongo_connection().Catalog.MasterData.find({'_id':int(skuId)}))
14107 kshitij.so 519
        for sku in skuData:
520
            try:
521
                cashBack = __getCashBack(sku['_id'], sku['source_id'], sku['category_id'])
522
                if not cashBack or cashBack.get('cash_back_status')!=1:
523
                    sku['cash_back_type'] = 0
524
                    sku['cash_back'] = 0
525
                else:
526
                    sku['cash_back_type'] = cashBack['cash_back_type']
527
                    sku['cash_back'] = cashBack['cash_back']
528
            except:
529
                print "Error in adding cashback to deals"
530
                sku['cash_back_type'] = 0
531
                sku['cash_back'] = 0
14629 kshitij.so 532
            sku['in_stock'] = int(sku['in_stock'])
533
            sku['is_shortage'] = int(sku['is_shortage'])
534
            sku['category_id'] = int(sku['category_id'])
535
            sku['status'] = int(sku['status'])
13785 kshitij.so 536
        return skuData
13795 kshitij.so 537
    except:
538
        return [{}]
13836 kshitij.so 539
 
13921 kshitij.so 540
def __getCashBack(skuId, source_id, category_id):
541
    itemCashBack = itemCashBackMap.get(skuId)
542
    if itemCashBack is not None:
543
        return itemCashBack
544
 
545
    sourceCashBack = cashBackMap.get(source_id)
546
    if sourceCashBack is not None and len(sourceCashBack) > 0:
547
        for cashBack in sourceCashBack:
548
            if cashBack.get(category_id) is None:
549
                continue
550
            else:
551
                return cashBack.get(category_id)
552
    else:
553
        return {}
554
 
13836 kshitij.so 555
def getCashBackDetails(identifier, source_id):
13922 kshitij.so 556
    if not bool(cashBackMap):
13921 kshitij.so 557
        populateCashBack()
558
 
13836 kshitij.so 559
    """Need to add item level cashback, no data available right now."""
13771 kshitij.so 560
 
13921 kshitij.so 561
    if source_id in (1,2,4,5):
13839 kshitij.so 562
        skuData = list(get_mongo_connection().Catalog.MasterData.find({'identifier':identifier.strip(), 'source_id':source_id}))
13840 kshitij.so 563
    elif source_id == 3:
13839 kshitij.so 564
        skuData = list(get_mongo_connection().Catalog.MasterData.find({'secondaryIdentifier':identifier.strip(), 'source_id':source_id}))
13840 kshitij.so 565
    else:
566
        return {}
13836 kshitij.so 567
    if len(skuData) > 0:
13921 kshitij.so 568
 
569
        itemCashBack = itemCashBackMap.get(skuData[0]['_id'])
570
        if itemCashBack is not None:
571
            return itemCashBack
572
 
573
        sourceCashBack = cashBackMap.get(source_id)
574
        if sourceCashBack is not None and len(sourceCashBack) > 0:
575
            for cashBack in sourceCashBack:
576
                if cashBack.get(skuData[0]['category_id']) is None:
577
                    continue
578
                else:
579
                    return cashBack.get(skuData[0]['category_id'])
13836 kshitij.so 580
        else:
581
            return {} 
582
    else:
583
        return {}
13986 amit.gupta 584
 
14398 amit.gupta 585
def getImgSrc(identifier, source_id):
586
    skuData = None
587
    if source_id in (1,2,4,5):
14414 amit.gupta 588
        skuData = get_mongo_connection().Catalog.MasterData.find_one({'identifier':identifier.strip(), 'source_id':source_id})
14398 amit.gupta 589
    elif source_id == 3:
14414 amit.gupta 590
        skuData = get_mongo_connection().Catalog.MasterData.find_one({'secondaryIdentifier':identifier.strip(), 'source_id':source_id})
14398 amit.gupta 591
    if skuData is None:
592
        return {}
593
    else:
594
        return {'thumbnail':skuData.get('thumbnail')}
13986 amit.gupta 595
 
596
def next_weekday(d, weekday):
597
    days_ahead = weekday - d.weekday()
598
    if days_ahead <= 0: # Target day already happened this week
599
        days_ahead += 7
600
    return d + timedelta(days_ahead)
601
 
13771 kshitij.so 602
 
13970 kshitij.so 603
def getAllDealerPrices(offset, limit):
604
    data = []
605
    collection = get_mongo_connection().Catalog.SkuDealerPrices
606
    cursor = collection.find().skip(offset).limit(limit)
607
    for val in cursor:
608
        master = list(get_mongo_connection().Catalog.MasterData.find({'_id':val['sku']}))
609
        if len(master) > 0:
14069 kshitij.so 610
            val['brand'] = master[0]['brand']
611
            val['source_product_name'] = master[0]['source_product_name']
612
            val['skuBundleId'] = master[0]['skuBundleId']
13970 kshitij.so 613
        else:
614
            val['brand'] = ""
615
            val['source_product_name'] = ""
616
            val['skuBundleId'] = ""
617
        data.append(val)
618
    return data
619
 
14553 kshitij.so 620
def addSkuDealerPrice(data, multi):
621
    if multi != 1:
622
        collection = get_mongo_connection().Catalog.SkuDealerPrices
623
        cursor = collection.find({"sku":data['sku']})
624
        if cursor.count() > 0:
625
            return {0:"Sku information already present."}
626
        else:
627
            collection.insert(data)
628
            get_mongo_connection().Catalog.MasterData.update({'_id':data['sku']},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=False)
629
            return {1:"Data added successfully"}
13970 kshitij.so 630
    else:
14553 kshitij.so 631
        skuIds = __getBundledSkusfromSku(data['sku'])
632
        for sku in skuIds:
633
            data['sku'] = sku.get('_id')
634
            collection = get_mongo_connection().Catalog.SkuDealerPrices
635
            cursor = collection.find({"sku":data['sku']})
636
            if cursor.count() > 0:
637
                continue
638
            else:   
14558 kshitij.so 639
                data.pop('_id',None)
14553 kshitij.so 640
                collection.insert(data)
641
        get_mongo_connection().Catalog.MasterData.update({'skuBundleId':sku.get('skuBundleId')},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=True)
13970 kshitij.so 642
        return {1:"Data added successfully"}
14553 kshitij.so 643
 
644
 
13970 kshitij.so 645
 
646
def updateSkuDealerPrice(data, _id):
647
    try:
648
        collection = get_mongo_connection().Catalog.SkuDealerPrices
649
        collection.update({'_id':ObjectId(_id)},{"$set":{'dp':data['dp']}},upsert=False, multi = False)
650
        get_mongo_connection().Catalog.MasterData.update({'_id':data['sku']},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=False)
651
        return {1:"Data updated successfully"}
652
    except:
653
        return {0:"Data not updated."}
654
 
655
def updateExceptionalNlc(data, _id):
656
    try:
657
        collection = get_mongo_connection().Catalog.ExceptionalNlc
658
        collection.update({'_id':ObjectId(_id)},{"$set":{'maxNlc':data['maxNlc'], 'minNlc':data['minNlc'], 'overrideNlc':data['overrideNlc']}},upsert=False, multi = False)
659
        get_mongo_connection().Catalog.MasterData.update({'_id':data['sku']},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=False)
660
        return {1:"Data updated successfully"}
661
    except:
662
        return {0:"Data not updated."}
663
 
14041 kshitij.so 664
def resetCache(userId):
14043 kshitij.so 665
    try:
666
        mc.delete(userId)
667
        return {1:'Cache cleared.'}
668
    except:
669
        return {0:'Unable to clear cache.'}
670
 
14575 kshitij.so 671
def updateCollection(data, multi):
14083 kshitij.so 672
    print data
14575 kshitij.so 673
    if multi!=1:
674
        try:
675
            collection = get_mongo_connection().Catalog[data['class']]
676
            class_name = data.pop('class')
677
            if class_name == "SkuSchemeDetails":
678
                data['addedOn'] = to_java_date(datetime.now())
679
            _id = data.pop('oid')
680
            result = collection.update({'_id':ObjectId(_id)},{"$set":data},upsert=False, multi = False)
681
            record = list(collection.find({'_id':ObjectId(_id)}))
682
            if class_name !="CategoryDiscount":
683
                get_mongo_connection().Catalog.MasterData.update({'_id':record[0]['sku']},{"$set":{'updatedOn':to_java_date(datetime.now())}})
684
            else:
685
                get_mongo_connection().Catalog.MasterData.update({'brand':re.compile(record[0]['brand'], re.IGNORECASE),'category_id':record[0]['category_id']}, \
686
                                                                 {"$set":{'updatedOn':to_java_date(datetime.now())}},upsert=False,multi=True)
687
            return {1:"Data updated successfully"}
688
        except Exception as e:
689
            print e
690
            return {0:"Data not updated."}
691
    else:
692
        try:
693
            collection = get_mongo_connection().Catalog[data['class']]
694
            class_name = data.pop('class')
695
            _id = data.pop('oid')
696
            record = list(collection.find({'_id':ObjectId(_id)}))
697
            skuIds = __getBundledSkusfromSku(record[0]['sku'])
698
            for sku in skuIds:
699
                if class_name == "SkuSchemeDetails":
700
                    data['addedOn'] = to_java_date(datetime.now())
14582 kshitij.so 701
                data['sku'] = sku.get('_id')
14575 kshitij.so 702
                data.pop('_id',None)
14583 kshitij.so 703
                collection.update({'sku':sku.get('_id')},{"$set":data},upsert=False,multi=False)
14575 kshitij.so 704
            get_mongo_connection().Catalog.MasterData.update({'skuBundleId':sku.get('skuBundleId')},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=True)
14580 kshitij.so 705
            return {1:"Data updatedsuccessfully"}
14575 kshitij.so 706
        except Exception as e:
707
            print e
708
            return {0:"Data not updated."}
709
 
14076 kshitij.so 710
 
14553 kshitij.so 711
def addNegativeDeals(data, multi):
712
    if multi !=1: 
713
        collection = get_mongo_connection().Catalog.NegativeDeals
714
        cursor = collection.find({"sku":data['sku']})
715
        if cursor.count() > 0:
716
            return {0:"Sku information already present."}
717
        else:
718
            collection.insert(data)
719
            return {1:"Data added successfully"}
14481 kshitij.so 720
    else:
14553 kshitij.so 721
        skuIds = __getBundledSkusfromSku(data['sku'])
722
        for sku in skuIds:
723
            data['sku'] = sku.get('_id')
724
            collection = get_mongo_connection().Catalog.NegativeDeals
725
            cursor = collection.find({"sku":data['sku']})
726
            if cursor.count() > 0:
727
                continue
728
            else:
14558 kshitij.so 729
                data.pop('_id',None)
14553 kshitij.so 730
                collection.insert(data)
14481 kshitij.so 731
        return {1:"Data added successfully"}
732
 
733
def getAllNegativeDeals(offset, limit):
734
    data = []
735
    collection = get_mongo_connection().Catalog.NegativeDeals
736
    cursor = collection.find().skip(offset).limit(limit)
737
    for val in cursor:
738
        master = list(get_mongo_connection().Catalog.MasterData.find({'_id':val['sku']}))
739
        if len(master) > 0:
740
            val['brand'] = master[0]['brand']
741
            val['source_product_name'] = master[0]['source_product_name']
742
            val['skuBundleId'] = master[0]['skuBundleId']
743
        else:
744
            val['brand'] = ""
745
            val['source_product_name'] = ""
746
            val['skuBundleId'] = ""
747
        data.append(val)
748
    return data
749
 
750
def getAllManualDeals(offset, limit):
751
    data = []
752
    collection = get_mongo_connection().Catalog.ManualDeals
14495 kshitij.so 753
    cursor = collection.find({'endDate':{'$gte':to_java_date(datetime.now())}}).skip(offset).limit(limit)
14481 kshitij.so 754
    for val in cursor:
755
        master = list(get_mongo_connection().Catalog.MasterData.find({'_id':val['sku']}))
756
        if len(master) > 0:
757
            val['brand'] = master[0]['brand']
758
            val['source_product_name'] = master[0]['source_product_name']
759
            val['skuBundleId'] = master[0]['skuBundleId']
760
        else:
761
            val['brand'] = ""
762
            val['source_product_name'] = ""
763
            val['skuBundleId'] = ""
764
        data.append(val)
765
    return data
14076 kshitij.so 766
 
14553 kshitij.so 767
def addManualDeal(data, multi):
768
    if multi !=1:
769
        collection = get_mongo_connection().Catalog.ManualDeals
770
        cursor = collection.find({'sku':data['sku'],'startDate':{'$lte':data['startDate']},'endDate':{'$gte':data['endDate']}})
771
        if cursor.count() > 0:
772
            return {0:"Sku information already present."}
773
        else:
774
            collection.insert(data)
775
            get_mongo_connection().Catalog.MasterData.update({'_id':data['sku']},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=False)
776
            return {1:"Data added successfully"}
14481 kshitij.so 777
    else:
14553 kshitij.so 778
        skuIds = __getBundledSkusfromSku(data['sku'])
779
        for sku in skuIds:
780
            data['sku'] = sku.get('_id')
781
            collection = get_mongo_connection().Catalog.ManualDeals
782
            cursor = collection.find({'sku':data['sku'],'startDate':{'$lte':data['startDate']},'endDate':{'$gte':data['endDate']}})
783
            if cursor.count() > 0:
784
                continue
785
            else:
14558 kshitij.so 786
                data.pop('_id',None)
14553 kshitij.so 787
                collection.insert(data)
788
        get_mongo_connection().Catalog.MasterData.update({'skuBundleId':sku.get('skuBundleId')},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=True)
14481 kshitij.so 789
        return {1:"Data added successfully"}
14553 kshitij.so 790
 
14481 kshitij.so 791
def deleteDocument(data):
792
    print data
793
    try:
794
        collection = get_mongo_connection().Catalog[data['class']]
795
        class_name = data.pop('class')
796
        _id = data.pop('oid')
797
        record = list(collection.find({'_id':ObjectId(_id)}))
798
        collection.remove({'_id':ObjectId(_id)})
799
        if class_name !="CategoryDiscount":
800
            get_mongo_connection().Catalog.MasterData.update({'_id':record[0]['sku']},{"$set":{'updatedOn':to_java_date(datetime.now())}})
801
        else:
802
            get_mongo_connection().Catalog.MasterData.update({'brand':re.compile(record[0]['brand'], re.IGNORECASE),'category_id':record[0]['category_id']}, \
803
                                                             {"$set":{'updatedOn':to_java_date(datetime.now())}},upsert=False,multi=True)
804
        return {1:"Document deleted successfully"}
805
    except Exception as e:
806
        print e
807
        return {0:"Document not deleted."}
13970 kshitij.so 808
 
14482 kshitij.so 809
def searchMaster(offset, limit, search_term):
810
    data = []
14531 kshitij.so 811
    if search_term is not None:
14551 kshitij.so 812
        terms = search_term.split(' ')
813
        outer_query = []
814
        for term in terms:
815
            outer_query.append({"source_product_name":re.compile(term, re.IGNORECASE)})
14531 kshitij.so 816
        try:
14551 kshitij.so 817
            collection = get_mongo_connection().Catalog.MasterData.find({"$and":outer_query,'source_id':{'$in':SOURCE_MAP.keys()}}).skip(offset).limit(limit)
14531 kshitij.so 818
            for record in collection:
819
                data.append(record)
820
        except:
821
            pass
822
    else:
823
        collection = get_mongo_connection().Catalog.MasterData.find({'source_id':{'$in':SOURCE_MAP.keys()}}).skip(offset).limit(limit)
14482 kshitij.so 824
        for record in collection:
825
            data.append(record)
826
    return data
14481 kshitij.so 827
 
14495 kshitij.so 828
def getAllFeaturedDeals(offset, limit):
829
    data = []
830
    collection = get_mongo_connection().Catalog.FeaturedDeals
831
    cursor = collection.find({'endDate':{'$gte':to_java_date(datetime.now())}}).skip(offset).limit(limit)
832
    for val in cursor:
833
        master = list(get_mongo_connection().Catalog.MasterData.find({'_id':val['sku']}))
834
        if len(master) > 0:
835
            val['brand'] = master[0]['brand']
836
            val['source_product_name'] = master[0]['source_product_name']
837
            val['skuBundleId'] = master[0]['skuBundleId']
838
        else:
839
            val['brand'] = ""
840
            val['source_product_name'] = ""
841
            val['skuBundleId'] = ""
842
        data.append(val)
843
    return data
844
 
14553 kshitij.so 845
def addFeaturedDeal(data, multi):
846
    if multi !=1:
847
        collection = get_mongo_connection().Catalog.FeaturedDeals
848
        cursor = collection.find({'sku':data['sku'],'startDate':{'$lte':data['startDate']},'endDate':{'$gte':data['endDate']}})
849
        if cursor.count() > 0:
850
            return {0:"Sku information already present."}
851
        else:
852
            collection.insert(data)
853
            get_mongo_connection().Catalog.MasterData.update({'_id':data['sku']},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=False)
854
            return {1:"Data added successfully"}
14495 kshitij.so 855
    else:
14553 kshitij.so 856
        skuIds = __getBundledSkusfromSku(data['sku'])
857
        for sku in skuIds:
858
            data['sku'] = sku.get('_id')
859
            collection = get_mongo_connection().Catalog.FeaturedDeals
860
            cursor = collection.find({'sku':data['sku'],'startDate':{'$lte':data['startDate']},'endDate':{'$gte':data['endDate']}})
861
            if cursor.count() > 0:
862
                continue
863
            else:
14558 kshitij.so 864
                data.pop('_id',None)
14553 kshitij.so 865
                collection.insert(data)
866
        get_mongo_connection().Catalog.MasterData.update({'skuBundleId':sku.get('skuBundleId')},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=True)
14495 kshitij.so 867
        return {1:"Data added successfully"}
868
 
14499 kshitij.so 869
def searchCollection(class_name, sku, skuBundleId):
14497 kshitij.so 870
    data = []
871
    collection = get_mongo_connection().Catalog[class_name]
14499 kshitij.so 872
    if sku is not None:
873
        cursor = collection.find({'sku':sku})
874
        for val in cursor:
875
            master = list(get_mongo_connection().Catalog.MasterData.find({'_id':val['sku']}))
876
            if len(master) > 0:
877
                val['brand'] = master[0]['brand']
878
                val['source_product_name'] = master[0]['source_product_name']
879
                val['skuBundleId'] = master[0]['skuBundleId']
880
            else:
881
                val['brand'] = ""
882
                val['source_product_name'] = ""
883
                val['skuBundleId'] = ""
884
            data.append(val)
885
        return data
886
    else:
14562 kshitij.so 887
        skuIds = get_mongo_connection().Catalog.MasterData.find({'skuBundleId':skuBundleId}).distinct('_id')
14499 kshitij.so 888
        for sku in skuIds:
889
            cursor = collection.find({'sku':sku})
890
            for val in cursor:
891
                master = list(get_mongo_connection().Catalog.MasterData.find({'_id':val['sku']}))
892
                if len(master) > 0:
893
                    val['brand'] = master[0]['brand']
894
                    val['source_product_name'] = master[0]['source_product_name']
895
                    val['skuBundleId'] = master[0]['skuBundleId']
896
                else:
897
                    val['brand'] = ""
898
                    val['source_product_name'] = ""
899
                    val['skuBundleId'] = ""
900
                data.append(val)
901
        return data
14495 kshitij.so 902
 
14588 kshitij.so 903
def addNewItem(data):
14594 kshitij.so 904
    try:
905
        data['updatedOn'] = to_java_date(datetime.now())
906
        data['addedOn'] = to_java_date(datetime.now())
907
        data['priceUpdatedOn'] = to_java_date(datetime.now())
908
        max_id = list(get_mongo_connection().Catalog.MasterData.find().sort([('_id',pymongo.DESCENDING)]).limit(1))
909
        max_bundle = list(get_mongo_connection().Catalog.MasterData.find().sort([('skuBundleId',pymongo.DESCENDING)]).limit(1))
910
        data['_id'] = max_id[0]['_id'] + 1
911
        data['skuBundleId'] = max_bundle[0]['skuBundleId'] + 1
912
        data['identifier'] = str(data['identifier'])
913
        data['secondaryIdentifier'] = str(data['secondaryIdentifier'])
914
        get_mongo_connection().Catalog.MasterData.insert(data)
915
        return {1:'Data added successfully'}
916
    except Exception as e:
917
        print e
918
        return {0:'Unable to add data.'}
14588 kshitij.so 919
 
920
def addItemToExistingBundle(data):
921
    try:
922
        data['updatedOn'] = to_java_date(datetime.now())
923
        data['addedOn'] = to_java_date(datetime.now())
924
        data['priceUpdatedOn'] = to_java_date(datetime.now())
14593 kshitij.so 925
        max_id = list(get_mongo_connection().Catalog.MasterData.find().sort([('_id',pymongo.DESCENDING)]).limit(1))
14590 kshitij.so 926
        data['_id'] = max_id[0]['_id'] + 1
14594 kshitij.so 927
        data['identifier'] = str(data['identifier'])
928
        data['secondaryIdentifier'] = str(data['secondaryIdentifier'])
14588 kshitij.so 929
        get_mongo_connection().Catalog.MasterData.insert(data)
930
        return {1:'Data added successfully.'}
14594 kshitij.so 931
    except Exception as e:
932
        print e
14588 kshitij.so 933
        return {0:'Unable to add data.'}
934
 
935
def updateMaster(data, multi):
14597 kshitij.so 936
    if multi != 1:
937
        _id = data.pop('_id')
938
        skuBundleId = data.pop('skuBundleId')
939
        data['updatedOn'] = to_java_date(datetime.now())
940
        get_mongo_connection().Catalog.MasterData.update({'_id':_id},{"$set":data},upsert=False)
941
        return {1:'Data updated successfully.'}
942
    else:
943
        _id = data.pop('_id')
944
        skuBundleId = data.pop('skuBundleId')
14612 kshitij.so 945
        data['updatedOn'] = to_java_date(datetime.now())
14597 kshitij.so 946
        get_mongo_connection().Catalog.MasterData.update({'_id':_id},{"$set":data},upsert=False)
947
        similarItems = get_mongo_connection().Catalog.MasterData.find({'skuBundleId':skuBundleId})
948
        for item in similarItems:
14598 kshitij.so 949
            if item['_id'] == _id:
14597 kshitij.so 950
                continue
951
            item['updatedOn'] = to_java_date(datetime.now())
952
            item['thumbnail'] = data['thumbnail']
953
            item['category'] = data['category']
954
            item['category_id'] = data['category_id']
955
            item['tagline'] = data['tagline']
956
            item['is_shortage'] = data['is_shortage']
957
            item['mrp'] = data['mrp']
14611 kshitij.so 958
            item['status'] = data['status']
14599 kshitij.so 959
            similar_item_id = item.pop('_id')
960
            get_mongo_connection().Catalog.MasterData.update({'_id':similar_item_id},{"$set":item},upsert=False)
14597 kshitij.so 961
        return {1:'Data updated successfully.'}
14619 kshitij.so 962
 
963
def getLiveCricScore():
964
    return mc.get('liveScore')
14588 kshitij.so 965
 
13572 kshitij.so 966
def main():
14553 kshitij.so 967
    print __getBundledSkusfromSku(1)
13811 kshitij.so 968
 
13921 kshitij.so 969
 
13572 kshitij.so 970
if __name__=='__main__':
13932 amit.gupta 971
    main()