| Line 5... |
Line 5... |
| 5 |
from datetime import datetime, timedelta
|
5 |
from datetime import datetime, timedelta
|
| 6 |
from operator import itemgetter
|
6 |
from operator import itemgetter
|
| 7 |
from dtr.utils.AmazonPriceOnlyScraper import AmazonScraper
|
7 |
from dtr.utils.AmazonPriceOnlyScraper import AmazonScraper
|
| 8 |
from dtr.utils import AmazonDealScraper
|
8 |
from dtr.utils import AmazonDealScraper
|
| 9 |
from dtr.utils import FlipkartScraper,NewFlipkartScraper
|
9 |
from dtr.utils import FlipkartScraper,NewFlipkartScraper
|
| - |
|
10 |
from dtr.storage.MemCache import MemCache
|
| - |
|
11 |
|
| - |
|
12 |
mc = MemCache("127.0.0.1")
|
| 10 |
|
13 |
|
| 11 |
con = None
|
14 |
con = None
|
| 12 |
SOURCE_MAP = {'AMAZON':1,'FLIPKART':2,'SNAPDEAL':3,'SAHOLIC':4}
|
15 |
SOURCE_MAP = {'AMAZON':1,'FLIPKART':2,'SNAPDEAL':3,'SAHOLIC':4}
|
| 13 |
|
16 |
|
| 14 |
headers = {
|
17 |
headers = {
|
| Line 235... |
Line 238... |
| 235 |
return {'_id':data['_id'],'available_price':lowestSp,'in_stock':inStock,'source_id':2,'source_product_name':data['source_product_name'],'marketPlaceUrl':data['marketPlaceUrl'],'thumbnail':data['thumbnail']}
|
238 |
return {'_id':data['_id'],'available_price':lowestSp,'in_stock':inStock,'source_id':2,'source_product_name':data['source_product_name'],'marketPlaceUrl':data['marketPlaceUrl'],'thumbnail':data['thumbnail']}
|
| 236 |
except:
|
239 |
except:
|
| 237 |
return {'_id':data['_id'],'available_price':data['available_price'],'in_stock':data['in_stock'],'source_id':2,'source_product_name':data['source_product_name'],'marketPlaceUrl':data['marketPlaceUrl'],'thumbnail':data['thumbnail']}
|
240 |
return {'_id':data['_id'],'available_price':data['available_price'],'in_stock':data['in_stock'],'source_id':2,'source_product_name':data['source_product_name'],'marketPlaceUrl':data['marketPlaceUrl'],'thumbnail':data['thumbnail']}
|
| 238 |
else:
|
241 |
else:
|
| 239 |
return {}
|
242 |
return {}
|
| - |
|
243 |
|
| 240 |
|
244 |
|
| - |
|
245 |
def populateNegativeDeals():
|
| - |
|
246 |
negativeDeals = get_mongo_connection().Catalog.NegativeDeals.find().distinct('sku')
|
| - |
|
247 |
mc.set("negative_deals", negativeDeals, 600)
|
| 241 |
|
248 |
|
| 242 |
def recomputeDeal(skuBundleId):
|
249 |
def recomputeDeal(skuBundleId):
|
| 243 |
"""Lets recompute deal for this bundle"""
|
250 |
"""Lets recompute deal for this bundle"""
|
| 244 |
print "Recomputing for bundleId",skuBundleId
|
251 |
print "Recomputing for bundleId",skuBundleId
|
| 245 |
|
252 |
|
| Line 247... |
Line 254... |
| 247 |
bestPrice = float("inf")
|
254 |
bestPrice = float("inf")
|
| 248 |
bestOne = None
|
255 |
bestOne = None
|
| 249 |
bestSellerPoints = 0
|
256 |
bestSellerPoints = 0
|
| 250 |
toUpdate = []
|
257 |
toUpdate = []
|
| 251 |
for similarItem in similarItems:
|
258 |
for similarItem in similarItems:
|
| - |
|
259 |
if mc.get("negativeDeals") is None:
|
| - |
|
260 |
populateNegativeDeals()
|
| 252 |
if similarItem['in_stock'] == 0 or similarItem['maxprice'] is None or similarItem['maxprice'] < similarItem['available_price']:
|
261 |
if similarItem['in_stock'] == 0 or similarItem['maxprice'] is None or similarItem['maxprice'] < similarItem['available_price'] or similarItem['_id'] in mc.get("negativeDeals"):
|
| 253 |
get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0 }})
|
262 |
get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0 }})
|
| 254 |
continue
|
263 |
continue
|
| 255 |
if similarItem['available_price'] < bestPrice:
|
264 |
if similarItem['available_price'] < bestPrice:
|
| 256 |
bestOne = similarItem
|
265 |
bestOne = similarItem
|
| 257 |
bestPrice = similarItem['available_price']
|
266 |
bestPrice = similarItem['available_price']
|