| 13755 |
kshitij.so |
1 |
import pymongo
|
|
|
2 |
from elixir import *
|
|
|
3 |
from shop2020.model.v1.catalog.impl import DataService
|
|
|
4 |
from shop2020.model.v1.catalog.impl.DataService import Item
|
|
|
5 |
from shop2020.clients.InventoryClient import InventoryClient
|
|
|
6 |
from dtr.utils.utils import to_java_date
|
|
|
7 |
from datetime import datetime, timedelta
|
|
|
8 |
import time
|
| 14258 |
kshitij.so |
9 |
import optparse
|
| 14325 |
kshitij.so |
10 |
from dtr.storage.MemCache import MemCache
|
| 16635 |
manish.sha |
11 |
import traceback
|
| 13755 |
kshitij.so |
12 |
|
| 14258 |
kshitij.so |
13 |
parser = optparse.OptionParser()
|
| 14263 |
kshitij.so |
14 |
parser.add_option("-H", "--host", dest="hostname",
|
| 14258 |
kshitij.so |
15 |
default="localhost",
|
|
|
16 |
type="string", help="The HOST where the DB server is running",
|
|
|
17 |
metavar="host")
|
|
|
18 |
parser.add_option("-m", "--m", dest="mongoHost",
|
|
|
19 |
default="localhost",
|
|
|
20 |
type="string", help="The HOST where the mongo server is running",
|
|
|
21 |
metavar="mongo_host")
|
| 13755 |
kshitij.so |
22 |
|
| 14258 |
kshitij.so |
23 |
(options, args) = parser.parse_args()
|
| 14325 |
kshitij.so |
24 |
|
|
|
25 |
mc = MemCache(options.mongoHost)
|
|
|
26 |
|
| 14258 |
kshitij.so |
27 |
DataService.initialize(db_hostname=options.hostname)
|
|
|
28 |
|
| 13755 |
kshitij.so |
29 |
con = None
|
| 16405 |
kshitij.so |
30 |
SOURCE_MAP = {'AMAZON':1,'FLIPKART':2,'SNAPDEAL':3,'SAHOLIC':4, 'SHOPCLUES.COM':5,'PAYTM.COM':6}
|
| 13755 |
kshitij.so |
31 |
DISCOUNT_TYPE = {'MRP':1,'DP':2}
|
|
|
32 |
LATEST_UPDATED_ITEMS = []
|
| 16253 |
kshitij.so |
33 |
STATUS_WEIGHTAGE = {1 : 1.0, 2 : 2.0, 3 : 1.0, 4 : 0.5}
|
| 13755 |
kshitij.so |
34 |
|
|
|
35 |
now = datetime.now()
|
|
|
36 |
|
|
|
37 |
class __SkuInfo:
|
|
|
38 |
|
|
|
39 |
def __init__(self, _id, skuBundleId, category_id, mrp, available_price, source_id, rank, maxNlc, minNlc, schemeAmount, minDiscount, \
|
| 16534 |
kshitij.so |
40 |
maxDiscount, discountType, dp, nlcPoints, status, in_stock, maxprice, brand, dealType, brand_id, manualDealThresholdPrice,\
|
| 16456 |
kshitij.so |
41 |
codAvailable,showDp,gross_price):
|
| 13755 |
kshitij.so |
42 |
self._id = _id
|
|
|
43 |
self.skuBundleId = skuBundleId
|
|
|
44 |
self.category_id = category_id
|
|
|
45 |
self.mrp = mrp
|
|
|
46 |
self.available_price = available_price
|
|
|
47 |
self.source_id = source_id
|
|
|
48 |
self.rank = rank
|
|
|
49 |
self.maxNlc = maxNlc
|
|
|
50 |
self.minNlc = minNlc
|
|
|
51 |
self.schemeAmount = schemeAmount
|
|
|
52 |
self.minDiscount = minDiscount
|
|
|
53 |
self.maxDiscount = maxDiscount
|
|
|
54 |
self.discountType = discountType
|
|
|
55 |
self.dp = dp
|
|
|
56 |
self.nlcPoints = nlcPoints
|
| 13824 |
kshitij.so |
57 |
self.status = status
|
|
|
58 |
self.in_stock = in_stock
|
|
|
59 |
self.maxprice = maxprice
|
| 14035 |
kshitij.so |
60 |
self.brand = brand
|
| 14306 |
kshitij.so |
61 |
self.dealType = dealType
|
| 15063 |
kshitij.so |
62 |
self.brand_id = brand_id
|
| 15271 |
kshitij.so |
63 |
self.manualDealThresholdPrice = manualDealThresholdPrice
|
| 16019 |
kshitij.so |
64 |
self.codAvailable = codAvailable
|
| 16253 |
kshitij.so |
65 |
self.showDp = showDp
|
| 16456 |
kshitij.so |
66 |
self.gross_price = gross_price
|
| 13755 |
kshitij.so |
67 |
|
|
|
68 |
|
| 14258 |
kshitij.so |
69 |
def get_mongo_connection(host=options.mongoHost, port=27017):
|
| 13755 |
kshitij.so |
70 |
global con
|
|
|
71 |
if con is None:
|
|
|
72 |
print "Establishing connection %s host and port %d" %(host,port)
|
|
|
73 |
try:
|
|
|
74 |
con = pymongo.MongoClient(host, port)
|
|
|
75 |
except Exception, e:
|
|
|
76 |
print e
|
|
|
77 |
return None
|
|
|
78 |
return con
|
|
|
79 |
|
|
|
80 |
def populateStuff():
|
|
|
81 |
print "Inside populate"
|
|
|
82 |
global LATEST_UPDATED_ITEMS
|
|
|
83 |
"""Fetch latest updated items across portals
|
|
|
84 |
and calculate max and min R-Nlc"""
|
|
|
85 |
offset= 0
|
|
|
86 |
while(True):
|
|
|
87 |
print "Fetching records offset %d and limit %d" %(offset,300)
|
|
|
88 |
topSkus = list(get_mongo_connection().Catalog.MasterData.find( {"$and":[{'updatedOn': { "$gt": to_java_date(now - timedelta(hours=4))} }, { 'source_id' : { "$in": SOURCE_MAP.values() } }] }).skip(offset).limit(300))
|
|
|
89 |
if len((topSkus)) == 0:
|
|
|
90 |
break
|
|
|
91 |
#topSkus = collection.find( {'_id':664})
|
|
|
92 |
for sku in topSkus:
|
| 13908 |
kshitij.so |
93 |
"""Fix this """
|
|
|
94 |
#TODO Compute deal flags else where.
|
| 13755 |
kshitij.so |
95 |
info = __SkuInfo(sku['_id'], sku['skuBundleId'], sku['category_id'], sku['mrp'], sku['available_price'], sku['source_id'], sku['rank'], None, None, 0.0, None, \
|
| 16534 |
kshitij.so |
96 |
None, None, None, None, sku['status'], sku['in_stock'],sku['maxPrice'],sku['brand'].strip().upper(), 0, sku['brand_id'], None, sku['codAvailable'], 0, sku['gross_price'])
|
| 15854 |
kshitij.so |
97 |
exceptionalNlc = list(get_mongo_connection().Catalog.ExceptionalNlc.find( {"$and" : [ {'skuBundleId':info.skuBundleId}, {'overrideNlc':1} ]} ))
|
| 13755 |
kshitij.so |
98 |
if len(exceptionalNlc) > 0:
|
|
|
99 |
"""Exceptional nlc found, no need to calculate max and min R-nlc"""
|
|
|
100 |
info.maxNlc = exceptionalNlc[0]['maxNlc']
|
|
|
101 |
info.minNlc = exceptionalNlc[0]['minNlc']
|
| 14842 |
kshitij.so |
102 |
if info.maxprice == 0:
|
|
|
103 |
info.maxprice = exceptionalNlc[0]['maxNlc']
|
| 13755 |
kshitij.so |
104 |
LATEST_UPDATED_ITEMS.append(info)
|
|
|
105 |
continue
|
|
|
106 |
|
| 15854 |
kshitij.so |
107 |
skuSchemeDetails = list(get_mongo_connection().Catalog.SkuSchemeDetails.find( {'skuBundleId':info.skuBundleId}))
|
| 13755 |
kshitij.so |
108 |
if len(skuSchemeDetails) > 0:
|
|
|
109 |
"""Sku scheme details, populate scheme amount (Recently added)"""
|
| 13824 |
kshitij.so |
110 |
|
|
|
111 |
#TODO Add start date and end date of scehems
|
|
|
112 |
|
| 13755 |
kshitij.so |
113 |
info.schemeAmount = float(skuSchemeDetails[0]['schemeAmount'])
|
|
|
114 |
|
| 15854 |
kshitij.so |
115 |
skuDealerPrices = list(get_mongo_connection().Catalog.SkuDealerPrices.find( {'skuBundleId':info.skuBundleId} ) )
|
| 13755 |
kshitij.so |
116 |
if len(skuDealerPrices) > 0:
|
|
|
117 |
info.dp = skuDealerPrices[0]['dp']
|
| 16253 |
kshitij.so |
118 |
info.showDp = skuDealerPrices[0]['showDp']
|
| 15854 |
kshitij.so |
119 |
skuDiscount = list(get_mongo_connection().Catalog.SkuDiscountInfo.find( {'skuBundleId':info.skuBundleId} ) )
|
| 13755 |
kshitij.so |
120 |
if len(skuDiscount) > 0:
|
|
|
121 |
"""Sku rule found, populate max , min Discount and discount type"""
|
|
|
122 |
info.maxDiscount = skuDiscount[0]['max_discount']
|
|
|
123 |
info.minDiscount = skuDiscount[0]['min_discount']
|
|
|
124 |
info.discountType = DISCOUNT_TYPE.get(skuDiscount[0]['discountType'].upper())
|
|
|
125 |
LATEST_UPDATED_ITEMS.append(info)
|
|
|
126 |
continue
|
|
|
127 |
|
| 14035 |
kshitij.so |
128 |
categoryDiscount = list(get_mongo_connection().Catalog.CategoryDiscount.find( {"$and" : [{'brand':sku['brand'].strip().upper()}, {'category_id':sku['category_id']} ]} ))
|
| 13755 |
kshitij.so |
129 |
if len(categoryDiscount) > 0:
|
|
|
130 |
info.maxDiscount = categoryDiscount[0]['max_discount']
|
|
|
131 |
info.minDiscount = categoryDiscount[0]['min_discount']
|
|
|
132 |
info.discountType = DISCOUNT_TYPE.get(categoryDiscount[0]['discountType'].upper())
|
|
|
133 |
|
|
|
134 |
LATEST_UPDATED_ITEMS.append(info)
|
|
|
135 |
offset = offset + 300
|
|
|
136 |
for lol in LATEST_UPDATED_ITEMS:
|
|
|
137 |
print lol.__dict__
|
|
|
138 |
|
|
|
139 |
|
|
|
140 |
def calculateNlc():
|
|
|
141 |
global LATEST_UPDATED_ITEMS
|
|
|
142 |
populated = 0
|
|
|
143 |
while(populated <= len(LATEST_UPDATED_ITEMS)):
|
|
|
144 |
inventory_client = InventoryClient().get_client()
|
|
|
145 |
for obj in LATEST_UPDATED_ITEMS[populated:300+populated]:
|
|
|
146 |
if obj.maxNlc > 0 and obj.minNlc > 0:
|
|
|
147 |
continue
|
|
|
148 |
saholic_sku = list(get_mongo_connection().Catalog.MasterData.find( {"$and":[{'skuBundleId': obj.skuBundleId}, { 'source_id' : SOURCE_MAP.get('SAHOLIC')}] }))
|
|
|
149 |
identifier = None
|
|
|
150 |
if len(saholic_sku) > 0:
|
|
|
151 |
identifier = saholic_sku[0]['identifier']
|
|
|
152 |
if obj.discountType == DISCOUNT_TYPE.get('MRP'):
|
|
|
153 |
if obj.mrp == 0:
|
|
|
154 |
"""Now mrp is zero, so we have to use saholic MRP"""
|
|
|
155 |
if identifier is not None:
|
|
|
156 |
it = Item.query.filter_by(catalog_item_id=identifier).first()
|
|
|
157 |
obj.mrp = it.mrp
|
|
|
158 |
if obj.mrp > 0:
|
| 14842 |
kshitij.so |
159 |
print obj._id
|
| 13755 |
kshitij.so |
160 |
obj.minNlc = obj.mrp - (obj.mrp * obj.maxDiscount/100) - obj.schemeAmount
|
| 13824 |
kshitij.so |
161 |
obj.maxNlc = obj.mrp - (obj.mrp * obj.minDiscount/100) - obj.schemeAmount
|
| 14842 |
kshitij.so |
162 |
if obj.maxprice == 0:
|
|
|
163 |
obj.maxprice = obj.maxNlc
|
| 13755 |
kshitij.so |
164 |
elif obj.discountType == DISCOUNT_TYPE.get('DP'):
|
|
|
165 |
if obj.dp == 0:
|
|
|
166 |
"""Now dp is zero, so we have to use saholic minimum dp for item"""
|
|
|
167 |
if identifier is not None:
|
|
|
168 |
it = Item.query.filter_by(catalog_item_id=identifier).first()
|
|
|
169 |
try:
|
|
|
170 |
vendorPricing = inventory_client.getAllItemPricing(it.id)
|
|
|
171 |
min_dp = min(pricing.dealerPrice for pricing in vendorPricing)
|
|
|
172 |
obj.dp = min_dp
|
| 16253 |
kshitij.so |
173 |
obj.showDp = 1
|
| 13755 |
kshitij.so |
174 |
except:
|
|
|
175 |
pass
|
|
|
176 |
if obj.dp > 0:
|
|
|
177 |
obj.minNlc = obj.dp - (obj.dp * obj.maxDiscount/100) - obj.schemeAmount
|
| 13824 |
kshitij.so |
178 |
obj.maxNlc = obj.dp - (obj.dp * obj.minDiscount/100) - obj.schemeAmount
|
| 14842 |
kshitij.so |
179 |
if obj.maxprice == 0:
|
|
|
180 |
obj.maxprice = obj.maxNlc
|
| 13755 |
kshitij.so |
181 |
else:
|
|
|
182 |
"""No rule found, use saholic min nlc as max and min R-Nlc"""
|
|
|
183 |
if identifier is not None:
|
|
|
184 |
it = Item.query.filter_by(catalog_item_id=identifier).first()
|
|
|
185 |
try:
|
|
|
186 |
vendorPricing = inventory_client.getAllItemPricing(it.id)
|
|
|
187 |
min_nlc = min(pricing.nlc for pricing in vendorPricing)
|
|
|
188 |
obj.maxNlc = min_nlc
|
| 13824 |
kshitij.so |
189 |
obj.minNlc = min_nlc
|
| 14842 |
kshitij.so |
190 |
if obj.maxprice == 0:
|
|
|
191 |
obj.maxprice = obj.maxNlc
|
| 13755 |
kshitij.so |
192 |
except:
|
|
|
193 |
pass
|
|
|
194 |
populated = populated + 300
|
|
|
195 |
time.sleep(10)
|
|
|
196 |
|
| 14306 |
kshitij.so |
197 |
def addManualDealsInfo():
|
|
|
198 |
for sku in LATEST_UPDATED_ITEMS:
|
|
|
199 |
manualDeal = list(get_mongo_connection().Catalog.ManualDeals.find({'startDate':{'$lte':to_java_date(datetime.now())},'endDate':{'$gte':to_java_date(datetime.now())},'source_id':sku.source_id, 'sku':sku._id}))
|
|
|
200 |
if len(manualDeal) > 0:
|
|
|
201 |
sku.dealType = manualDeal[0]['dealType']
|
| 14310 |
kshitij.so |
202 |
|
|
|
203 |
"""Remove deal flag from expired deals"""
|
| 14311 |
kshitij.so |
204 |
manualDeals = list(get_mongo_connection().Catalog.Deals.find({'dealType':1}))
|
| 14310 |
kshitij.so |
205 |
for manualDeal in manualDeals:
|
| 14389 |
kshitij.so |
206 |
d_manualDeal = list(get_mongo_connection().Catalog.ManualDeals.find({'startDate':{'$lte':to_java_date(datetime.now())},'endDate':{'$gte':to_java_date(datetime.now())},'source_id':manualDeal['source_id'], 'sku':manualDeal['_id']}))
|
|
|
207 |
if len(d_manualDeal) > 0:
|
| 14310 |
kshitij.so |
208 |
continue
|
|
|
209 |
else:
|
| 16507 |
kshitij.so |
210 |
get_mongo_connection().Catalog.Deals.update({'_id':manualDeal['_id']},{"$set":{'dealType':0}},upsert=False, multi=False)
|
| 14306 |
kshitij.so |
211 |
|
| 13755 |
kshitij.so |
212 |
def calculateNlcPoints():
|
|
|
213 |
global LATEST_UPDATED_ITEMS
|
| 14842 |
kshitij.so |
214 |
print "inside nlc oints"
|
| 13755 |
kshitij.so |
215 |
for sku in LATEST_UPDATED_ITEMS:
|
|
|
216 |
if sku.maxNlc and sku.minNlc:
|
| 14842 |
kshitij.so |
217 |
print sku._id
|
| 13824 |
kshitij.so |
218 |
|
|
|
219 |
"""Create map - TODO"""
|
|
|
220 |
|
|
|
221 |
if sku.status == 2:
|
|
|
222 |
eolWeight = .60
|
|
|
223 |
else:
|
|
|
224 |
eolWeight = 1.0
|
|
|
225 |
if sku.category_id == 3:
|
|
|
226 |
basePointPercentage = 5.0
|
|
|
227 |
maxNlcPoints = 200
|
|
|
228 |
elif sku.category_id == 5:
|
|
|
229 |
basePointPercentage = 8.0
|
|
|
230 |
maxNlcPoints = 150
|
|
|
231 |
else:
|
|
|
232 |
basePointPercentage = 10.0
|
|
|
233 |
maxNlcPoints = 150
|
| 14842 |
kshitij.so |
234 |
discFromMinNlc = float((sku.minNlc - sku.available_price))/sku.available_price *100
|
|
|
235 |
discFromMaxNlc = float((sku.maxNlc - sku.available_price))/sku.available_price *100
|
|
|
236 |
print discFromMinNlc
|
|
|
237 |
print discFromMaxNlc
|
| 13755 |
kshitij.so |
238 |
if discFromMinNlc > 0:
|
| 13824 |
kshitij.so |
239 |
nlcPoints = 100/basePointPercentage * discFromMinNlc
|
| 13755 |
kshitij.so |
240 |
elif discFromMinNlc < 0 and discFromMaxNlc > 0:
|
|
|
241 |
nlcPoints = 0
|
|
|
242 |
else:
|
| 13824 |
kshitij.so |
243 |
nlcPoints = 100/basePointPercentage * discFromMinNlc
|
|
|
244 |
if (min(nlcPoints,maxNlcPoints)) > 0:
|
|
|
245 |
sku.nlcPoints = (min(nlcPoints,maxNlcPoints)) * eolWeight
|
|
|
246 |
else:
|
|
|
247 |
sku.nlcPoints = (min(nlcPoints,maxNlcPoints))
|
| 13755 |
kshitij.so |
248 |
else:
|
|
|
249 |
sku.nlcPoints = 0
|
|
|
250 |
|
|
|
251 |
def commitData():
|
|
|
252 |
global LATEST_UPDATED_ITEMS
|
|
|
253 |
for sku in LATEST_UPDATED_ITEMS:
|
|
|
254 |
#get_mongo_connection().Catalog.Deals.update({'_id':sku._id},{'$set' : sku.__dict__},upsert=True,multi=True)
|
| 14020 |
amit.gupta |
255 |
get_mongo_connection().Catalog.Deals.update({'_id':sku._id},{"$set":sku.__dict__},upsert=True)
|
| 13755 |
kshitij.so |
256 |
|
|
|
257 |
|
|
|
258 |
def addBestSellerPoints():
|
|
|
259 |
allItems = list(get_mongo_connection().Catalog.Deals.find({}))
|
|
|
260 |
for sku in allItems:
|
| 13824 |
kshitij.so |
261 |
bestSellerPoints = list(get_mongo_connection().Catalog.BestSellerPoints.find( {"$and":[{'min_rank': { "$lte": sku['rank'] } }, {'max_rank': { "$gte": sku['rank'] } } , { 'category_id' : sku['category_id'] }, { 'source_id' : sku['source_id'] }] } ))
|
| 13755 |
kshitij.so |
262 |
if len(bestSellerPoints) > 0:
|
| 13824 |
kshitij.so |
263 |
print bestSellerPoints[0]['points']
|
|
|
264 |
if (bestSellerPoints[0]['points']) > 0:
|
| 16253 |
kshitij.so |
265 |
sku['bestSellerPoints'] = (bestSellerPoints[0]['points']) * bestSellerPoints[0]['weightage'] * STATUS_WEIGHTAGE.get(sku['status'])
|
| 13824 |
kshitij.so |
266 |
else:
|
|
|
267 |
sku['bestSellerPoints'] = (bestSellerPoints[0]['points'])
|
| 13755 |
kshitij.so |
268 |
else:
|
| 16253 |
kshitij.so |
269 |
sku['bestSellerPoints'] = -120
|
| 14114 |
kshitij.so |
270 |
#sku['totalPoints'] = sku['bestSellerPoints'] + sku['nlcPoints']
|
|
|
271 |
get_mongo_connection().Catalog.Deals.update({'_id':sku['_id']},{'$set':{'bestSellerPoints':sku['bestSellerPoints']}},multi=False)
|
|
|
272 |
|
| 14390 |
kshitij.so |
273 |
shortageSkus = get_mongo_connection().Catalog.MasterData.find({"$and":[{'is_shortage': 1 }, { 'source_id' : { "$in": SOURCE_MAP.values() } }] }).distinct('_id')
|
|
|
274 |
print "Shortage skus"
|
|
|
275 |
print shortageSkus
|
| 14388 |
kshitij.so |
276 |
|
| 14114 |
kshitij.so |
277 |
for sku in allItems:
|
|
|
278 |
deal_item = list(get_mongo_connection().Catalog.Deals.find({'skuBundleId':sku['skuBundleId']}).sort('bestSellerPoints',pymongo.DESCENDING).limit(1))
|
| 14142 |
kshitij.so |
279 |
sku['catalogBestSellerPoints'] = deal_item[0]['bestSellerPoints']
|
| 14388 |
kshitij.so |
280 |
shortagePoints = 50 if sku['_id'] in shortageSkus else 0
|
| 14391 |
kshitij.so |
281 |
print "Shortage points for ",sku['_id']
|
|
|
282 |
print shortagePoints
|
| 16635 |
manish.sha |
283 |
try:
|
|
|
284 |
sku['totalPoints'] = sku['catalogBestSellerPoints'] + sku['nlcPoints'] + shortagePoints + sku['dealPoints']
|
|
|
285 |
get_mongo_connection().Catalog.Deals.update({'_id':sku['_id']},{'$set':{'catalogBestSellerPoints':sku['catalogBestSellerPoints'],'totalPoints':sku['totalPoints']}},multi=False)
|
|
|
286 |
except:
|
| 16637 |
manish.sha |
287 |
print 'Error Comes for Sku Id :- ', sku['_id']
|
| 16635 |
manish.sha |
288 |
print traceback.print_exc()
|
| 15271 |
kshitij.so |
289 |
|
|
|
290 |
|
| 13755 |
kshitij.so |
291 |
|
| 14325 |
kshitij.so |
292 |
def populateNegativeDeals():
|
|
|
293 |
negativeDeals = get_mongo_connection().Catalog.NegativeDeals.find().distinct('sku')
|
|
|
294 |
mc.set("negative_deals", negativeDeals, 600)
|
|
|
295 |
|
| 13828 |
kshitij.so |
296 |
def elimiateSimilarDeals():
|
| 13912 |
kshitij.so |
297 |
allItems = get_mongo_connection().Catalog.Deals.find().distinct('skuBundleId')
|
|
|
298 |
for skuBundleId in allItems:
|
|
|
299 |
print skuBundleId
|
|
|
300 |
similarItems = list(get_mongo_connection().Catalog.Deals.find({'skuBundleId':skuBundleId}).sort([('available_price',pymongo.ASCENDING)]))
|
| 13828 |
kshitij.so |
301 |
bestPrice = float("inf")
|
|
|
302 |
bestOne = None
|
|
|
303 |
bestSellerPoints = 0
|
|
|
304 |
toUpdate = []
|
| 16019 |
kshitij.so |
305 |
prepaidBestPrice = float("inf")
|
|
|
306 |
prepaidBestOne = None
|
|
|
307 |
prepaidBestSellerPoints = 0
|
| 13828 |
kshitij.so |
308 |
for similarItem in similarItems:
|
| 16019 |
kshitij.so |
309 |
if similarItem['codAvailable'] ==1:
|
|
|
310 |
if mc.get("negative_deals") is None:
|
|
|
311 |
populateNegativeDeals()
|
| 16171 |
kshitij.so |
312 |
if similarItem['in_stock'] == 0 or similarItem['_id'] in mc.get("negative_deals"):
|
| 16019 |
kshitij.so |
313 |
get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0, 'prepaidDeal':0 }})
|
|
|
314 |
continue
|
|
|
315 |
if similarItem['source_id'] == SOURCE_MAP.get('SHOPCLUES.COM') and similarItem['rank']==0:
|
|
|
316 |
get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0,'prepaidDeal':0 }})
|
|
|
317 |
continue
|
|
|
318 |
if similarItem['available_price'] < bestPrice:
|
|
|
319 |
bestOne = similarItem
|
|
|
320 |
bestPrice = similarItem['available_price']
|
|
|
321 |
bestSellerPoints = similarItem['bestSellerPoints']
|
|
|
322 |
elif similarItem['available_price'] == bestPrice and bestSellerPoints < similarItem['bestSellerPoints']:
|
|
|
323 |
bestOne = similarItem
|
|
|
324 |
bestPrice = similarItem['available_price']
|
|
|
325 |
bestSellerPoints = similarItem['bestSellerPoints']
|
|
|
326 |
else:
|
|
|
327 |
pass
|
| 13828 |
kshitij.so |
328 |
else:
|
| 16019 |
kshitij.so |
329 |
if mc.get("negative_deals") is None:
|
|
|
330 |
populateNegativeDeals()
|
| 16171 |
kshitij.so |
331 |
if similarItem['in_stock'] == 0 or similarItem['_id'] in mc.get("negative_deals"):
|
| 16019 |
kshitij.so |
332 |
get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0, 'prepaidDeal':0 }})
|
|
|
333 |
continue
|
|
|
334 |
if similarItem['source_id'] == SOURCE_MAP.get('SHOPCLUES.COM') and similarItem['rank']==0:
|
|
|
335 |
get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0,'prepaidDeal':0 }})
|
|
|
336 |
continue
|
|
|
337 |
if similarItem['available_price'] < prepaidBestPrice:
|
|
|
338 |
prepaidBestOne = similarItem
|
|
|
339 |
prepaidBestPrice = similarItem['available_price']
|
|
|
340 |
prepaidBestSellerPoints = similarItem['bestSellerPoints']
|
|
|
341 |
elif similarItem['available_price'] == prepaidBestPrice and prepaidBestSellerPoints < similarItem['bestSellerPoints']:
|
|
|
342 |
prepaidBestOne = similarItem
|
|
|
343 |
prepaidBestPrice = similarItem['available_price']
|
|
|
344 |
prepaidBestSellerPoints = similarItem['bestSellerPoints']
|
|
|
345 |
else:
|
|
|
346 |
pass
|
| 16026 |
kshitij.so |
347 |
if bestOne is not None or prepaidBestOne is not None:
|
| 13828 |
kshitij.so |
348 |
for similarItem in similarItems:
|
|
|
349 |
toUpdate.append(similarItem['_id'])
|
| 16026 |
kshitij.so |
350 |
if bestOne is not None:
|
|
|
351 |
toUpdate.remove(bestOne['_id'])
|
|
|
352 |
get_mongo_connection().Catalog.Deals.update({ '_id' : bestOne['_id'] }, {'$set':{'showDeal':1,'prepaidDeal':0 }})
|
|
|
353 |
if prepaidBestOne is not None:
|
| 16071 |
kshitij.so |
354 |
if bestOne is not None:
|
|
|
355 |
if prepaidBestOne['available_price'] < bestOne['available_price']:
|
|
|
356 |
toUpdate.remove(prepaidBestOne['_id'])
|
|
|
357 |
get_mongo_connection().Catalog.Deals.update({ '_id' : prepaidBestOne['_id'] }, {'$set':{'showDeal':0,'prepaidDeal':1 }})
|
|
|
358 |
else:
|
|
|
359 |
toUpdate.remove(prepaidBestOne['_id'])
|
|
|
360 |
get_mongo_connection().Catalog.Deals.update({ '_id' : prepaidBestOne['_id'] }, {'$set':{'showDeal':0,'prepaidDeal':1 }})
|
| 13828 |
kshitij.so |
361 |
if len(toUpdate) > 0:
|
| 16019 |
kshitij.so |
362 |
get_mongo_connection().Catalog.Deals.update({ '_id' : { "$in": toUpdate } }, {'$set':{'showDeal':0,'prepaidDeal':0 }},upsert=False, multi=True)
|
| 13755 |
kshitij.so |
363 |
|
|
|
364 |
def main():
|
| 14263 |
kshitij.so |
365 |
try:
|
|
|
366 |
populateStuff()
|
|
|
367 |
calculateNlc()
|
| 14306 |
kshitij.so |
368 |
addManualDealsInfo()
|
| 14263 |
kshitij.so |
369 |
finally:
|
|
|
370 |
session.close()
|
| 13755 |
kshitij.so |
371 |
calculateNlcPoints()
|
|
|
372 |
commitData()
|
|
|
373 |
addBestSellerPoints()
|
| 13828 |
kshitij.so |
374 |
elimiateSimilarDeals()
|
| 13755 |
kshitij.so |
375 |
|
| 13828 |
kshitij.so |
376 |
|
| 13755 |
kshitij.so |
377 |
if __name__=='__main__':
|
| 14842 |
kshitij.so |
378 |
main()
|