| Line 21... |
Line 21... |
| 21 |
(options, args) = parser.parse_args()
|
21 |
(options, args) = parser.parse_args()
|
| 22 |
|
22 |
|
| 23 |
mc = MemCache(options.mongoHost)
|
23 |
mc = MemCache(options.mongoHost)
|
| 24 |
|
24 |
|
| 25 |
ignoreItems = []
|
25 |
ignoreItems = []
|
| - |
|
26 |
SOURCE_MAP = {'AMAZON':1,'FLIPKART':2,'SNAPDEAL':3,'SAHOLIC':4, 'SHOPCLUES.COM':5}
|
| 26 |
|
27 |
|
| 27 |
def get_mongo_connection(host=options.mongoHost, port=27017):
|
28 |
def get_mongo_connection(host=options.mongoHost, port=27017):
|
| 28 |
global con
|
29 |
global con
|
| 29 |
if con is None:
|
30 |
if con is None:
|
| 30 |
print "Establishing connection %s host and port %d" %(host,port)
|
31 |
print "Establishing connection %s host and port %d" %(host,port)
|
| Line 150... |
Line 151... |
| 150 |
print inStock
|
151 |
print inStock
|
| 151 |
if buyBoxPrice is not None and buyBoxPrice == lowestSp:
|
152 |
if buyBoxPrice is not None and buyBoxPrice == lowestSp:
|
| 152 |
isBuyBox = 1
|
153 |
isBuyBox = 1
|
| 153 |
if lowestSp > 0:
|
154 |
if lowestSp > 0:
|
| 154 |
get_mongo_connection().Catalog.MasterData.update({'_id':data['_id']}, {'$set' : {'available_price':lowestSp,'updatedOn':to_java_date(datetime.now()),'priceUpdatedOn':to_java_date(datetime.now()),'in_stock':inStock,'buyBoxFlag':isBuyBox}}, multi=True)
|
155 |
get_mongo_connection().Catalog.MasterData.update({'_id':data['_id']}, {'$set' : {'available_price':lowestSp,'updatedOn':to_java_date(datetime.now()),'priceUpdatedOn':to_java_date(datetime.now()),'in_stock':inStock,'buyBoxFlag':isBuyBox}}, multi=True)
|
| 155 |
get_mongo_connection().Catalog.Deals.update({'_id':data['_id']}, {'$set' : {'available_price':lowestSp , 'in_stock':inStock}}, multi=True)
|
156 |
get_mongo_connection().Catalog.Deals.update({'_id':data['_id']}, {'$set' : {'available_price':lowestSp , 'in_stock':inStock,'codAvailable':data['codAvailable']}}, multi=True)
|
| 156 |
else:
|
157 |
else:
|
| 157 |
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()),'buyBoxFlag':isBuyBox}}, multi=True)
|
158 |
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()),'buyBoxFlag':isBuyBox}}, multi=True)
|
| 158 |
get_mongo_connection().Catalog.Deals.update({'_id':data['_id']}, {'$set' : {'in_stock':inStock}}, multi=True)
|
159 |
get_mongo_connection().Catalog.Deals.update({'_id':data['_id']}, {'$set' : {'in_stock':inStock,'codAvailable':data['codAvailable']}})
|
| 159 |
|
160 |
|
| 160 |
try:
|
161 |
try:
|
| 161 |
recomputeDeal(data)
|
162 |
recomputeDeal(data)
|
| 162 |
except:
|
163 |
except:
|
| 163 |
print "Unable to compute deal for %s"%(data['skuBundleId'])
|
164 |
print "Unable to compute deal for %s"%(data['skuBundleId'])
|
| Line 175... |
Line 176... |
| 175 |
dealPoints = item['dealPoints']
|
176 |
dealPoints = item['dealPoints']
|
| 176 |
else:
|
177 |
else:
|
| 177 |
dealPoints = 0
|
178 |
dealPoints = 0
|
| 178 |
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']}})
|
| 179 |
|
180 |
|
| 180 |
|
- |
|
| 181 |
|
- |
|
| 182 |
def populateNegativeDeals():
|
181 |
def populateNegativeDeals():
|
| 183 |
negativeDeals = get_mongo_connection().Catalog.NegativeDeals.find().distinct('sku')
|
182 |
negativeDeals = get_mongo_connection().Catalog.NegativeDeals.find().distinct('sku')
|
| 184 |
mc.set("negative_deals", negativeDeals, 600)
|
183 |
mc.set("negative_deals", negativeDeals, 600)
|
| 185 |
|
184 |
|
| 186 |
def recomputeDeal(item):
|
185 |
def recomputeDeal(item):
|
| Line 191... |
Line 190... |
| 191 |
similarItems = list(get_mongo_connection().Catalog.Deals.find({'skuBundleId':skuBundleId}).sort([('available_price',pymongo.ASCENDING)]))
|
190 |
similarItems = list(get_mongo_connection().Catalog.Deals.find({'skuBundleId':skuBundleId}).sort([('available_price',pymongo.ASCENDING)]))
|
| 192 |
bestPrice = float("inf")
|
191 |
bestPrice = float("inf")
|
| 193 |
bestOne = None
|
192 |
bestOne = None
|
| 194 |
bestSellerPoints = 0
|
193 |
bestSellerPoints = 0
|
| 195 |
toUpdate = []
|
194 |
toUpdate = []
|
| - |
|
195 |
prepaidBestPrice = float("inf")
|
| - |
|
196 |
prepaidBestOne = None
|
| - |
|
197 |
prepaidBestSellerPoints = 0
|
| 196 |
for similarItem in similarItems:
|
198 |
for similarItem in similarItems:
|
| 197 |
if mc.get("negative_deals") is None:
|
- |
|
| 198 |
populateNegativeDeals()
|
- |
|
| 199 |
# try:
|
- |
|
| 200 |
# cashBack = getCashBack(similarItem['_id'], similarItem['source_id'], similarItem['category_id'], mc, options.mongoHost)
|
- |
|
| 201 |
# if not cashBack or cashBack.get('cash_back_status')!=1:
|
- |
|
| 202 |
# pass
|
- |
|
| 203 |
# else:
|
- |
|
| 204 |
# if cashBack['cash_back_type'] ==1:
|
- |
|
| 205 |
# similarItem['available_price'] = similarItem['available_price'] - similarItem['available_price'] * float(cashBack['cash_back'])/100
|
- |
|
| 206 |
# elif cashBack['cash_back_type'] ==2:
|
- |
|
| 207 |
# similarItem['available_price'] = similarItem['available_price'] - float(cashBack['cash_back'])
|
- |
|
| 208 |
# else:
|
- |
|
| 209 |
# pass
|
- |
|
| 210 |
# except Exception as cashBackEx:
|
- |
|
| 211 |
# print cashBackEx
|
- |
|
| 212 |
# print "Error calculating cashback."
|
- |
|
| 213 |
if similarItem['_id'] == item['_id']:
|
199 |
if similarItem['_id'] == item['_id']:
|
| - |
|
200 |
try:
|
| 214 |
recomputePoints(item, similarItem)
|
201 |
recomputePoints(item, similarItem)
|
| - |
|
202 |
except:
|
| - |
|
203 |
traceback.print_exc()
|
| - |
|
204 |
if similarItem['codAvailable'] ==1:
|
| - |
|
205 |
if mc.get("negative_deals") is None:
|
| - |
|
206 |
populateNegativeDeals()
|
| 215 |
if similarItem['in_stock'] == 0 or similarItem['maxprice'] is None or similarItem['maxprice'] < similarItem['available_price'] or similarItem['_id'] in mc.get("negative_deals"):
|
207 |
if similarItem['in_stock'] == 0 or similarItem['maxprice'] is None or similarItem['maxprice'] < similarItem['available_price'] or similarItem['_id'] in mc.get("negative_deals"):
|
| - |
|
208 |
get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0, 'prepaidDeal':0 }})
|
| - |
|
209 |
continue
|
| - |
|
210 |
if similarItem['source_id'] == SOURCE_MAP.get('SHOPCLUES.COM') and similarItem['rank']==0:
|
| 216 |
get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0 }})
|
211 |
get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0,'prepaidDeal':0 }})
|
| 217 |
continue
|
212 |
continue
|
| 218 |
if similarItem['available_price'] < bestPrice:
|
213 |
if similarItem['available_price'] < bestPrice:
|
| 219 |
bestOne = similarItem
|
214 |
bestOne = similarItem
|
| 220 |
bestPrice = similarItem['available_price']
|
215 |
bestPrice = similarItem['available_price']
|
| 221 |
bestSellerPoints = similarItem['bestSellerPoints']
|
216 |
bestSellerPoints = similarItem['bestSellerPoints']
|
| 222 |
elif similarItem['available_price'] == bestPrice and bestSellerPoints < similarItem['bestSellerPoints']:
|
217 |
elif similarItem['available_price'] == bestPrice and bestSellerPoints < similarItem['bestSellerPoints']:
|
| 223 |
bestOne = similarItem
|
218 |
bestOne = similarItem
|
| 224 |
bestPrice = similarItem['available_price']
|
219 |
bestPrice = similarItem['available_price']
|
| 225 |
bestSellerPoints = similarItem['bestSellerPoints']
|
220 |
bestSellerPoints = similarItem['bestSellerPoints']
|
| - |
|
221 |
else:
|
| - |
|
222 |
pass
|
| 226 |
else:
|
223 |
else:
|
| - |
|
224 |
if mc.get("negative_deals") is None:
|
| - |
|
225 |
populateNegativeDeals()
|
| - |
|
226 |
if similarItem['in_stock'] == 0 or similarItem['maxprice'] is None or similarItem['maxprice'] < similarItem['available_price'] or similarItem['_id'] in mc.get("negative_deals"):
|
| - |
|
227 |
get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0, 'prepaidDeal':0 }})
|
| - |
|
228 |
continue
|
| - |
|
229 |
if similarItem['source_id'] == SOURCE_MAP.get('SHOPCLUES.COM') and similarItem['rank']==0:
|
| - |
|
230 |
get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0,'prepaidDeal':0 }})
|
| - |
|
231 |
continue
|
| - |
|
232 |
if similarItem['available_price'] < prepaidBestPrice:
|
| - |
|
233 |
prepaidBestOne = similarItem
|
| - |
|
234 |
prepaidBestPrice = similarItem['available_price']
|
| - |
|
235 |
prepaidBestSellerPoints = similarItem['bestSellerPoints']
|
| - |
|
236 |
elif similarItem['available_price'] == prepaidBestPrice and prepaidBestSellerPoints < similarItem['bestSellerPoints']:
|
| - |
|
237 |
prepaidBestOne = similarItem
|
| - |
|
238 |
prepaidBestPrice = similarItem['available_price']
|
| - |
|
239 |
prepaidBestSellerPoints = similarItem['bestSellerPoints']
|
| - |
|
240 |
else:
|
| 227 |
pass
|
241 |
pass
|
| 228 |
if bestOne is not None:
|
242 |
if bestOne is not None and prepaidBestOne is not None:
|
| 229 |
for similarItem in similarItems:
|
243 |
for similarItem in similarItems:
|
| 230 |
toUpdate.append(similarItem['_id'])
|
244 |
toUpdate.append(similarItem['_id'])
|
| 231 |
toUpdate.remove(bestOne['_id'])
|
245 |
toUpdate.remove(bestOne['_id'])
|
| - |
|
246 |
toUpdate.remove(prepaidBestOne['_id'])
|
| 232 |
get_mongo_connection().Catalog.Deals.update({ '_id' : bestOne['_id'] }, {'$set':{'showDeal':1 }})
|
247 |
get_mongo_connection().Catalog.Deals.update({ '_id' : bestOne['_id'] }, {'$set':{'showDeal':1,'prepaidDeal':0 }})
|
| - |
|
248 |
get_mongo_connection().Catalog.Deals.update({ '_id' : prepaidBestOne['_id'] }, {'$set':{'showDeal':0,'prepaidDeal':1 }})
|
| 233 |
if len(toUpdate) > 0:
|
249 |
if len(toUpdate) > 0:
|
| 234 |
get_mongo_connection().Catalog.Deals.update({ '_id' : { "$in": toUpdate } }, {'$set':{'showDeal':0 }},upsert=False, multi=True)
|
250 |
get_mongo_connection().Catalog.Deals.update({ '_id' : { "$in": toUpdate } }, {'$set':{'showDeal':0,'prepaidDeal':0 }},upsert=False, multi=True)
|
| 235 |
|
251 |
|
| 236 |
def main():
|
252 |
def main():
|
| 237 |
populate()
|
253 |
populate()
|
| 238 |
|
254 |
|
| 239 |
if __name__=='__main__':
|
255 |
if __name__=='__main__':
|