Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
13928 kshitij.so 1
import pymongo
14037 kshitij.so 2
from elixir import *
13572 kshitij.so 3
from datetime import datetime
13986 amit.gupta 4
from datetime import timedelta
13927 amit.gupta 5
from dtr.main import Store
13785 kshitij.so 6
from dtr.utils.utils import to_java_date
13970 kshitij.so 7
from operator import itemgetter
8
from bson.objectid import ObjectId
14037 kshitij.so 9
from dtr.storage import DataService
10
from dtr.storage.DataService import price_preferences, brand_preferences, \
11
user_actions
12
from dtr.storage.MemCache import MemCache
13572 kshitij.so 13
 
14
con = None
13907 kshitij.so 15
cashBackMap = {}
13921 kshitij.so 16
itemCashBackMap = {}
13572 kshitij.so 17
 
14037 kshitij.so 18
DataService.initialize(db_hostname="localhost")
19
mc = MemCache("127.0.0.1")
20
 
13572 kshitij.so 21
def get_mongo_connection(host='localhost', port=27017):
22
    global con
23
    if con is None:
24
        print "Establishing connection %s host and port %d" %(host,port)
25
        try:
26
            con = pymongo.MongoClient(host, port)
27
        except Exception, e:
28
            print e
29
            return None
30
    return con
31
 
13907 kshitij.so 32
def populateCashBack():
13921 kshitij.so 33
    print "Populating cashback"
13907 kshitij.so 34
    global cashBackMap
13921 kshitij.so 35
    global itemCashBackMap
36
    cashBackMap = {}
37
    itemCashBackMap = {}
13907 kshitij.so 38
    cashBack = list(get_mongo_connection().Catalog.CategoryCashBack.find())
39
    for row in cashBack:
13970 kshitij.so 40
        temp_map = {}
41
        temp_list = []
13907 kshitij.so 42
        if cashBackMap.has_key(row['source_id']):
43
            arr = cashBackMap.get(row['source_id'])
44
            for val in arr:
45
                temp_list.append(val)
46
            temp_map[row['category_id']] = row
47
            temp_list.append(temp_map)
48
            cashBackMap[row['source_id']] = temp_list 
49
        else:
50
            temp_map[row['category_id']] = row
51
            temp_list.append(temp_map)
52
            cashBackMap[row['source_id']] = temp_list
13921 kshitij.so 53
    itemCashBack = list(get_mongo_connection().Catalog.ItemCashBack.find())
54
    for row in itemCashBack:
55
        if not itemCashBackMap.has_key(row['skuId']):
56
            itemCashBackMap[row['skuId']] = row
13907 kshitij.so 57
 
13572 kshitij.so 58
def addCategoryDiscount(data):
13970 kshitij.so 59
    collection = get_mongo_connection().Catalog.CategoryDiscount
13572 kshitij.so 60
    query = []
61
    data['brand'] = data['brand'].strip().upper()
13970 kshitij.so 62
    data['discountType'] = data['discountType'].upper().strip()
13572 kshitij.so 63
    query.append({"brand":data['brand']})
64
    query.append({"category_id":data['category_id']})
65
    r = collection.find({"$and":query})
66
    if r.count() > 0:
13639 kshitij.so 67
        return {0:"Brand & Category info already present."}
13572 kshitij.so 68
    else:
69
        collection.insert(data)
13970 kshitij.so 70
        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 71
        return {1:"Data added successfully"}
13572 kshitij.so 72
 
13970 kshitij.so 73
def updateCategoryDiscount(data,_id):
74
    try:
75
        collection = get_mongo_connection().Catalog.CategoryDiscount
76
        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)
77
        get_mongo_connection().Catalog.MasterData.update({'brand':data['brand'],'category_id':data['category_id']},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=True)
78
        return {1:"Data updated successfully"}
79
    except:
80
        return {0:"Data not updated."}
81
 
82
 
13572 kshitij.so 83
def getAllCategoryDiscount():
84
    data = []
13970 kshitij.so 85
    collection = get_mongo_connection().Catalog.CategoryDiscount
13572 kshitij.so 86
    cursor = collection.find()
87
    for val in cursor:
88
        data.append(val)
89
    return data
90
 
91
def addSchemeDetailsForSku(data):
13970 kshitij.so 92
    collection = get_mongo_connection().Catalog.SkuSchemeDetails
13572 kshitij.so 93
    data['addedOn'] = to_java_date(datetime.now())
94
    collection.insert(data)
13639 kshitij.so 95
    return {1:"Data added successfully"}
13572 kshitij.so 96
 
97
def getAllSkuWiseSchemeDetails():
98
    data = []
13970 kshitij.so 99
    collection = get_mongo_connection().Catalog.SkuSchemeDetails
13572 kshitij.so 100
    cursor = collection.find()
101
    for val in cursor:
102
        data.append(val)
103
    return data
104
 
105
def addSkuDiscountInfo(data):
13970 kshitij.so 106
    collection = get_mongo_connection().Catalog.SkuDiscountInfo
13572 kshitij.so 107
    cursor = collection.find({"sku":data['sku']})
13642 kshitij.so 108
    if cursor.count() > 0:
13639 kshitij.so 109
        return {0:"Sku information already present."}
13572 kshitij.so 110
    else:
111
        collection.insert(data)
13970 kshitij.so 112
        get_mongo_connection().Catalog.MasterData.update({'_id':data['sku']},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=False)
13639 kshitij.so 113
        return {1:"Data added successfully"}
13572 kshitij.so 114
 
13970 kshitij.so 115
def getallSkuDiscountInfo(offset, limit):
13572 kshitij.so 116
    data = []
13970 kshitij.so 117
    collection = get_mongo_connection().Catalog.SkuDiscountInfo
118
    cursor = collection.find().skip(offset).limit(limit)
13572 kshitij.so 119
    for val in cursor:
13970 kshitij.so 120
        master = list(get_mongo_connection().Catalog.MasterData.find({'_id':val['sku']}))
121
        if len(master) > 0:
122
            val['brand'] = master['brand']
123
            val['source_product_name'] = master['source_product_name']
124
            val['skuBundleId'] = master['skuBundleId']
125
        else:
126
            val['brand'] = ""
127
            val['source_product_name'] = ""
128
            val['skuBundleId'] = ""
13572 kshitij.so 129
        data.append(val)
130
    return data
131
 
13970 kshitij.so 132
def updateSkuDiscount(data,_id):
133
    try:
134
        collection = get_mongo_connection().Catalog.SkuDiscountInfo
135
        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)
136
        get_mongo_connection().Catalog.MasterData.update({'_id':data['sku']},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=False)
137
        return {1:"Data updated successfully"}
138
    except:
139
        return {0:"Data not updated."}
140
 
141
 
13572 kshitij.so 142
def addExceptionalNlc(data):
13970 kshitij.so 143
    collection = get_mongo_connection().Catalog.ExceptionalNlc
13572 kshitij.so 144
    cursor = collection.find({"sku":data['sku']})
13642 kshitij.so 145
    if cursor.count() > 0:
13639 kshitij.so 146
        return {0:"Sku information already present."}
13572 kshitij.so 147
    else:
148
        collection.insert(data)
13970 kshitij.so 149
        get_mongo_connection().Catalog.MasterData.update({'_id':data['sku']},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=False)
13639 kshitij.so 150
        return {1:"Data added successfully"}
13572 kshitij.so 151
 
13970 kshitij.so 152
def getAllExceptionlNlcItems(offset, limit):
13572 kshitij.so 153
    data = []
13970 kshitij.so 154
    collection = get_mongo_connection().Catalog.ExceptionalNlc
13572 kshitij.so 155
    cursor = collection.find()
156
    for val in cursor:
13970 kshitij.so 157
        master = list(get_mongo_connection().Catalog.MasterData.find({'_id':val['sku']}))
158
        if len(master) > 0:
159
            val['brand'] = master['brand']
160
            val['source_product_name'] = master['source_product_name']
161
            val['skuBundleId'] = master['skuBundleId']
162
        else:
163
            val['brand'] = ""
164
            val['source_product_name'] = ""
165
            val['skuBundleId'] = ""
13572 kshitij.so 166
        data.append(val)
167
    return data
168
 
14005 amit.gupta 169
def getMerchantOrdersByUser(userId, page=1, window=50, searchMap={}):
170
    if searchMap is None:
171
        searchMap = {}
13603 amit.gupta 172
    if page==None:
173
        page = 1
174
 
175
    if window==None:
176
        window = 50
177
    result = {}
13582 amit.gupta 178
    skip = (page-1)*window
14005 amit.gupta 179
 
180
    searchMap['userId'] = userId
13603 amit.gupta 181
    collection = get_mongo_connection().Dtr.merchantOrder
14005 amit.gupta 182
    cursor = collection.find(searchMap).sort("_id",-1)
13603 amit.gupta 183
    total_count = cursor.count()
184
    pages = total_count/window + (0 if total_count%window==0 else 1)  
185
    print "total_count", total_count
186
    if total_count > skip:
13999 amit.gupta 187
        cursor = cursor.skip(skip).limit(window)
13603 amit.gupta 188
        orders = []
189
        for order in cursor:
14002 amit.gupta 190
            del(order["_id"])
191
            orders.append(order)
13603 amit.gupta 192
        result['data'] = orders
193
        result['window'] = window
194
        result['totalCount'] = total_count 
195
        result['currCount'] = cursor.count()
196
        result['totalPages'] = pages
197
        result['currPage'] = page    
198
        return result
199
    else:
200
        return result
13630 kshitij.so 201
 
13927 amit.gupta 202
def getRefunds(userId, page=1, window=10):
203
    if page==None:
204
        page = 1
205
 
206
    if window==None:
13995 amit.gupta 207
        window = 10
13927 amit.gupta 208
    result = {}
209
    skip = (page-1)*window
210
    collection = get_mongo_connection().Dtr.refund
211
    cursor = collection.find({"userId":userId})
212
    total_count = cursor.count()
213
    pages = total_count/window + (0 if total_count%window==0 else 1)  
214
    print "total_count", total_count
215
    if total_count > skip:
13991 amit.gupta 216
        cursor = cursor.skip(skip).limit(window).sort([('batchId',-1)])
13927 amit.gupta 217
        refunds = []
218
        for refund in cursor:
219
            del(refund["_id"])
220
            refunds.append(refund)
221
        result['data'] = refunds
222
        result['window'] = window
223
        result['totalCount'] = total_count 
224
        result['currCount'] = cursor.count()
225
        result['totalPages'] = pages
226
        result['currPage'] = page    
227
        return result
228
    else:
229
        return result
230
 
231
def getPendingRefunds(userId):
13991 amit.gupta 232
    print type(userId)
13927 amit.gupta 233
    result = get_mongo_connection().Dtr.merchantOrder\
234
        .aggregate([
235
                    {'$match':{'subOrders.cashBackStatus':Store.CB_APPROVED, 'userId':userId}},
236
                    {'$unwind':"$subOrders"},
237
                    { 
238
                     '$group':{
239
                               '_id':None,
240
                               'amount': { '$sum':'$subOrders.cashBackAmount'},
241
                               }
242
                     }
13987 amit.gupta 243
                ])['result']
244
 
245
    if len(result)>0:
246
        result = result[0]        
247
        result.pop("_id")
248
    else:
249
        result={}
250
        result['amount'] = 0.0
13988 amit.gupta 251
    result['nextCredit'] = datetime.strftime(next_weekday(datetime.now(), 0),"%Y-%m-%d %H:%M:%S")
13927 amit.gupta 252
    return result
14037 kshitij.so 253
 
254
def __populateCache(userId):
255
    print "Populating memcache for userId",userId
256
    outer_query = []
257
    outer_query.append({"showDeal":1})
258
    query = {}
259
    query['$gt'] = 0
260
    outer_query.append({'totalPoints':query})
261
    brandPrefMap = {}
262
    pricePrefMap = {}
263
    actionsMap = {}
264
    brand_p = session.query(price_preferences).filter_by(user_id=userId).all()
265
    for x in brand_p:
266
        pricePrefMap[x.category_id] = [x.min_price,x.max_price]
267
    for x in session.query(brand_preferences).filter_by(user_id=userId).all():
268
        temp_map = {}
269
        if brandPrefMap.has_key((x.brand).strip().upper()):
270
            val = brandPrefMap.get((x.brand).strip().upper())
271
            temp_map[x.category_id] = 1 if x.status == 'show' else 0
272
            val.append(temp_map)
273
        else:
274
            temp = []
275
            temp_map[x.category_id] = 1 if x.status == 'show' else 0
276
            temp.append(temp_map)
277
            brandPrefMap[(x.brand).strip().upper()] = temp
278
 
279
    for x in session.query(user_actions).filter_by(user_id=userId).all():
280
        actionsMap[x.store_product_id] = 1 if x.action == 'like' else 0
281
    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}).sort([('totalPoints',pymongo.DESCENDING),('bestSellerPoints',pymongo.DESCENDING),('nlcPoints',pymongo.DESCENDING),('rank',pymongo.DESCENDING)]))
282
    all_category_deals = []
283
    mobile_deals = []
284
    tablet_deals = []
285
    for deal in all_deals:
286
        if actionsMap.get(deal['_id']) == 0:
287
            fav_weight =.25
288
        elif actionsMap.get(deal['_id']) == 1:
289
            fav_weight = 1.5
290
        else:
291
            fav_weight = 1
292
 
293
        if brandPrefMap.get(deal['brand'].strip().upper()) is not None:
294
            brand_weight = 1
295
            for brandInfo in brandPrefMap.get(deal['brand'].strip().upper()):
296
                if brandInfo.get(deal['category_id']) is not None:
297
                    if brandInfo.get(deal['category_id']) == 1:
298
                        brand_weight = 1.5
299
        else:
300
            brand_weight = 1
301
 
302
        if pricePrefMap.get(deal['category_id']) is not None:
303
 
304
            if deal['available_price'] >= pricePrefMap.get(deal['category_id'])[0] and deal['available_price'] <= pricePrefMap.get(deal['category_id'])[1]:
305
                asp_weight = 1.5
306
            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]:
307
                asp_weight = 1.2
308
            else:
309
                asp_weight = 1
310
        else:
311
            asp_weight = 1
312
 
313
        persPoints = deal['totalPoints'] * fav_weight * brand_weight * asp_weight
314
        deal['persPoints'] = persPoints
315
 
316
        if deal['category_id'] ==3:
317
            mobile_deals.append(deal)
318
        elif deal['category_id'] ==5:
319
            tablet_deals.append(deal)
320
        else:
321
            continue
322
        all_category_deals.append(deal)
323
 
324
 
325
    mem_cache_val = {3:mobile_deals, 5:tablet_deals, 0:all_deals}
326
    mc.set(str(userId), mem_cache_val)
327
 
328
 
329
 
330
def getNewDeals(userId, category_id, offset, limit, sort, direction):
13922 kshitij.so 331
    if not bool(cashBackMap):
13921 kshitij.so 332
        populateCashBack()
14037 kshitij.so 333
 
13771 kshitij.so 334
    rank = 1
14037 kshitij.so 335
    dealsMap = {}
336
    user_specific_deals = mc.get(str(userId))
337
    if user_specific_deals is None:
338
        __populateCache(userId)
339
        user_specific_deals = mc.get(str(userId))
14038 kshitij.so 340
    else:
341
        print "Getting user deals from cache"
14037 kshitij.so 342
    category_specific_deals = user_specific_deals.get(category_id)
343
 
344
    if sort is None or direction is None:
345
        sorted_deals = sorted(category_specific_deals, key = lambda x: (x['persPoints'],x['totalPoints'],x['bestSellerPoints'], x['nlcPoints'], x['rank']),reverse=True)
346
    else:
347
        if sort == "bestSellerPoints":
348
            sorted_deals = sorted(category_specific_deals, key = lambda x: (x['bestSellerPoints'], x['rank'], x['nlcPoints']),reverse=True)
349
        else:
350
            if direction == -1:
351
                rev = True
352
            else:
353
                rev = False
354
            sorted_deals = sorted(category_specific_deals, key = lambda x: (x['available_price']),reverse=rev)
355
 
356
    for d in sorted_deals[offset:offset+limit]:
357
        item = list(get_mongo_connection().Catalog.MasterData.find({'_id':d['_id']}))
358
        if not dealsMap.has_key(item[0]['identifier']):
359
            item[0]['dealRank'] = rank
360
            item[0]['persPoints'] = d['persPoints']
361
            try:
362
                cashBack = __getCashBack(item[0]['_id'], item[0]['source_id'], item[0]['category_id'])
363
                if not cashBack or cashBack.get('cash_back_status')!=1:
364
                    item[0]['cash_back_type'] = 0
365
                    item[0]['cash_back'] = 0
366
                else:
367
                    item[0]['cash_back_type'] = cashBack['cash_back_type']
368
                    item[0]['cash_back'] = cashBack['cash_back']
369
            except:
370
                print "Error in adding cashback to deals"
371
                item[0]['cash_back_type'] = 0
372
                item[0]['cash_back'] = 0
373
            dealsMap[item[0]['identifier']] = item[0]
374
 
375
            rank +=1
376
    return sorted(dealsMap.values(), key=itemgetter('dealRank'))
377
 
378
 
379
def getDeals(userId, category_id, offset, limit, sort, direction):
380
    if not bool(cashBackMap):
381
        populateCashBack()
382
    rank = 1
13771 kshitij.so 383
    deals = {}
13910 kshitij.so 384
    outer_query = []
385
    outer_query.append({"showDeal":1})
386
    query = {}
387
    query['$gt'] = 0
388
    outer_query.append({'totalPoints':query})
389
    if category_id in (3,5):
390
        outer_query.append({'category_id':category_id})
13803 kshitij.so 391
    if sort is None or direction is None:
392
        direct = -1
13910 kshitij.so 393
        print outer_query
394
        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 395
    else:
13910 kshitij.so 396
        print outer_query
13803 kshitij.so 397
        direct = direction
13910 kshitij.so 398
        if sort == "bestSellerPoints":
399
            print "yes,sorting by bestSellerPoints"
400
            data = list(get_mongo_connection().Catalog.Deals.find({"$and":outer_query}).sort([('bestSellerPoints',direct),('rank',direct),('nlcPoints',direct)]).skip(offset).limit(limit))
401
        else:
402
            data = list(get_mongo_connection().Catalog.Deals.find({"$and":outer_query}).sort([(sort,direct)]).skip(offset).limit(limit))
13771 kshitij.so 403
    for d in data:
404
        item = list(get_mongo_connection().Catalog.MasterData.find({'_id':d['_id']}))
405
        if not deals.has_key(item[0]['identifier']):
13921 kshitij.so 406
            item[0]['dealRank'] = rank
407
            try:
408
                cashBack = __getCashBack(item[0]['_id'], item[0]['source_id'], item[0]['category_id'])
409
                if not cashBack or cashBack.get('cash_back_status')!=1:
13928 kshitij.so 410
                    item[0]['cash_back_type'] = 0
411
                    item[0]['cash_back'] = 0
13921 kshitij.so 412
                else:
13928 kshitij.so 413
                    item[0]['cash_back_type'] = cashBack['cash_back_type']
414
                    item[0]['cash_back'] = cashBack['cash_back']
13921 kshitij.so 415
            except:
416
                print "Error in adding cashback to deals"
13928 kshitij.so 417
                item[0]['cash_back_type'] = 0
418
                item[0]['cash_back'] = 0
13771 kshitij.so 419
            deals[item[0]['identifier']] = item[0]
13921 kshitij.so 420
 
13771 kshitij.so 421
            rank +=1
13785 kshitij.so 422
    return sorted(deals.values(), key=itemgetter('dealRank'))
423
 
424
def getItem(skuId):
13795 kshitij.so 425
    try:
426
        skuData = list(get_mongo_connection().Catalog.MasterData.find({'_id':int(skuId)}))
13785 kshitij.so 427
        return skuData
13795 kshitij.so 428
    except:
429
        return [{}]
13836 kshitij.so 430
 
13921 kshitij.so 431
def __getCashBack(skuId, source_id, category_id):
432
    itemCashBack = itemCashBackMap.get(skuId)
433
    if itemCashBack is not None:
434
        return itemCashBack
435
 
436
    sourceCashBack = cashBackMap.get(source_id)
437
    if sourceCashBack is not None and len(sourceCashBack) > 0:
438
        for cashBack in sourceCashBack:
439
            if cashBack.get(category_id) is None:
440
                continue
441
            else:
442
                return cashBack.get(category_id)
443
    else:
444
        return {}
445
 
13836 kshitij.so 446
def getCashBackDetails(identifier, source_id):
13922 kshitij.so 447
    if not bool(cashBackMap):
13921 kshitij.so 448
        populateCashBack()
449
 
13836 kshitij.so 450
    """Need to add item level cashback, no data available right now."""
13771 kshitij.so 451
 
13921 kshitij.so 452
    if source_id in (1,2,4,5):
13839 kshitij.so 453
        skuData = list(get_mongo_connection().Catalog.MasterData.find({'identifier':identifier.strip(), 'source_id':source_id}))
13840 kshitij.so 454
    elif source_id == 3:
13839 kshitij.so 455
        skuData = list(get_mongo_connection().Catalog.MasterData.find({'secondaryIdentifier':identifier.strip(), 'source_id':source_id}))
13840 kshitij.so 456
    else:
457
        return {}
13836 kshitij.so 458
    if len(skuData) > 0:
13921 kshitij.so 459
 
460
        itemCashBack = itemCashBackMap.get(skuData[0]['_id'])
461
        if itemCashBack is not None:
462
            return itemCashBack
463
 
464
        sourceCashBack = cashBackMap.get(source_id)
465
        if sourceCashBack is not None and len(sourceCashBack) > 0:
466
            for cashBack in sourceCashBack:
467
                if cashBack.get(skuData[0]['category_id']) is None:
468
                    continue
469
                else:
470
                    return cashBack.get(skuData[0]['category_id'])
13836 kshitij.so 471
        else:
472
            return {} 
473
    else:
474
        return {}
13986 amit.gupta 475
 
476
 
477
def next_weekday(d, weekday):
478
    days_ahead = weekday - d.weekday()
479
    if days_ahead <= 0: # Target day already happened this week
480
        days_ahead += 7
481
    return d + timedelta(days_ahead)
482
 
13771 kshitij.so 483
 
13970 kshitij.so 484
def getAllDealerPrices(offset, limit):
485
    data = []
486
    collection = get_mongo_connection().Catalog.SkuDealerPrices
487
    cursor = collection.find().skip(offset).limit(limit)
488
    for val in cursor:
489
        master = list(get_mongo_connection().Catalog.MasterData.find({'_id':val['sku']}))
490
        if len(master) > 0:
491
            val['brand'] = master['brand']
492
            val['source_product_name'] = master['source_product_name']
493
            val['skuBundleId'] = master['skuBundleId']
494
        else:
495
            val['brand'] = ""
496
            val['source_product_name'] = ""
497
            val['skuBundleId'] = ""
498
        data.append(val)
499
    return data
500
 
501
def addSkuDealerPrice(data):
502
    collection = get_mongo_connection().Catalog.SkuDealerPrices
503
    cursor = collection.find({"sku":data['sku']})
504
    if cursor.count() > 0:
505
        return {0:"Sku information already present."}
506
    else:
507
        collection.insert(data)
508
        get_mongo_connection().Catalog.MasterData.update({'_id':data['sku']},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=False)
509
        return {1:"Data added successfully"}
510
 
511
def updateSkuDealerPrice(data, _id):
512
    try:
513
        collection = get_mongo_connection().Catalog.SkuDealerPrices
514
        collection.update({'_id':ObjectId(_id)},{"$set":{'dp':data['dp']}},upsert=False, multi = False)
515
        get_mongo_connection().Catalog.MasterData.update({'_id':data['sku']},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=False)
516
        return {1:"Data updated successfully"}
517
    except:
518
        return {0:"Data not updated."}
519
 
520
def updateExceptionalNlc(data, _id):
521
    try:
522
        collection = get_mongo_connection().Catalog.ExceptionalNlc
523
        collection.update({'_id':ObjectId(_id)},{"$set":{'maxNlc':data['maxNlc'], 'minNlc':data['minNlc'], 'overrideNlc':data['overrideNlc']}},upsert=False, multi = False)
524
        get_mongo_connection().Catalog.MasterData.update({'_id':data['sku']},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=False)
525
        return {1:"Data updated successfully"}
526
    except:
527
        return {0:"Data not updated."}
528
 
529
 
13572 kshitij.so 530
def main():
14038 kshitij.so 531
    x = getNewDeals(1, 0, 0, 500, None, None)
14037 kshitij.so 532
    for i in x:
533
        print i['_id'],
534
        print '\t',
535
        print i['persPoints']
13811 kshitij.so 536
 
13921 kshitij.so 537
 
13572 kshitij.so 538
if __name__=='__main__':
13932 amit.gupta 539
    main()