| Line 33... |
Line 33... |
| 33 |
except Exception, e:
|
33 |
except Exception, e:
|
| 34 |
print e
|
34 |
print e
|
| 35 |
return None
|
35 |
return None
|
| 36 |
return con
|
36 |
return con
|
| 37 |
|
37 |
|
| - |
|
38 |
def getNetPriceForItem(itemId, source_id, category_id ,price):
|
| - |
|
39 |
cash_back_type = 0
|
| - |
|
40 |
cash_back = 0
|
| - |
|
41 |
try:
|
| - |
|
42 |
cashBack = getCashBack(itemId, source_id, category_id, mc, options.mongoHost)
|
| - |
|
43 |
if not cashBack or cashBack.get('cash_back_status')!=1:
|
| - |
|
44 |
cash_back_type = 0
|
| - |
|
45 |
cash_back = 0
|
| - |
|
46 |
|
| - |
|
47 |
else:
|
| - |
|
48 |
if cashBack['cash_back_type'] in (1,2):
|
| - |
|
49 |
|
| - |
|
50 |
if cashBack.get('maxCashBack') is not None:
|
| - |
|
51 |
|
| - |
|
52 |
if cashBack.get('cash_back_type') ==1 and (float(cashBack.get('cash_back'))*price)/100 > cashBack.get('maxCashBack'):
|
| - |
|
53 |
cashBack['cash_back_type'] = 2
|
| - |
|
54 |
cashBack['cash_back'] = cashBack['maxCashBack']
|
| - |
|
55 |
elif cashBack.get('cash_back_type') ==2 and cashBack.get('cash_back') > cashBack.get('maxCashBack'):
|
| - |
|
56 |
cashBack['cash_back'] = cashBack['maxCashBack']
|
| - |
|
57 |
else:
|
| - |
|
58 |
pass
|
| - |
|
59 |
|
| - |
|
60 |
|
| - |
|
61 |
|
| - |
|
62 |
cash_back_type = cashBack['cash_back_type']
|
| - |
|
63 |
cash_back = float(cashBack['cash_back'])
|
| - |
|
64 |
except Exception as cashBackEx:
|
| - |
|
65 |
pass
|
| - |
|
66 |
|
| - |
|
67 |
if cash_back_type ==1:
|
| - |
|
68 |
return (price - float(cash_back)*price/100)
|
| - |
|
69 |
elif cash_back_type ==2:
|
| - |
|
70 |
return (price - cash_back)
|
| - |
|
71 |
else:
|
| - |
|
72 |
return price
|
| - |
|
73 |
|
| 38 |
def populate():
|
74 |
def populate():
|
| 39 |
toScrapMap = {}
|
75 |
toScrapMap = {}
|
| 40 |
bestSellers = list(get_mongo_connection().Catalog.MasterData.find({'rank':{'$gt':0}}))
|
76 |
bestSellers = list(get_mongo_connection().Catalog.MasterData.find({'rank':{'$gt':0}}))
|
| 41 |
for bestSeller in bestSellers:
|
77 |
for bestSeller in bestSellers:
|
| 42 |
amazonBestSellers = list(get_mongo_connection().Catalog.MasterData.find({'skuBundleId':bestSeller['skuBundleId'],'source_id':1}))
|
78 |
amazonBestSellers = list(get_mongo_connection().Catalog.MasterData.find({'skuBundleId':bestSeller['skuBundleId'],'source_id':1}))
|
| Line 119... |
Line 155... |
| 119 |
dealScraping = False
|
155 |
dealScraping = False
|
| 120 |
|
156 |
|
| 121 |
print lowestPrice
|
157 |
print lowestPrice
|
| 122 |
if lowestPrice > 0:
|
158 |
if lowestPrice > 0:
|
| 123 |
inStock = 1
|
159 |
inStock = 1
|
| - |
|
160 |
netPriceAfterCashBack = getNetPriceForItem(data['_id'], SOURCE_MAP.get('AMAZON'), data['category_id'], lowestPrice)
|
| - |
|
161 |
else:
|
| - |
|
162 |
netPriceAfterCashBack = getNetPriceForItem(data['_id'], SOURCE_MAP.get('AMAZON'), data['category_id'], data['available_price'])
|
| - |
|
163 |
|
| 124 |
print lowestPrice
|
164 |
print lowestPrice
|
| 125 |
print inStock
|
165 |
print inStock
|
| 126 |
if lowestPrice > 0:
|
166 |
if lowestPrice > 0:
|
| 127 |
get_mongo_connection().Catalog.MasterData.update({'_id':data['_id']}, {'$set' : {'available_price':lowestPrice,'updatedOn':to_java_date(datetime.now()),'priceUpdatedOn':to_java_date(datetime.now()),'in_stock':inStock}}, multi=True)
|
167 |
get_mongo_connection().Catalog.MasterData.update({'_id':data['_id']}, {'$set' : {'available_price':lowestPrice,'updatedOn':to_java_date(datetime.now()),'priceUpdatedOn':to_java_date(datetime.now()),'in_stock':inStock}}, multi=True)
|
| 128 |
get_mongo_connection().Catalog.Deals.update({'_id':data['_id']}, {'$set' : {'available_price':lowestPrice , 'in_stock':inStock,'dealType':data['dealType'],'codAvailable':data['codAvailable']}}, multi=True)
|
168 |
get_mongo_connection().Catalog.Deals.update({'_id':data['_id']}, {'$set' : {'available_price':lowestPrice , 'in_stock':inStock,'dealType':data['dealType'],'codAvailable':data['codAvailable'],'netPriceAfterCashBack':netPriceAfterCashBack}}, multi=True)
|
| 129 |
else:
|
169 |
else:
|
| 130 |
get_mongo_connection().Catalog.MasterData.update({'_id':data['_id']}, {'$set' : {'updatedOn':to_java_date(datetime.now()),'in_stock':inStock,'priceUpdatedOn':to_java_date(datetime.now())}}, multi=True)
|
170 |
get_mongo_connection().Catalog.MasterData.update({'_id':data['_id']}, {'$set' : {'updatedOn':to_java_date(datetime.now()),'in_stock':inStock,'priceUpdatedOn':to_java_date(datetime.now())}}, multi=True)
|
| 131 |
get_mongo_connection().Catalog.Deals.update({'_id':data['_id']}, {'$set' : {'in_stock':inStock,'dealType':data['dealType'],'codAvailable':data['codAvailable']}})
|
171 |
get_mongo_connection().Catalog.Deals.update({'_id':data['_id']}, {'$set' : {'in_stock':inStock,'dealType':data['dealType'],'codAvailable':data['codAvailable'], 'netPriceAfterCashBack':netPriceAfterCashBack}})
|
| 132 |
|
172 |
|
| 133 |
try:
|
173 |
try:
|
| 134 |
recomputeDeal(data)
|
174 |
recomputeDeal(data)
|
| 135 |
except:
|
175 |
except:
|
| 136 |
print "Unable to compute deal for ",data['skuBundleId']
|
176 |
print "Unable to compute deal for ",data['skuBundleId']
|
| Line 164... |
Line 204... |
| 164 |
def recomputeDeal(item):
|
204 |
def recomputeDeal(item):
|
| 165 |
"""Lets recompute deal for this bundle"""
|
205 |
"""Lets recompute deal for this bundle"""
|
| 166 |
print "Recomputing for bundleId %d" %(item.get('skuBundleId'))
|
206 |
print "Recomputing for bundleId %d" %(item.get('skuBundleId'))
|
| 167 |
skuBundleId = item['skuBundleId']
|
207 |
skuBundleId = item['skuBundleId']
|
| 168 |
|
208 |
|
| 169 |
similarItems = list(get_mongo_connection().Catalog.Deals.find({'skuBundleId':skuBundleId}).sort([('available_price',pymongo.ASCENDING)]))
|
209 |
similarItems = list(get_mongo_connection().Catalog.Deals.find({'skuBundleId':skuBundleId}).sort([('netPriceAfterCashBack',pymongo.ASCENDING)]))
|
| 170 |
bestPrice = float("inf")
|
210 |
bestPrice = float("inf")
|
| 171 |
bestOne = None
|
211 |
bestOne = None
|
| 172 |
bestSellerPoints = 0
|
212 |
bestSellerPoints = 0
|
| 173 |
toUpdate = []
|
213 |
toUpdate = []
|
| 174 |
prepaidBestPrice = float("inf")
|
214 |
prepaidBestPrice = float("inf")
|
| Line 182... |
Line 222... |
| 182 |
get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0, 'prepaidDeal':0 }})
|
222 |
get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0, 'prepaidDeal':0 }})
|
| 183 |
continue
|
223 |
continue
|
| 184 |
if similarItem['source_id'] == SOURCE_MAP.get('SHOPCLUES.COM') and similarItem['rank']==0:
|
224 |
if similarItem['source_id'] == SOURCE_MAP.get('SHOPCLUES.COM') and similarItem['rank']==0:
|
| 185 |
get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0,'prepaidDeal':0 }})
|
225 |
get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0,'prepaidDeal':0 }})
|
| 186 |
continue
|
226 |
continue
|
| 187 |
if similarItem['available_price'] < bestPrice:
|
227 |
if similarItem.get('netPriceAfterCashBack') < bestPrice:
|
| 188 |
bestOne = similarItem
|
228 |
bestOne = similarItem
|
| 189 |
bestPrice = similarItem['available_price']
|
229 |
bestPrice = similarItem.get('netPriceAfterCashBack')
|
| 190 |
bestSellerPoints = similarItem['bestSellerPoints']
|
230 |
bestSellerPoints = similarItem['bestSellerPoints']
|
| 191 |
elif similarItem['available_price'] == bestPrice and bestSellerPoints < similarItem['bestSellerPoints']:
|
231 |
elif similarItem.get('netPriceAfterCashBack') == bestPrice and bestSellerPoints < similarItem['bestSellerPoints']:
|
| 192 |
bestOne = similarItem
|
232 |
bestOne = similarItem
|
| 193 |
bestPrice = similarItem['available_price']
|
233 |
bestPrice = similarItem.get('netPriceAfterCashBack')
|
| 194 |
bestSellerPoints = similarItem['bestSellerPoints']
|
234 |
bestSellerPoints = similarItem['bestSellerPoints']
|
| 195 |
else:
|
235 |
else:
|
| 196 |
pass
|
236 |
pass
|
| 197 |
else:
|
237 |
else:
|
| 198 |
if mc.get("negative_deals") is None:
|
238 |
if mc.get("negative_deals") is None:
|
| Line 201... |
Line 241... |
| 201 |
get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0, 'prepaidDeal':0 }})
|
241 |
get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0, 'prepaidDeal':0 }})
|
| 202 |
continue
|
242 |
continue
|
| 203 |
if similarItem['source_id'] == SOURCE_MAP.get('SHOPCLUES.COM') and similarItem['rank']==0:
|
243 |
if similarItem['source_id'] == SOURCE_MAP.get('SHOPCLUES.COM') and similarItem['rank']==0:
|
| 204 |
get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0,'prepaidDeal':0 }})
|
244 |
get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0,'prepaidDeal':0 }})
|
| 205 |
continue
|
245 |
continue
|
| 206 |
if similarItem['source_id'] == SOURCE_MAP.get('PAYTM.COM'):
|
- |
|
| 207 |
similarItem['available_price'] = similarItem['gross_price']
|
- |
|
| 208 |
if similarItem['available_price'] < prepaidBestPrice:
|
246 |
if similarItem.get('netPriceAfterCashBack') < prepaidBestPrice:
|
| 209 |
prepaidBestOne = similarItem
|
247 |
prepaidBestOne = similarItem
|
| 210 |
prepaidBestPrice = similarItem['available_price']
|
248 |
prepaidBestPrice = similarItem.get('netPriceAfterCashBack')
|
| 211 |
prepaidBestSellerPoints = similarItem['bestSellerPoints']
|
249 |
prepaidBestSellerPoints = similarItem['bestSellerPoints']
|
| 212 |
elif similarItem['available_price'] == prepaidBestPrice and prepaidBestSellerPoints < similarItem['bestSellerPoints']:
|
250 |
elif similarItem.get('netPriceAfterCashBack') == prepaidBestPrice and prepaidBestSellerPoints < similarItem['bestSellerPoints']:
|
| 213 |
prepaidBestOne = similarItem
|
251 |
prepaidBestOne = similarItem
|
| 214 |
prepaidBestPrice = similarItem['available_price']
|
252 |
prepaidBestPrice = similarItem.get('netPriceAfterCashBack')
|
| 215 |
prepaidBestSellerPoints = similarItem['bestSellerPoints']
|
253 |
prepaidBestSellerPoints = similarItem['bestSellerPoints']
|
| 216 |
else:
|
254 |
else:
|
| 217 |
pass
|
255 |
pass
|
| 218 |
if bestOne is not None or prepaidBestOne is not None:
|
256 |
if bestOne is not None or prepaidBestOne is not None:
|
| 219 |
for similarItem in similarItems:
|
257 |
for similarItem in similarItems:
|
| Line 221... |
Line 259... |
| 221 |
if bestOne is not None:
|
259 |
if bestOne is not None:
|
| 222 |
toUpdate.remove(bestOne['_id'])
|
260 |
toUpdate.remove(bestOne['_id'])
|
| 223 |
get_mongo_connection().Catalog.Deals.update({ '_id' : bestOne['_id'] }, {'$set':{'showDeal':1,'prepaidDeal':0 }})
|
261 |
get_mongo_connection().Catalog.Deals.update({ '_id' : bestOne['_id'] }, {'$set':{'showDeal':1,'prepaidDeal':0 }})
|
| 224 |
if prepaidBestOne is not None:
|
262 |
if prepaidBestOne is not None:
|
| 225 |
if bestOne is not None:
|
263 |
if bestOne is not None:
|
| 226 |
if prepaidBestOne['available_price'] < bestOne['available_price']:
|
264 |
if prepaidBestOne.get('netPriceAfterCashBack') < bestOne.get('netPriceAfterCashBack'):
|
| 227 |
toUpdate.remove(prepaidBestOne['_id'])
|
265 |
toUpdate.remove(prepaidBestOne['_id'])
|
| 228 |
get_mongo_connection().Catalog.Deals.update({ '_id' : prepaidBestOne['_id'] }, {'$set':{'showDeal':0,'prepaidDeal':1 }})
|
266 |
get_mongo_connection().Catalog.Deals.update({ '_id' : prepaidBestOne['_id'] }, {'$set':{'showDeal':0,'prepaidDeal':1 }})
|
| 229 |
else:
|
267 |
else:
|
| 230 |
toUpdate.remove(prepaidBestOne['_id'])
|
268 |
toUpdate.remove(prepaidBestOne['_id'])
|
| 231 |
get_mongo_connection().Catalog.Deals.update({ '_id' : prepaidBestOne['_id'] }, {'$set':{'showDeal':0,'prepaidDeal':1 }})
|
269 |
get_mongo_connection().Catalog.Deals.update({ '_id' : prepaidBestOne['_id'] }, {'$set':{'showDeal':0,'prepaidDeal':1 }})
|