| Line 21... |
Line 21... |
| 21 |
|
21 |
|
| 22 |
mc = MemCache(options.mongoHost)
|
22 |
mc = MemCache(options.mongoHost)
|
| 23 |
|
23 |
|
| 24 |
ignoreItems = []
|
24 |
ignoreItems = []
|
| 25 |
|
25 |
|
| - |
|
26 |
SOURCE_MAP = {'AMAZON':1,'FLIPKART':2,'SNAPDEAL':3,'SAHOLIC':4, 'SHOPCLUES.COM':5}
|
| - |
|
27 |
|
| 26 |
def get_mongo_connection(host=options.mongoHost, port=27017):
|
28 |
def get_mongo_connection(host=options.mongoHost, port=27017):
|
| 27 |
global con
|
29 |
global con
|
| 28 |
if con is None:
|
30 |
if con is None:
|
| 29 |
print "Establishing connection %s host and port %d" %(host,port)
|
31 |
print "Establishing connection %s host and port %d" %(host,port)
|
| 30 |
try:
|
32 |
try:
|
| Line 125... |
Line 127... |
| 125 |
inStock = 1
|
127 |
inStock = 1
|
| 126 |
print lowestPrice
|
128 |
print lowestPrice
|
| 127 |
print inStock
|
129 |
print inStock
|
| 128 |
if lowestPrice > 0:
|
130 |
if lowestPrice > 0:
|
| 129 |
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)
|
131 |
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)
|
| 130 |
get_mongo_connection().Catalog.Deals.update({'_id':data['_id']}, {'$set' : {'available_price':lowestPrice , 'in_stock':inStock,'dealType':data['dealType']}}, multi=True)
|
132 |
get_mongo_connection().Catalog.Deals.update({'_id':data['_id']}, {'$set' : {'available_price':lowestPrice , 'in_stock':inStock,'dealType':data['dealType'],'codAvailable':data['codAvailable']}}, multi=True)
|
| 131 |
else:
|
133 |
else:
|
| 132 |
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)
|
134 |
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)
|
| 133 |
get_mongo_connection().Catalog.Deals.update({'_id':data['_id']}, {'$set' : {'in_stock':inStock,'dealType':data['dealType']}}, multi=True)
|
135 |
get_mongo_connection().Catalog.Deals.update({'_id':data['_id']}, {'$set' : {'in_stock':inStock,'dealType':data['dealType'],'codAvailable':data['codAvailable']}})
|
| 134 |
|
136 |
|
| 135 |
try:
|
137 |
try:
|
| 136 |
recomputeDeal(data)
|
138 |
recomputeDeal(data)
|
| 137 |
except:
|
139 |
except:
|
| 138 |
print "Unable to compute deal for ",data['skuBundleId']
|
140 |
print "Unable to compute deal for ",data['skuBundleId']
|
| Line 158... |
Line 160... |
| 158 |
|
160 |
|
| 159 |
|
161 |
|
| 160 |
|
162 |
|
| 161 |
def recomputeDeal(item):
|
163 |
def recomputeDeal(item):
|
| 162 |
"""Lets recompute deal for this bundle"""
|
164 |
"""Lets recompute deal for this bundle"""
|
| 163 |
print "Recomputing for bundleId",item.get('skuBundleId')
|
165 |
print "Recomputing for bundleId %d" %(item.get('skuBundleId'))
|
| 164 |
skuBundleId = item['skuBundleId']
|
166 |
skuBundleId = item['skuBundleId']
|
| 165 |
|
167 |
|
| 166 |
similarItems = list(get_mongo_connection().Catalog.Deals.find({'skuBundleId':skuBundleId}).sort([('available_price',pymongo.ASCENDING)]))
|
168 |
similarItems = list(get_mongo_connection().Catalog.Deals.find({'skuBundleId':skuBundleId}).sort([('available_price',pymongo.ASCENDING)]))
|
| 167 |
bestPrice = float("inf")
|
169 |
bestPrice = float("inf")
|
| 168 |
bestOne = None
|
170 |
bestOne = None
|
| 169 |
bestSellerPoints = 0
|
171 |
bestSellerPoints = 0
|
| 170 |
toUpdate = []
|
172 |
toUpdate = []
|
| - |
|
173 |
prepaidBestPrice = float("inf")
|
| - |
|
174 |
prepaidBestOne = None
|
| - |
|
175 |
prepaidBestSellerPoints = 0
|
| 171 |
for similarItem in similarItems:
|
176 |
for similarItem in similarItems:
|
| 172 |
if mc.get("negative_deals") is None:
|
- |
|
| 173 |
populateNegativeDeals()
|
- |
|
| 174 |
# try:
|
- |
|
| 175 |
# cashBack = getCashBack(similarItem['_id'], similarItem['source_id'], similarItem['category_id'], mc, options.mongoHost)
|
- |
|
| 176 |
# if not cashBack or cashBack.get('cash_back_status')!=1:
|
- |
|
| 177 |
# pass
|
- |
|
| 178 |
# else:
|
- |
|
| 179 |
# if cashBack['cash_back_type'] ==1:
|
- |
|
| 180 |
# similarItem['available_price'] = similarItem['available_price'] - similarItem['available_price'] * float(cashBack['cash_back'])/100
|
- |
|
| 181 |
# elif cashBack['cash_back_type'] ==2:
|
- |
|
| 182 |
# similarItem['available_price'] = similarItem['available_price'] - float(cashBack['cash_back'])
|
- |
|
| 183 |
# else:
|
- |
|
| 184 |
# pass
|
- |
|
| 185 |
# except Exception as cashBackEx:
|
- |
|
| 186 |
# print cashBackEx
|
- |
|
| 187 |
# print "Error calculating cashback."
|
- |
|
| 188 |
if similarItem['_id'] == item['_id']:
|
177 |
if similarItem['_id'] == item['_id']:
|
| 189 |
try:
|
178 |
try:
|
| 190 |
recomputePoints(item, similarItem)
|
179 |
recomputePoints(item, similarItem)
|
| 191 |
except:
|
180 |
except:
|
| 192 |
traceback.print_exc()
|
181 |
traceback.print_exc()
|
| - |
|
182 |
if similarItem['codAvailable'] ==1:
|
| - |
|
183 |
if mc.get("negative_deals") is None:
|
| - |
|
184 |
populateNegativeDeals()
|
| 193 |
if similarItem['in_stock'] == 0 or similarItem['maxprice'] is None or similarItem['maxprice'] < similarItem['available_price'] or similarItem['_id'] in mc.get("negative_deals"):
|
185 |
if similarItem['in_stock'] == 0 or similarItem['maxprice'] is None or similarItem['maxprice'] < similarItem['available_price'] or similarItem['_id'] in mc.get("negative_deals"):
|
| - |
|
186 |
get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0, 'prepaidDeal':0 }})
|
| - |
|
187 |
continue
|
| - |
|
188 |
if similarItem['source_id'] == SOURCE_MAP.get('SHOPCLUES.COM') and similarItem['rank']==0:
|
| 194 |
get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0 }})
|
189 |
get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0,'prepaidDeal':0 }})
|
| 195 |
continue
|
190 |
continue
|
| 196 |
if similarItem['available_price'] < bestPrice:
|
191 |
if similarItem['available_price'] < bestPrice:
|
| 197 |
bestOne = similarItem
|
192 |
bestOne = similarItem
|
| 198 |
bestPrice = similarItem['available_price']
|
193 |
bestPrice = similarItem['available_price']
|
| 199 |
bestSellerPoints = similarItem['bestSellerPoints']
|
194 |
bestSellerPoints = similarItem['bestSellerPoints']
|
| 200 |
elif similarItem['available_price'] == bestPrice and bestSellerPoints < similarItem['bestSellerPoints']:
|
195 |
elif similarItem['available_price'] == bestPrice and bestSellerPoints < similarItem['bestSellerPoints']:
|
| 201 |
bestOne = similarItem
|
196 |
bestOne = similarItem
|
| 202 |
bestPrice = similarItem['available_price']
|
197 |
bestPrice = similarItem['available_price']
|
| 203 |
bestSellerPoints = similarItem['bestSellerPoints']
|
198 |
bestSellerPoints = similarItem['bestSellerPoints']
|
| - |
|
199 |
else:
|
| - |
|
200 |
pass
|
| 204 |
else:
|
201 |
else:
|
| - |
|
202 |
if mc.get("negative_deals") is None:
|
| - |
|
203 |
populateNegativeDeals()
|
| - |
|
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:
|
| - |
|
208 |
get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0,'prepaidDeal':0 }})
|
| - |
|
209 |
continue
|
| - |
|
210 |
if similarItem['available_price'] < prepaidBestPrice:
|
| - |
|
211 |
prepaidBestOne = similarItem
|
| - |
|
212 |
prepaidBestPrice = similarItem['available_price']
|
| - |
|
213 |
prepaidBestSellerPoints = similarItem['bestSellerPoints']
|
| - |
|
214 |
elif similarItem['available_price'] == prepaidBestPrice and prepaidBestSellerPoints < similarItem['bestSellerPoints']:
|
| - |
|
215 |
prepaidBestOne = similarItem
|
| - |
|
216 |
prepaidBestPrice = similarItem['available_price']
|
| - |
|
217 |
prepaidBestSellerPoints = similarItem['bestSellerPoints']
|
| - |
|
218 |
else:
|
| 205 |
pass
|
219 |
pass
|
| 206 |
if bestOne is not None:
|
220 |
if bestOne is not None and prepaidBestOne is not None:
|
| 207 |
for similarItem in similarItems:
|
221 |
for similarItem in similarItems:
|
| 208 |
toUpdate.append(similarItem['_id'])
|
222 |
toUpdate.append(similarItem['_id'])
|
| 209 |
toUpdate.remove(bestOne['_id'])
|
223 |
toUpdate.remove(bestOne['_id'])
|
| - |
|
224 |
toUpdate.remove(prepaidBestOne['_id'])
|
| 210 |
get_mongo_connection().Catalog.Deals.update({ '_id' : bestOne['_id'] }, {'$set':{'showDeal':1 }})
|
225 |
get_mongo_connection().Catalog.Deals.update({ '_id' : bestOne['_id'] }, {'$set':{'showDeal':1,'prepaidDeal':0 }})
|
| - |
|
226 |
get_mongo_connection().Catalog.Deals.update({ '_id' : prepaidBestOne['_id'] }, {'$set':{'showDeal':0,'prepaidDeal':1 }})
|
| 211 |
if len(toUpdate) > 0:
|
227 |
if len(toUpdate) > 0:
|
| 212 |
get_mongo_connection().Catalog.Deals.update({ '_id' : { "$in": toUpdate } }, {'$set':{'showDeal':0 }},upsert=False, multi=True)
|
228 |
get_mongo_connection().Catalog.Deals.update({ '_id' : { "$in": toUpdate } }, {'$set':{'showDeal':0,'prepaidDeal':0 }},upsert=False, multi=True)
|
| 213 |
|
- |
|
| 214 |
|
- |
|
| 215 |
|
229 |
|
| 216 |
def main():
|
230 |
def main():
|
| 217 |
populate()
|
231 |
populate()
|
| 218 |
|
232 |
|
| 219 |
if __name__=='__main__':
|
233 |
if __name__=='__main__':
|