| Line 26... |
Line 26... |
| 26 |
|
26 |
|
| 27 |
DataService.initialize(db_hostname=options.mongoHost)
|
27 |
DataService.initialize(db_hostname=options.mongoHost)
|
| 28 |
|
28 |
|
| 29 |
SOURCE_MAP = {'AMAZON':1,'FLIPKART':2,'SNAPDEAL':3,'SAHOLIC':4, 'SHOPCLUES.COM':5,'PAYTM.COM':6}
|
29 |
SOURCE_MAP = {'AMAZON':1,'FLIPKART':2,'SNAPDEAL':3,'SAHOLIC':4, 'SHOPCLUES.COM':5,'PAYTM.COM':6}
|
| 30 |
|
30 |
|
| - |
|
31 |
def getNetPriceForItem(itemId, source_id, category_id ,price):
|
| - |
|
32 |
cash_back_type = 0
|
| - |
|
33 |
cash_back = 0
|
| - |
|
34 |
try:
|
| - |
|
35 |
cashBack = getCashBack(itemId, source_id, category_id, mc, options.mongoHost)
|
| - |
|
36 |
if not cashBack or cashBack.get('cash_back_status')!=1:
|
| - |
|
37 |
cash_back_type = 0
|
| - |
|
38 |
cash_back = 0
|
| - |
|
39 |
|
| - |
|
40 |
else:
|
| - |
|
41 |
if cashBack['cash_back_type'] in (1,2):
|
| - |
|
42 |
|
| - |
|
43 |
if cashBack.get('maxCashBack') is not None:
|
| - |
|
44 |
|
| - |
|
45 |
if cashBack.get('cash_back_type') ==1 and (float(cashBack.get('cash_back'))*price)/100 > cashBack.get('maxCashBack'):
|
| - |
|
46 |
cashBack['cash_back_type'] = 2
|
| - |
|
47 |
cashBack['cash_back'] = cashBack['maxCashBack']
|
| - |
|
48 |
elif cashBack.get('cash_back_type') ==2 and cashBack.get('cash_back') > cashBack.get('maxCashBack'):
|
| - |
|
49 |
cashBack['cash_back'] = cashBack['maxCashBack']
|
| - |
|
50 |
else:
|
| - |
|
51 |
pass
|
| - |
|
52 |
|
| - |
|
53 |
|
| - |
|
54 |
|
| - |
|
55 |
cash_back_type = cashBack['cash_back_type']
|
| - |
|
56 |
cash_back = float(cashBack['cash_back'])
|
| - |
|
57 |
except Exception as cashBackEx:
|
| - |
|
58 |
pass
|
| - |
|
59 |
|
| - |
|
60 |
if cash_back_type ==1:
|
| - |
|
61 |
return (price - float(cash_back)*price/100)
|
| - |
|
62 |
elif cash_back_type ==2:
|
| - |
|
63 |
return (price - cash_back)
|
| - |
|
64 |
else:
|
| - |
|
65 |
return price
|
| - |
|
66 |
|
| - |
|
67 |
|
| 31 |
def get_mongo_connection(host=options.mongoHost, port=27017):
|
68 |
def get_mongo_connection(host=options.mongoHost, port=27017):
|
| 32 |
global con
|
69 |
global con
|
| 33 |
if con is None:
|
70 |
if con is None:
|
| 34 |
print "Establishing connection %s host and port %d" %(host,port)
|
71 |
print "Establishing connection %s host and port %d" %(host,port)
|
| 35 |
try:
|
72 |
try:
|
| Line 121... |
Line 158... |
| 121 |
print "coupon code",coupon
|
158 |
print "coupon code",coupon
|
| 122 |
if len(coupon) > 0:
|
159 |
if len(coupon) > 0:
|
| 123 |
result['codAvailable'] = 0
|
160 |
result['codAvailable'] = 0
|
| 124 |
available_price = effective_price
|
161 |
available_price = effective_price
|
| 125 |
if result['inStock']:
|
162 |
if result['inStock']:
|
| - |
|
163 |
if result['codAvailable'] ==0:
|
| - |
|
164 |
netPriceAfterCashBack = getNetPriceForItem(data['_id'], SOURCE_MAP.get('PAYTM.COM'), data['category_id'], gross_price)
|
| - |
|
165 |
else:
|
| - |
|
166 |
netPriceAfterCashBack = getNetPriceForItem(data['_id'], SOURCE_MAP.get('PAYTM.COM'), data['category_id'], available_price)
|
| - |
|
167 |
|
| 126 |
get_mongo_connection().Catalog.MasterData.update({'_id':data['_id']}, {'$set' : {'available_price':available_price,'updatedOn':to_java_date(datetime.now()),'priceUpdatedOn':to_java_date(datetime.now()),'in_stock':1,'buyBoxFlag':1,'codAvailable':result.get('codAvailable'),'coupon':coupon,'gross_price':gross_price,'marketPlaceUrl':shareUrl}})
|
168 |
get_mongo_connection().Catalog.MasterData.update({'_id':data['_id']}, {'$set' : {'available_price':available_price,'updatedOn':to_java_date(datetime.now()),'priceUpdatedOn':to_java_date(datetime.now()),'in_stock':1,'buyBoxFlag':1,'codAvailable':result.get('codAvailable'),'coupon':coupon,'gross_price':gross_price,'marketPlaceUrl':shareUrl}})
|
| 127 |
get_mongo_connection().Catalog.Deals.update({'_id':data['_id']}, {'$set' : {'available_price':available_price , 'in_stock':1,'codAvailable':result.get('codAvailable'),'gross_price':gross_price}})
|
169 |
get_mongo_connection().Catalog.Deals.update({'_id':data['_id']}, {'$set' : {'available_price':available_price , 'in_stock':1,'codAvailable':result.get('codAvailable'),'gross_price':gross_price,'netPriceAfterCashBack':netPriceAfterCashBack}})
|
| 128 |
else:
|
170 |
else:
|
| - |
|
171 |
if data['codAvailable'] ==0:
|
| - |
|
172 |
netPriceAfterCashBack = getNetPriceForItem(data['_id'], SOURCE_MAP.get('PAYTM.COM'), data['category_id'], data['gross_price'])
|
| - |
|
173 |
else:
|
| - |
|
174 |
netPriceAfterCashBack = getNetPriceForItem(data['_id'], SOURCE_MAP.get('PAYTM.COM'), data['category_id'], data['available_price'])
|
| - |
|
175 |
|
| 129 |
get_mongo_connection().Catalog.MasterData.update({'_id':data['_id']}, {'$set' : {'updatedOn':to_java_date(datetime.now()),'in_stock':0,'priceUpdatedOn':to_java_date(datetime.now()),'buyBoxFlag':1,'codAvailable':result.get('codAvailable'),'coupon':coupon,'marketPlaceUrl':shareUrl}})
|
176 |
get_mongo_connection().Catalog.MasterData.update({'_id':data['_id']}, {'$set' : {'updatedOn':to_java_date(datetime.now()),'in_stock':0,'priceUpdatedOn':to_java_date(datetime.now()),'buyBoxFlag':1,'codAvailable':result.get('codAvailable'),'coupon':coupon,'marketPlaceUrl':shareUrl}})
|
| 130 |
get_mongo_connection().Catalog.Deals.update({'_id':data['_id']}, {'$set' : {'in_stock':0,'codAvailable':result.get('codAvailable')}})
|
177 |
get_mongo_connection().Catalog.Deals.update({'_id':data['_id']}, {'$set' : {'in_stock':0,'codAvailable':result.get('codAvailable'),'netPriceAfterCashBack':netPriceAfterCashBack}})
|
| 131 |
|
178 |
|
| 132 |
except:
|
179 |
except:
|
| - |
|
180 |
if data['codAvailable'] ==0:
|
| 133 |
get_mongo_connection().Catalog.MasterData.update({'_id':data['_id']}, {'$set' : {'updatedOn':to_java_date(datetime.now()),'in_stock':0,'priceUpdatedOn':to_java_date(datetime.now()),'buyBoxFlag':1}})
|
181 |
netPriceAfterCashBack = getNetPriceForItem(data['_id'], SOURCE_MAP.get('PAYTM.COM'), data['category_id'], data['gross_price'])
|
| - |
|
182 |
else:
|
| 134 |
get_mongo_connection().Catalog.Deals.update({'_id':data['_id']}, {'$set' : {'in_stock':0}})
|
183 |
netPriceAfterCashBack = getNetPriceForItem(data['_id'], SOURCE_MAP.get('PAYTM.COM'), data['category_id'], data['available_price'])
|
| - |
|
184 |
|
| 135 |
|
185 |
|
| - |
|
186 |
get_mongo_connection().Catalog.MasterData.update({'_id':data['_id']}, {'$set' : {'updatedOn':to_java_date(datetime.now()),'in_stock':0,'priceUpdatedOn':to_java_date(datetime.now()),'buyBoxFlag':1}})
|
| - |
|
187 |
get_mongo_connection().Catalog.Deals.update({'_id':data['_id']}, {'$set' : {'in_stock':0,'netPriceAfterCashBack':netPriceAfterCashBack}})
|
| 136 |
|
188 |
|
| 137 |
|
189 |
|
| 138 |
try:
|
190 |
try:
|
| 139 |
recomputeDeal(data)
|
191 |
recomputeDeal(data)
|
| 140 |
except:
|
192 |
except:
|
| Line 167... |
Line 219... |
| 167 |
def recomputeDeal(item):
|
219 |
def recomputeDeal(item):
|
| 168 |
"""Lets recompute deal for this bundle"""
|
220 |
"""Lets recompute deal for this bundle"""
|
| 169 |
print "Recomputing for bundleId %d" %(item.get('skuBundleId'))
|
221 |
print "Recomputing for bundleId %d" %(item.get('skuBundleId'))
|
| 170 |
skuBundleId = item['skuBundleId']
|
222 |
skuBundleId = item['skuBundleId']
|
| 171 |
|
223 |
|
| 172 |
similarItems = list(get_mongo_connection().Catalog.Deals.find({'skuBundleId':skuBundleId}).sort([('available_price',pymongo.ASCENDING)]))
|
224 |
similarItems = list(get_mongo_connection().Catalog.Deals.find({'skuBundleId':skuBundleId}).sort([('netPriceAfterCashBack',pymongo.ASCENDING)]))
|
| 173 |
bestPrice = float("inf")
|
225 |
bestPrice = float("inf")
|
| 174 |
bestOne = None
|
226 |
bestOne = None
|
| 175 |
bestSellerPoints = 0
|
227 |
bestSellerPoints = 0
|
| 176 |
toUpdate = []
|
228 |
toUpdate = []
|
| 177 |
prepaidBestPrice = float("inf")
|
229 |
prepaidBestPrice = float("inf")
|
| Line 185... |
Line 237... |
| 185 |
get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0, 'prepaidDeal':0 }})
|
237 |
get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0, 'prepaidDeal':0 }})
|
| 186 |
continue
|
238 |
continue
|
| 187 |
if similarItem['source_id'] == SOURCE_MAP.get('SHOPCLUES.COM') and similarItem['rank']==0:
|
239 |
if similarItem['source_id'] == SOURCE_MAP.get('SHOPCLUES.COM') and similarItem['rank']==0:
|
| 188 |
get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0,'prepaidDeal':0 }})
|
240 |
get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0,'prepaidDeal':0 }})
|
| 189 |
continue
|
241 |
continue
|
| 190 |
if similarItem['available_price'] < bestPrice:
|
242 |
if similarItem.get('netPriceAfterCashBack') < bestPrice:
|
| 191 |
bestOne = similarItem
|
243 |
bestOne = similarItem
|
| 192 |
bestPrice = similarItem['available_price']
|
244 |
bestPrice = similarItem.get('netPriceAfterCashBack')
|
| 193 |
bestSellerPoints = similarItem['bestSellerPoints']
|
245 |
bestSellerPoints = similarItem['bestSellerPoints']
|
| 194 |
elif similarItem['available_price'] == bestPrice and bestSellerPoints < similarItem['bestSellerPoints']:
|
246 |
elif similarItem.get('netPriceAfterCashBack') == bestPrice and bestSellerPoints < similarItem['bestSellerPoints']:
|
| 195 |
bestOne = similarItem
|
247 |
bestOne = similarItem
|
| 196 |
bestPrice = similarItem['available_price']
|
248 |
bestPrice = similarItem.get('netPriceAfterCashBack')
|
| 197 |
bestSellerPoints = similarItem['bestSellerPoints']
|
249 |
bestSellerPoints = similarItem['bestSellerPoints']
|
| 198 |
else:
|
250 |
else:
|
| 199 |
pass
|
251 |
pass
|
| 200 |
else:
|
252 |
else:
|
| 201 |
if mc.get("negative_deals") is None:
|
253 |
if mc.get("negative_deals") is None:
|
| Line 204... |
Line 256... |
| 204 |
get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0, 'prepaidDeal':0 }})
|
256 |
get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0, 'prepaidDeal':0 }})
|
| 205 |
continue
|
257 |
continue
|
| 206 |
if similarItem['source_id'] == SOURCE_MAP.get('SHOPCLUES.COM') and similarItem['rank']==0:
|
258 |
if similarItem['source_id'] == SOURCE_MAP.get('SHOPCLUES.COM') and similarItem['rank']==0:
|
| 207 |
get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0,'prepaidDeal':0 }})
|
259 |
get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0,'prepaidDeal':0 }})
|
| 208 |
continue
|
260 |
continue
|
| 209 |
if similarItem['source_id'] == SOURCE_MAP.get('PAYTM.COM'):
|
- |
|
| 210 |
similarItem['available_price'] = similarItem['gross_price']
|
- |
|
| 211 |
if similarItem['available_price'] < prepaidBestPrice:
|
261 |
if similarItem.get('netPriceAfterCashBack') < prepaidBestPrice:
|
| 212 |
prepaidBestOne = similarItem
|
262 |
prepaidBestOne = similarItem
|
| 213 |
prepaidBestPrice = similarItem['available_price']
|
263 |
prepaidBestPrice = similarItem.get('netPriceAfterCashBack')
|
| 214 |
prepaidBestSellerPoints = similarItem['bestSellerPoints']
|
264 |
prepaidBestSellerPoints = similarItem['bestSellerPoints']
|
| 215 |
elif similarItem['available_price'] == prepaidBestPrice and prepaidBestSellerPoints < similarItem['bestSellerPoints']:
|
265 |
elif similarItem.get('netPriceAfterCashBack') == prepaidBestPrice and prepaidBestSellerPoints < similarItem['bestSellerPoints']:
|
| 216 |
prepaidBestOne = similarItem
|
266 |
prepaidBestOne = similarItem
|
| 217 |
prepaidBestPrice = similarItem['available_price']
|
267 |
prepaidBestPrice = similarItem.get('netPriceAfterCashBack')
|
| 218 |
prepaidBestSellerPoints = similarItem['bestSellerPoints']
|
268 |
prepaidBestSellerPoints = similarItem['bestSellerPoints']
|
| 219 |
else:
|
269 |
else:
|
| 220 |
pass
|
270 |
pass
|
| 221 |
if bestOne is not None or prepaidBestOne is not None:
|
271 |
if bestOne is not None or prepaidBestOne is not None:
|
| 222 |
for similarItem in similarItems:
|
272 |
for similarItem in similarItems:
|
| Line 224... |
Line 274... |
| 224 |
if bestOne is not None:
|
274 |
if bestOne is not None:
|
| 225 |
toUpdate.remove(bestOne['_id'])
|
275 |
toUpdate.remove(bestOne['_id'])
|
| 226 |
get_mongo_connection().Catalog.Deals.update({ '_id' : bestOne['_id'] }, {'$set':{'showDeal':1,'prepaidDeal':0 }})
|
276 |
get_mongo_connection().Catalog.Deals.update({ '_id' : bestOne['_id'] }, {'$set':{'showDeal':1,'prepaidDeal':0 }})
|
| 227 |
if prepaidBestOne is not None:
|
277 |
if prepaidBestOne is not None:
|
| 228 |
if bestOne is not None:
|
278 |
if bestOne is not None:
|
| 229 |
if prepaidBestOne['available_price'] < bestOne['available_price']:
|
279 |
if prepaidBestOne.get('netPriceAfterCashBack') < bestOne.get('netPriceAfterCashBack'):
|
| 230 |
toUpdate.remove(prepaidBestOne['_id'])
|
280 |
toUpdate.remove(prepaidBestOne['_id'])
|
| 231 |
get_mongo_connection().Catalog.Deals.update({ '_id' : prepaidBestOne['_id'] }, {'$set':{'showDeal':0,'prepaidDeal':1 }})
|
281 |
get_mongo_connection().Catalog.Deals.update({ '_id' : prepaidBestOne['_id'] }, {'$set':{'showDeal':0,'prepaidDeal':1 }})
|
| 232 |
else:
|
282 |
else:
|
| 233 |
toUpdate.remove(prepaidBestOne['_id'])
|
283 |
toUpdate.remove(prepaidBestOne['_id'])
|
| 234 |
get_mongo_connection().Catalog.Deals.update({ '_id' : prepaidBestOne['_id'] }, {'$set':{'showDeal':0,'prepaidDeal':1 }})
|
284 |
get_mongo_connection().Catalog.Deals.update({ '_id' : prepaidBestOne['_id'] }, {'$set':{'showDeal':0,'prepaidDeal':1 }})
|
| 235 |
if len(toUpdate) > 0:
|
285 |
if len(toUpdate) > 0:
|
| 236 |
get_mongo_connection().Catalog.Deals.update({ '_id' : { "$in": toUpdate } }, {'$set':{'showDeal':0,'prepaidDeal':0 }},upsert=False, multi=True)
|
286 |
get_mongo_connection().Catalog.Deals.update({ '_id' : { "$in": toUpdate } }, {'$set':{'showDeal':0,'prepaidDeal':0 }},upsert=False, multi=True)
|
| 237 |
|
287 |
|
| - |
|
288 |
|
| 238 |
def main():
|
289 |
def main():
|
| 239 |
populate()
|
290 |
populate()
|
| 240 |
|
291 |
|
| 241 |
if __name__=='__main__':
|
292 |
if __name__=='__main__':
|
| 242 |
main()
|
293 |
main()
|
| 243 |
|
294 |
|