Subversion Repositories SmartDukaan

Rev

Rev 15268 | Rev 16026 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 15268 Rev 16019
Line 30... Line 30...
30
 
30
 
31
mc = MemCache(options.mongoHost)
31
mc = MemCache(options.mongoHost)
32
 
32
 
33
DataService.initialize(db_hostname=options.hostname)
33
DataService.initialize(db_hostname=options.hostname)
34
 
34
 
-
 
35
SOURCE_MAP = {'AMAZON':1,'FLIPKART':2,'SNAPDEAL':3,'SAHOLIC':4, 'SHOPCLUES.COM':5}
-
 
36
 
35
def get_mongo_connection(host=options.mongoHost, port=27017):
37
def get_mongo_connection(host=options.mongoHost, port=27017):
36
    global con
38
    global con
37
    if con is None:
39
    if con is None:
38
        print "Establishing connection %s host and port %d" %(host,port)
40
        print "Establishing connection %s host and port %d" %(host,port)
39
        try:
41
        try:
Line 175... Line 177...
175
    else:
177
    else:
176
        dealPoints = 0
178
        dealPoints = 0
177
    get_mongo_connection().Catalog.Deals.update({'_id':deal['_id']},{"$set":{'totalPoints':deal['totalPoints'] - deal['nlcPoints'] + nlcPoints - deal['dealPoints'] +dealPoints , 'nlcPoints': nlcPoints, 'dealPoints': dealPoints, 'manualDealThresholdPrice': item['manualDealThresholdPrice']}})
179
    get_mongo_connection().Catalog.Deals.update({'_id':deal['_id']},{"$set":{'totalPoints':deal['totalPoints'] - deal['nlcPoints'] + nlcPoints - deal['dealPoints'] +dealPoints , 'nlcPoints': nlcPoints, 'dealPoints': dealPoints, 'manualDealThresholdPrice': item['manualDealThresholdPrice']}})
178
 
180
 
179
    
181
    
180
  
-
 
181
 
-
 
182
def recomputeDeal(item):
182
def recomputeDeal(item):
183
    """Lets recompute deal for this bundle"""
183
    """Lets recompute deal for this bundle"""
184
    print "Recomputing for bundleId",item.get('skuBundleId')
184
    print "Recomputing for bundleId %d" %(item.get('skuBundleId'))
185
    skuBundleId = item['skuBundleId']
185
    skuBundleId = item['skuBundleId']
186
    
186
    
187
    similarItems = list(get_mongo_connection().Catalog.Deals.find({'skuBundleId':skuBundleId}).sort([('available_price',pymongo.ASCENDING)]))
187
    similarItems = list(get_mongo_connection().Catalog.Deals.find({'skuBundleId':skuBundleId}).sort([('available_price',pymongo.ASCENDING)]))
188
    bestPrice = float("inf")
188
    bestPrice = float("inf")
189
    bestOne = None
189
    bestOne = None
190
    bestSellerPoints = 0
190
    bestSellerPoints = 0
191
    toUpdate = []
191
    toUpdate = []
-
 
192
    prepaidBestPrice = float("inf")
-
 
193
    prepaidBestOne = None
-
 
194
    prepaidBestSellerPoints = 0
192
    for similarItem in similarItems:
195
    for similarItem in similarItems:
193
        if mc.get("negative_deals") is None:
-
 
194
            populateNegativeDeals()
-
 
195
#        try:
-
 
196
#            cashBack = getCashBack(similarItem['_id'], similarItem['source_id'], similarItem['category_id'], mc, options.mongoHost)
-
 
197
#            if not cashBack or cashBack.get('cash_back_status')!=1:
-
 
198
#                pass
-
 
199
#            else:
-
 
200
#                if cashBack['cash_back_type'] ==1:
-
 
201
#                    similarItem['available_price'] = similarItem['available_price'] - similarItem['available_price'] * float(cashBack['cash_back'])/100
-
 
202
#                elif cashBack['cash_back_type'] ==2:
-
 
203
#                    similarItem['available_price'] = similarItem['available_price'] - float(cashBack['cash_back'])
-
 
204
#                else:
-
 
205
#                    pass
-
 
206
#        except Exception as cashBackEx:
-
 
207
#            print cashBackEx
-
 
208
#            print "Error calculating cashback."
-
 
209
        if similarItem['_id'] == item['_id']:
196
        if similarItem['_id'] == item['_id']:
210
            try:
197
            try:
211
                recomputePoints(item, similarItem)
198
                recomputePoints(item, similarItem)
212
            except:
199
            except:
213
                traceback.print_exc()
200
                traceback.print_exc()
-
 
201
        if similarItem['codAvailable'] ==1:
-
 
202
            if mc.get("negative_deals") is None:
-
 
203
                populateNegativeDeals()
214
        if similarItem['in_stock'] == 0 or similarItem['maxprice'] is None or similarItem['maxprice'] < similarItem['available_price'] or similarItem['_id'] in mc.get("negative_deals"):
204
            if similarItem['in_stock'] == 0 or similarItem['maxprice'] is None or similarItem['maxprice'] < similarItem['available_price'] or similarItem['_id'] in mc.get("negative_deals"):
-
 
205
                get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0, 'prepaidDeal':0 }})
-
 
206
                continue
-
 
207
            if similarItem['source_id'] == SOURCE_MAP.get('SHOPCLUES.COM') and similarItem['rank']==0:
215
            get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0 }})
208
                get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0,'prepaidDeal':0 }})
216
            continue
209
                continue
217
        if similarItem['available_price'] < bestPrice:
210
            if similarItem['available_price'] < bestPrice:
218
            bestOne = similarItem
211
                bestOne = similarItem
219
            bestPrice = similarItem['available_price']
212
                bestPrice = similarItem['available_price']
220
            bestSellerPoints = similarItem['bestSellerPoints']
213
                bestSellerPoints = similarItem['bestSellerPoints']
221
        elif similarItem['available_price'] == bestPrice and bestSellerPoints < similarItem['bestSellerPoints']:
214
            elif similarItem['available_price'] == bestPrice and bestSellerPoints < similarItem['bestSellerPoints']:
222
            bestOne = similarItem
215
                bestOne = similarItem
223
            bestPrice = similarItem['available_price']
216
                bestPrice = similarItem['available_price']
224
            bestSellerPoints = similarItem['bestSellerPoints']
217
                bestSellerPoints = similarItem['bestSellerPoints']
-
 
218
            else:
-
 
219
                pass
225
        else:
220
        else:
-
 
221
            if mc.get("negative_deals") is None:
-
 
222
                populateNegativeDeals()
-
 
223
            if similarItem['in_stock'] == 0 or similarItem['maxprice'] is None or similarItem['maxprice'] < similarItem['available_price'] or similarItem['_id'] in mc.get("negative_deals"):
-
 
224
                get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0, 'prepaidDeal':0 }})
-
 
225
                continue
-
 
226
            if similarItem['source_id'] == SOURCE_MAP.get('SHOPCLUES.COM') and similarItem['rank']==0:
-
 
227
                get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0,'prepaidDeal':0 }})
-
 
228
                continue
-
 
229
            if similarItem['available_price'] < prepaidBestPrice:
-
 
230
                prepaidBestOne = similarItem
-
 
231
                prepaidBestPrice = similarItem['available_price']
-
 
232
                prepaidBestSellerPoints = similarItem['bestSellerPoints']
-
 
233
            elif similarItem['available_price'] == prepaidBestPrice and prepaidBestSellerPoints < similarItem['bestSellerPoints']:
-
 
234
                prepaidBestOne = similarItem
-
 
235
                prepaidBestPrice = similarItem['available_price']
-
 
236
                prepaidBestSellerPoints = similarItem['bestSellerPoints']
-
 
237
            else:
226
            pass
238
                pass
227
    if bestOne is not None:
239
    if bestOne is not None and prepaidBestOne is not None:
228
        for similarItem in similarItems:
240
        for similarItem in similarItems:
229
            toUpdate.append(similarItem['_id'])
241
            toUpdate.append(similarItem['_id'])
230
        toUpdate.remove(bestOne['_id'])
242
        toUpdate.remove(bestOne['_id'])
-
 
243
        toUpdate.remove(prepaidBestOne['_id'])
231
        get_mongo_connection().Catalog.Deals.update({ '_id' : bestOne['_id'] }, {'$set':{'showDeal':1 }})
244
        get_mongo_connection().Catalog.Deals.update({ '_id' : bestOne['_id'] }, {'$set':{'showDeal':1,'prepaidDeal':0 }})
-
 
245
        get_mongo_connection().Catalog.Deals.update({ '_id' : prepaidBestOne['_id'] }, {'$set':{'showDeal':0,'prepaidDeal':1 }})
232
    if len(toUpdate) > 0:
246
    if len(toUpdate) > 0:
233
        get_mongo_connection().Catalog.Deals.update({ '_id' : { "$in": toUpdate } }, {'$set':{'showDeal':0 }},upsert=False, multi=True)
247
        get_mongo_connection().Catalog.Deals.update({ '_id' : { "$in": toUpdate } }, {'$set':{'showDeal':0,'prepaidDeal':0 }},upsert=False, multi=True)
-
 
248
  
-
 
249
 
234
        
250
        
235
def main():
251
def main():
236
    getPrivateDeals()
252
    getPrivateDeals()
237
    try:
253
    try:
238
        getItemsToUpdate()
254
        getItemsToUpdate()