| Line 5... |
Line 5... |
| 5 |
from shop2020.clients.InventoryClient import InventoryClient
|
5 |
from shop2020.clients.InventoryClient import InventoryClient
|
| 6 |
from dtr.utils.utils import to_java_date
|
6 |
from dtr.utils.utils import to_java_date
|
| 7 |
from datetime import datetime, timedelta
|
7 |
from datetime import datetime, timedelta
|
| 8 |
import time
|
8 |
import time
|
| 9 |
import optparse
|
9 |
import optparse
|
| - |
|
10 |
from dtr.storage.MemCache import MemCache
|
| 10 |
|
11 |
|
| 11 |
parser = optparse.OptionParser()
|
12 |
parser = optparse.OptionParser()
|
| 12 |
parser.add_option("-H", "--host", dest="hostname",
|
13 |
parser.add_option("-H", "--host", dest="hostname",
|
| 13 |
default="localhost",
|
14 |
default="localhost",
|
| 14 |
type="string", help="The HOST where the DB server is running",
|
15 |
type="string", help="The HOST where the DB server is running",
|
| Line 17... |
Line 18... |
| 17 |
default="localhost",
|
18 |
default="localhost",
|
| 18 |
type="string", help="The HOST where the mongo server is running",
|
19 |
type="string", help="The HOST where the mongo server is running",
|
| 19 |
metavar="mongo_host")
|
20 |
metavar="mongo_host")
|
| 20 |
|
21 |
|
| 21 |
(options, args) = parser.parse_args()
|
22 |
(options, args) = parser.parse_args()
|
| - |
|
23 |
|
| - |
|
24 |
mc = MemCache(options.mongoHost)
|
| - |
|
25 |
|
| 22 |
DataService.initialize(db_hostname=options.hostname)
|
26 |
DataService.initialize(db_hostname=options.hostname)
|
| 23 |
|
27 |
|
| 24 |
con = None
|
28 |
con = None
|
| 25 |
SOURCE_MAP = {'AMAZON':1,'FLIPKART':2,'SNAPDEAL':3,'SAHOLIC':4}
|
29 |
SOURCE_MAP = {'AMAZON':1,'FLIPKART':2,'SNAPDEAL':3,'SAHOLIC':4}
|
| 26 |
DISCOUNT_TYPE = {'MRP':1,'DP':2}
|
30 |
DISCOUNT_TYPE = {'MRP':1,'DP':2}
|
| Line 255... |
Line 259... |
| 255 |
for sku in allItems:
|
259 |
for sku in allItems:
|
| 256 |
deal_item = list(get_mongo_connection().Catalog.Deals.find({'skuBundleId':sku['skuBundleId']}).sort('bestSellerPoints',pymongo.DESCENDING).limit(1))
|
260 |
deal_item = list(get_mongo_connection().Catalog.Deals.find({'skuBundleId':sku['skuBundleId']}).sort('bestSellerPoints',pymongo.DESCENDING).limit(1))
|
| 257 |
sku['catalogBestSellerPoints'] = deal_item[0]['bestSellerPoints']
|
261 |
sku['catalogBestSellerPoints'] = deal_item[0]['bestSellerPoints']
|
| 258 |
sku['totalPoints'] = sku['catalogBestSellerPoints'] + sku['nlcPoints']
|
262 |
sku['totalPoints'] = sku['catalogBestSellerPoints'] + sku['nlcPoints']
|
| 259 |
get_mongo_connection().Catalog.Deals.update({'_id':sku['_id']},{'$set':{'catalogBestSellerPoints':sku['catalogBestSellerPoints'],'totalPoints':sku['totalPoints']}},multi=False)
|
263 |
get_mongo_connection().Catalog.Deals.update({'_id':sku['_id']},{'$set':{'catalogBestSellerPoints':sku['catalogBestSellerPoints'],'totalPoints':sku['totalPoints']}},multi=False)
|
| - |
|
264 |
|
| 260 |
|
265 |
|
| - |
|
266 |
def populateNegativeDeals():
|
| - |
|
267 |
negativeDeals = get_mongo_connection().Catalog.NegativeDeals.find().distinct('sku')
|
| - |
|
268 |
mc.set("negative_deals", negativeDeals, 600)
|
| 261 |
|
269 |
|
| 262 |
def elimiateSimilarDeals():
|
270 |
def elimiateSimilarDeals():
|
| 263 |
allItems = get_mongo_connection().Catalog.Deals.find().distinct('skuBundleId')
|
271 |
allItems = get_mongo_connection().Catalog.Deals.find().distinct('skuBundleId')
|
| 264 |
for skuBundleId in allItems:
|
272 |
for skuBundleId in allItems:
|
| 265 |
print skuBundleId
|
273 |
print skuBundleId
|
| Line 267... |
Line 275... |
| 267 |
bestPrice = float("inf")
|
275 |
bestPrice = float("inf")
|
| 268 |
bestOne = None
|
276 |
bestOne = None
|
| 269 |
bestSellerPoints = 0
|
277 |
bestSellerPoints = 0
|
| 270 |
toUpdate = []
|
278 |
toUpdate = []
|
| 271 |
for similarItem in similarItems:
|
279 |
for similarItem in similarItems:
|
| - |
|
280 |
if mc.get("negativeDeals") is None:
|
| - |
|
281 |
populateNegativeDeals()
|
| 272 |
if similarItem['in_stock'] == 0 or similarItem['maxprice'] is None or similarItem['maxprice'] < similarItem['available_price']:
|
282 |
if similarItem['in_stock'] == 0 or similarItem['maxprice'] is None or similarItem['maxprice'] < similarItem['available_price'] or similarItem['_id'] in mc.get("negativeDeals"):
|
| 273 |
get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0 }})
|
283 |
get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0 }})
|
| 274 |
continue
|
284 |
continue
|
| 275 |
if similarItem['available_price'] < bestPrice:
|
285 |
if similarItem['available_price'] < bestPrice:
|
| 276 |
bestOne = similarItem
|
286 |
bestOne = similarItem
|
| 277 |
bestPrice = similarItem['available_price']
|
287 |
bestPrice = similarItem['available_price']
|