| 14305 |
amit.gupta |
1 |
from bson.objectid import ObjectId
|
|
|
2 |
from datetime import datetime, timedelta
|
|
|
3 |
from dtr.config import PythonPropertyReader
|
| 16894 |
manish.sha |
4 |
from dtr.dao import FeaturedDeals, AppTransactions, AppOfferObj
|
| 14037 |
kshitij.so |
5 |
from dtr.storage import DataService
|
|
|
6 |
from dtr.storage.DataService import price_preferences, brand_preferences, \
|
| 16789 |
amit.gupta |
7 |
user_actions, Brands, app_offers, approved_app_transactions, user_app_cashbacks, \
|
| 17280 |
manish.sha |
8 |
user_app_installs, appmasters, notification_campaigns
|
| 16304 |
amit.gupta |
9 |
from dtr.storage.MemCache import MemCache
|
| 16789 |
amit.gupta |
10 |
from dtr.utils.MailSender import Email
|
|
|
11 |
from dtr.utils.utils import to_java_date, CB_PENDING, CB_APPROVED, CB_INIT, \
|
|
|
12 |
to_py_date, CB_REJECTED
|
| 16894 |
manish.sha |
13 |
from sqlalchemy.sql.expression import func, func, or_, desc, asc, case
|
| 14305 |
amit.gupta |
14 |
from elixir import *
|
|
|
15 |
from operator import itemgetter
|
| 16789 |
amit.gupta |
16 |
from pymongo.command_cursor import CommandCursor
|
| 14305 |
amit.gupta |
17 |
import pymongo
|
| 16398 |
amit.gupta |
18 |
import random
|
| 14322 |
kshitij.so |
19 |
import re
|
| 16789 |
amit.gupta |
20 |
import time
|
| 14791 |
kshitij.so |
21 |
import traceback
|
| 16894 |
manish.sha |
22 |
from itertools import groupby
|
| 17280 |
manish.sha |
23 |
import urllib
|
|
|
24 |
import urllib2
|
|
|
25 |
import json
|
| 17367 |
kshitij.so |
26 |
import collections
|
|
|
27 |
try:
|
|
|
28 |
import ordereddict
|
|
|
29 |
except:
|
|
|
30 |
pass
|
| 13572 |
kshitij.so |
31 |
|
|
|
32 |
con = None
|
|
|
33 |
|
| 14037 |
kshitij.so |
34 |
DataService.initialize(db_hostname="localhost")
|
| 16304 |
amit.gupta |
35 |
mc = MemCache("127.0.0.1")
|
| 14037 |
kshitij.so |
36 |
|
| 17035 |
kshitij.so |
37 |
SOURCE_MAP = {1:'AMAZON',2:'FLIPKART',3:'SNAPDEAL',4:'SAHOLIC',5:"SHOPCLUES.COM",6:"PAYTM.COM",7:"HOMESHOP18.COM"}
|
| 14482 |
kshitij.so |
38 |
|
| 15853 |
kshitij.so |
39 |
COLLECTION_MAP = {
|
|
|
40 |
'ExceptionalNlc':'skuBundleId',
|
|
|
41 |
'SkuDealerPrices':'skuBundleId',
|
|
|
42 |
'SkuDiscountInfo':'skuBundleId',
|
|
|
43 |
'SkuSchemeDetails':'skuBundleId',
|
| 17367 |
kshitij.so |
44 |
'DealPoints':'skuBundleId',
|
|
|
45 |
'FeaturedDeals': 'skuBundleId'
|
| 15853 |
kshitij.so |
46 |
}
|
|
|
47 |
|
| 13572 |
kshitij.so |
48 |
def get_mongo_connection(host='localhost', port=27017):
|
|
|
49 |
global con
|
|
|
50 |
if con is None:
|
|
|
51 |
print "Establishing connection %s host and port %d" %(host,port)
|
|
|
52 |
try:
|
|
|
53 |
con = pymongo.MongoClient(host, port)
|
|
|
54 |
except Exception, e:
|
|
|
55 |
print e
|
|
|
56 |
return None
|
|
|
57 |
return con
|
|
|
58 |
|
| 13907 |
kshitij.so |
59 |
def populateCashBack():
|
| 13921 |
kshitij.so |
60 |
print "Populating cashback"
|
|
|
61 |
cashBackMap = {}
|
|
|
62 |
itemCashBackMap = {}
|
| 13907 |
kshitij.so |
63 |
cashBack = list(get_mongo_connection().Catalog.CategoryCashBack.find())
|
|
|
64 |
for row in cashBack:
|
| 13970 |
kshitij.so |
65 |
temp_map = {}
|
|
|
66 |
temp_list = []
|
| 13907 |
kshitij.so |
67 |
if cashBackMap.has_key(row['source_id']):
|
|
|
68 |
arr = cashBackMap.get(row['source_id'])
|
|
|
69 |
for val in arr:
|
|
|
70 |
temp_list.append(val)
|
|
|
71 |
temp_map[row['category_id']] = row
|
|
|
72 |
temp_list.append(temp_map)
|
|
|
73 |
cashBackMap[row['source_id']] = temp_list
|
|
|
74 |
else:
|
|
|
75 |
temp_map[row['category_id']] = row
|
|
|
76 |
temp_list.append(temp_map)
|
|
|
77 |
cashBackMap[row['source_id']] = temp_list
|
| 13921 |
kshitij.so |
78 |
itemCashBack = list(get_mongo_connection().Catalog.ItemCashBack.find())
|
|
|
79 |
for row in itemCashBack:
|
|
|
80 |
if not itemCashBackMap.has_key(row['skuId']):
|
|
|
81 |
itemCashBackMap[row['skuId']] = row
|
| 14761 |
kshitij.so |
82 |
mc.set("item_cash_back", itemCashBackMap, 24 * 60 * 60)
|
|
|
83 |
mc.set("category_cash_back", cashBackMap, 24 * 60 * 60)
|
| 13907 |
kshitij.so |
84 |
|
| 13572 |
kshitij.so |
85 |
def addCategoryDiscount(data):
|
| 13970 |
kshitij.so |
86 |
collection = get_mongo_connection().Catalog.CategoryDiscount
|
| 13572 |
kshitij.so |
87 |
query = []
|
|
|
88 |
data['brand'] = data['brand'].strip().upper()
|
| 13970 |
kshitij.so |
89 |
data['discountType'] = data['discountType'].upper().strip()
|
| 13572 |
kshitij.so |
90 |
query.append({"brand":data['brand']})
|
|
|
91 |
query.append({"category_id":data['category_id']})
|
|
|
92 |
r = collection.find({"$and":query})
|
|
|
93 |
if r.count() > 0:
|
| 13639 |
kshitij.so |
94 |
return {0:"Brand & Category info already present."}
|
| 13572 |
kshitij.so |
95 |
else:
|
|
|
96 |
collection.insert(data)
|
| 13970 |
kshitij.so |
97 |
get_mongo_connection().Catalog.MasterData.update({'brand':data['brand'],'category_id':data['category_id']},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=True)
|
| 13639 |
kshitij.so |
98 |
return {1:"Data added successfully"}
|
| 13572 |
kshitij.so |
99 |
|
| 13970 |
kshitij.so |
100 |
def updateCategoryDiscount(data,_id):
|
|
|
101 |
try:
|
|
|
102 |
collection = get_mongo_connection().Catalog.CategoryDiscount
|
|
|
103 |
collection.update({'_id':ObjectId(_id)},{"$set":{'min_discount':data['min_discount'],'max_discount':data['max_discount'],'discountType':data['discountType'].upper().strip()}},upsert=False, multi = False)
|
|
|
104 |
get_mongo_connection().Catalog.MasterData.update({'brand':data['brand'],'category_id':data['category_id']},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=True)
|
|
|
105 |
return {1:"Data updated successfully"}
|
|
|
106 |
except:
|
|
|
107 |
return {0:"Data not updated."}
|
|
|
108 |
|
|
|
109 |
|
| 13572 |
kshitij.so |
110 |
def getAllCategoryDiscount():
|
|
|
111 |
data = []
|
| 13970 |
kshitij.so |
112 |
collection = get_mongo_connection().Catalog.CategoryDiscount
|
| 13572 |
kshitij.so |
113 |
cursor = collection.find()
|
|
|
114 |
for val in cursor:
|
|
|
115 |
data.append(val)
|
|
|
116 |
return data
|
|
|
117 |
|
| 14553 |
kshitij.so |
118 |
def __getBundledSkusfromSku(sku):
|
|
|
119 |
masterData = get_mongo_connection().Catalog.MasterData.find_one({"_id":sku},{"skuBundleId":1})
|
|
|
120 |
if masterData is not None:
|
|
|
121 |
return list(get_mongo_connection().Catalog.MasterData.find({"skuBundleId":masterData.get('skuBundleId')},{'_id':1,'skuBundleId':1}))
|
|
|
122 |
else:
|
|
|
123 |
return []
|
| 13572 |
kshitij.so |
124 |
|
| 15853 |
kshitij.so |
125 |
def addSchemeDetailsForSku(data):
|
|
|
126 |
collection = get_mongo_connection().Catalog.SkuSchemeDetails
|
|
|
127 |
result = collection.find_one({'skuBundleId':data['skuBundleId']})
|
|
|
128 |
if result is None:
|
| 14553 |
kshitij.so |
129 |
collection.insert(data)
|
| 15853 |
kshitij.so |
130 |
get_mongo_connection().Catalog.MasterData.update({'skuBundleId':data['skuBundleId']},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=True)
|
| 14553 |
kshitij.so |
131 |
return {1:"Data added successfully"}
|
| 15853 |
kshitij.so |
132 |
return {1:"BundleId info already present"}
|
|
|
133 |
|
| 14069 |
kshitij.so |
134 |
def getAllSkuWiseSchemeDetails(offset, limit):
|
| 13572 |
kshitij.so |
135 |
data = []
|
| 13970 |
kshitij.so |
136 |
collection = get_mongo_connection().Catalog.SkuSchemeDetails
|
| 14071 |
kshitij.so |
137 |
cursor = collection.find().skip(offset).limit(limit)
|
| 13572 |
kshitij.so |
138 |
for val in cursor:
|
| 15853 |
kshitij.so |
139 |
master = get_mongo_connection().Catalog.MasterData.find_one({'skuBundleId':val['skuBundleId']})
|
|
|
140 |
if master is not None:
|
|
|
141 |
val['brand'] = master['brand']
|
|
|
142 |
val['source_product_name'] = master['source_product_name']
|
| 14069 |
kshitij.so |
143 |
else:
|
|
|
144 |
val['brand'] = ""
|
|
|
145 |
val['source_product_name'] = ""
|
| 13572 |
kshitij.so |
146 |
data.append(val)
|
|
|
147 |
return data
|
|
|
148 |
|
| 15853 |
kshitij.so |
149 |
def addSkuDiscountInfo(data):
|
|
|
150 |
collection = get_mongo_connection().Catalog.SkuDiscountInfo
|
|
|
151 |
cursor = collection.find_one({"skuBundleId":data['skuBundleId']})
|
|
|
152 |
if cursor is not None:
|
|
|
153 |
return {0:"BundleId information already present."}
|
| 13572 |
kshitij.so |
154 |
else:
|
| 15853 |
kshitij.so |
155 |
collection.insert(data)
|
|
|
156 |
get_mongo_connection().Catalog.MasterData.update({'skuBundleId':data['skuBundleId']},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=True)
|
| 13639 |
kshitij.so |
157 |
return {1:"Data added successfully"}
|
| 13572 |
kshitij.so |
158 |
|
| 13970 |
kshitij.so |
159 |
def getallSkuDiscountInfo(offset, limit):
|
| 13572 |
kshitij.so |
160 |
data = []
|
| 13970 |
kshitij.so |
161 |
collection = get_mongo_connection().Catalog.SkuDiscountInfo
|
|
|
162 |
cursor = collection.find().skip(offset).limit(limit)
|
| 13572 |
kshitij.so |
163 |
for val in cursor:
|
| 15853 |
kshitij.so |
164 |
master = get_mongo_connection().Catalog.MasterData.find_one({'skuBundleId':val['skuBundleId']})
|
|
|
165 |
if master is not None:
|
|
|
166 |
val['brand'] = master['brand']
|
|
|
167 |
val['source_product_name'] = master['source_product_name']
|
| 13970 |
kshitij.so |
168 |
else:
|
|
|
169 |
val['brand'] = ""
|
|
|
170 |
val['source_product_name'] = ""
|
| 13572 |
kshitij.so |
171 |
data.append(val)
|
|
|
172 |
return data
|
|
|
173 |
|
| 13970 |
kshitij.so |
174 |
def updateSkuDiscount(data,_id):
|
|
|
175 |
try:
|
|
|
176 |
collection = get_mongo_connection().Catalog.SkuDiscountInfo
|
|
|
177 |
collection.update({'_id':ObjectId(_id)},{"$set":{'min_discount':data['min_discount'],'max_discount':data['max_discount'],'discountType':data['discountType'].upper().strip()}},upsert=False, multi = False)
|
| 15853 |
kshitij.so |
178 |
get_mongo_connection().Catalog.MasterData.update({'_id':data['skuBundleId']},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=True)
|
| 13970 |
kshitij.so |
179 |
return {1:"Data updated successfully"}
|
|
|
180 |
except:
|
|
|
181 |
return {0:"Data not updated."}
|
|
|
182 |
|
|
|
183 |
|
| 15853 |
kshitij.so |
184 |
def addExceptionalNlc(data):
|
|
|
185 |
collection = get_mongo_connection().Catalog.ExceptionalNlc
|
|
|
186 |
cursor = collection.find_one({"skuBundleId":data['skuBundleId']})
|
|
|
187 |
if cursor is not None:
|
|
|
188 |
return {0:"BundleId information already present."}
|
| 13572 |
kshitij.so |
189 |
else:
|
| 15853 |
kshitij.so |
190 |
collection.insert(data)
|
|
|
191 |
get_mongo_connection().Catalog.MasterData.update({'skuBundleId':data['skuBundleId']},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=True)
|
| 13639 |
kshitij.so |
192 |
return {1:"Data added successfully"}
|
| 13572 |
kshitij.so |
193 |
|
| 13970 |
kshitij.so |
194 |
def getAllExceptionlNlcItems(offset, limit):
|
| 13572 |
kshitij.so |
195 |
data = []
|
| 13970 |
kshitij.so |
196 |
collection = get_mongo_connection().Catalog.ExceptionalNlc
|
| 14071 |
kshitij.so |
197 |
cursor = collection.find().skip(offset).limit(limit)
|
| 13572 |
kshitij.so |
198 |
for val in cursor:
|
| 15853 |
kshitij.so |
199 |
master = get_mongo_connection().Catalog.MasterData.find_one({'skuBundleId':val['skuBundleId']})
|
|
|
200 |
if master is not None:
|
|
|
201 |
val['brand'] = master['brand']
|
|
|
202 |
val['source_product_name'] = master['source_product_name']
|
| 13970 |
kshitij.so |
203 |
else:
|
|
|
204 |
val['brand'] = ""
|
|
|
205 |
val['source_product_name'] = ""
|
| 13572 |
kshitij.so |
206 |
data.append(val)
|
|
|
207 |
return data
|
|
|
208 |
|
| 14005 |
amit.gupta |
209 |
def getMerchantOrdersByUser(userId, page=1, window=50, searchMap={}):
|
|
|
210 |
if searchMap is None:
|
|
|
211 |
searchMap = {}
|
| 13603 |
amit.gupta |
212 |
if page==None:
|
|
|
213 |
page = 1
|
|
|
214 |
|
|
|
215 |
if window==None:
|
|
|
216 |
window = 50
|
|
|
217 |
result = {}
|
| 13582 |
amit.gupta |
218 |
skip = (page-1)*window
|
| 14005 |
amit.gupta |
219 |
|
| 14353 |
amit.gupta |
220 |
if userId is not None:
|
|
|
221 |
searchMap['userId'] = userId
|
| 13603 |
amit.gupta |
222 |
collection = get_mongo_connection().Dtr.merchantOrder
|
| 14609 |
amit.gupta |
223 |
cursor = collection.find(searchMap).sort("orderId",-1)
|
| 13603 |
amit.gupta |
224 |
total_count = cursor.count()
|
|
|
225 |
pages = total_count/window + (0 if total_count%window==0 else 1)
|
|
|
226 |
print "total_count", total_count
|
|
|
227 |
if total_count > skip:
|
| 13999 |
amit.gupta |
228 |
cursor = cursor.skip(skip).limit(window)
|
| 13603 |
amit.gupta |
229 |
orders = []
|
|
|
230 |
for order in cursor:
|
| 14002 |
amit.gupta |
231 |
del(order["_id"])
|
|
|
232 |
orders.append(order)
|
| 13603 |
amit.gupta |
233 |
result['data'] = orders
|
|
|
234 |
result['window'] = window
|
|
|
235 |
result['totalCount'] = total_count
|
|
|
236 |
result['currCount'] = cursor.count()
|
|
|
237 |
result['totalPages'] = pages
|
|
|
238 |
result['currPage'] = page
|
|
|
239 |
return result
|
|
|
240 |
else:
|
|
|
241 |
return result
|
| 13630 |
kshitij.so |
242 |
|
| 13927 |
amit.gupta |
243 |
def getRefunds(userId, page=1, window=10):
|
|
|
244 |
if page==None:
|
|
|
245 |
page = 1
|
|
|
246 |
|
|
|
247 |
if window==None:
|
| 13995 |
amit.gupta |
248 |
window = 10
|
| 13927 |
amit.gupta |
249 |
result = {}
|
|
|
250 |
skip = (page-1)*window
|
| 16737 |
amit.gupta |
251 |
con = get_mongo_connection()
|
|
|
252 |
collection = con.Dtr.refund
|
|
|
253 |
user = con.Dtr.user
|
| 16754 |
amit.gupta |
254 |
credited = user.find_one({"userId":userId})
|
|
|
255 |
if credited:
|
|
|
256 |
credited = credited.get("credited")
|
|
|
257 |
else:
|
|
|
258 |
credited=0
|
|
|
259 |
|
| 13927 |
amit.gupta |
260 |
cursor = collection.find({"userId":userId})
|
|
|
261 |
total_count = cursor.count()
|
|
|
262 |
pages = total_count/window + (0 if total_count%window==0 else 1)
|
|
|
263 |
print "total_count", total_count
|
|
|
264 |
if total_count > skip:
|
| 14668 |
amit.gupta |
265 |
cursor = cursor.skip(skip).limit(window).sort([('batch',-1)])
|
| 13927 |
amit.gupta |
266 |
refunds = []
|
|
|
267 |
for refund in cursor:
|
|
|
268 |
del(refund["_id"])
|
|
|
269 |
refunds.append(refund)
|
| 16754 |
amit.gupta |
270 |
result['credited'] = credited
|
| 13927 |
amit.gupta |
271 |
result['data'] = refunds
|
|
|
272 |
result['window'] = window
|
|
|
273 |
result['totalCount'] = total_count
|
|
|
274 |
result['currCount'] = cursor.count()
|
|
|
275 |
result['totalPages'] = pages
|
|
|
276 |
result['currPage'] = page
|
|
|
277 |
return result
|
|
|
278 |
else:
|
|
|
279 |
return result
|
|
|
280 |
|
|
|
281 |
def getPendingRefunds(userId):
|
| 13991 |
amit.gupta |
282 |
print type(userId)
|
| 13927 |
amit.gupta |
283 |
result = get_mongo_connection().Dtr.merchantOrder\
|
|
|
284 |
.aggregate([
|
| 16398 |
amit.gupta |
285 |
{'$match':{'subOrders.cashBackStatus':CB_APPROVED, 'userId':userId}},
|
| 13927 |
amit.gupta |
286 |
{'$unwind':"$subOrders"},
|
| 16398 |
amit.gupta |
287 |
{'$match':{'subOrders.cashBackStatus':CB_APPROVED}},
|
| 13927 |
amit.gupta |
288 |
{
|
|
|
289 |
'$group':{
|
|
|
290 |
'_id':None,
|
|
|
291 |
'amount': { '$sum':'$subOrders.cashBackAmount'},
|
|
|
292 |
}
|
|
|
293 |
}
|
| 13987 |
amit.gupta |
294 |
])['result']
|
|
|
295 |
|
|
|
296 |
if len(result)>0:
|
|
|
297 |
result = result[0]
|
|
|
298 |
result.pop("_id")
|
|
|
299 |
else:
|
|
|
300 |
result={}
|
|
|
301 |
result['amount'] = 0.0
|
| 14305 |
amit.gupta |
302 |
result['nextCredit'] = datetime.strftime(next_weekday(datetime.now(), int(PythonPropertyReader.getConfig('CREDIT_DAY_OF_WEEK'))),"%Y-%m-%d %H:%M:%S")
|
| 13927 |
amit.gupta |
303 |
return result
|
| 14037 |
kshitij.so |
304 |
|
| 14671 |
amit.gupta |
305 |
def getPendingCashbacks(userId):
|
|
|
306 |
result = get_mongo_connection().Dtr.merchantOrder\
|
|
|
307 |
.aggregate([
|
| 16398 |
amit.gupta |
308 |
{'$match':{'subOrders.cashBackStatus':CB_PENDING, 'userId':userId}},
|
| 14671 |
amit.gupta |
309 |
{'$unwind':"$subOrders"},
|
| 16398 |
amit.gupta |
310 |
{'$match':{'subOrders.cashBackStatus':CB_PENDING}},
|
| 14671 |
amit.gupta |
311 |
{
|
|
|
312 |
'$group':{
|
|
|
313 |
'_id':None,
|
|
|
314 |
'amount': { '$sum':'$subOrders.cashBackAmount'},
|
|
|
315 |
}
|
|
|
316 |
}
|
|
|
317 |
])['result']
|
|
|
318 |
|
|
|
319 |
if len(result)>0:
|
|
|
320 |
result = result[0]
|
|
|
321 |
result.pop("_id")
|
|
|
322 |
else:
|
|
|
323 |
result={}
|
|
|
324 |
result['amount'] = 0.0
|
|
|
325 |
return result
|
|
|
326 |
|
| 17369 |
kshitij.so |
327 |
def __constructDummyDealObject(skuBundleId):
|
|
|
328 |
temp =[]
|
|
|
329 |
deals = get_mongo_connection().Catalog.Deals.find({"skuBundleId":skuBundleId,"$or":[{"showDeal":1}, {"prepaidDeal":1}]},{'_id':1,'category_id':1,'brand':1,'totalPoints':1,'bestSellerPoints':1,'nlcPoints':1,'rank':1,'available_price':1,'dealType':1,'source_id':1,'brand_id':1,'skuBundleId':1,'dp':1, 'showDp':1, 'gross_price':1})
|
|
|
330 |
for d in deals:
|
|
|
331 |
d['persPoints'] = 0
|
|
|
332 |
temp.append(d)
|
|
|
333 |
return temp
|
|
|
334 |
|
|
|
335 |
|
|
|
336 |
|
| 14037 |
kshitij.so |
337 |
def __populateCache(userId):
|
| 17369 |
kshitij.so |
338 |
try:
|
|
|
339 |
if mc.get("featured_deals") is None:
|
|
|
340 |
__populateFeaturedDeals()
|
|
|
341 |
featuredDeals = mc.get("featured_deals")
|
|
|
342 |
|
|
|
343 |
except Exception as e:
|
|
|
344 |
print traceback.print_exc()
|
| 17469 |
kshitij.so |
345 |
featuredDeals = {3:{},5:{},6:{}}
|
| 17369 |
kshitij.so |
346 |
print featuredDeals
|
|
|
347 |
|
|
|
348 |
fd_bundles = []
|
|
|
349 |
|
|
|
350 |
for catMap in featuredDeals.itervalues():
|
|
|
351 |
for fd_map in catMap.itervalues():
|
|
|
352 |
fd_bundles.append(fd_map.get('skuBundleId'))
|
|
|
353 |
|
| 14037 |
kshitij.so |
354 |
print "Populating memcache for userId",userId
|
|
|
355 |
outer_query = []
|
| 16067 |
kshitij.so |
356 |
outer_query.append({ "$or": [ { "showDeal": 1} , { "prepaidDeal": 1 } ] })
|
| 14037 |
kshitij.so |
357 |
query = {}
|
| 16170 |
kshitij.so |
358 |
query['$gt'] = -100
|
| 14037 |
kshitij.so |
359 |
outer_query.append({'totalPoints':query})
|
|
|
360 |
brandPrefMap = {}
|
|
|
361 |
pricePrefMap = {}
|
|
|
362 |
actionsMap = {}
|
|
|
363 |
brand_p = session.query(price_preferences).filter_by(user_id=userId).all()
|
|
|
364 |
for x in brand_p:
|
|
|
365 |
pricePrefMap[x.category_id] = [x.min_price,x.max_price]
|
|
|
366 |
for x in session.query(brand_preferences).filter_by(user_id=userId).all():
|
|
|
367 |
temp_map = {}
|
|
|
368 |
if brandPrefMap.has_key((x.brand).strip().upper()):
|
|
|
369 |
val = brandPrefMap.get((x.brand).strip().upper())
|
|
|
370 |
temp_map[x.category_id] = 1 if x.status == 'show' else 0
|
|
|
371 |
val.append(temp_map)
|
|
|
372 |
else:
|
|
|
373 |
temp = []
|
|
|
374 |
temp_map[x.category_id] = 1 if x.status == 'show' else 0
|
|
|
375 |
temp.append(temp_map)
|
|
|
376 |
brandPrefMap[(x.brand).strip().upper()] = temp
|
|
|
377 |
|
|
|
378 |
for x in session.query(user_actions).filter_by(user_id=userId).all():
|
|
|
379 |
actionsMap[x.store_product_id] = 1 if x.action == 'like' else 0
|
| 17367 |
kshitij.so |
380 |
all_deals = list(get_mongo_connection().Catalog.Deals.find({"$and":outer_query},{'_id':1,'category_id':1,'brand':1,'totalPoints':1,'bestSellerPoints':1,'nlcPoints':1,'rank':1,'available_price':1,'dealType':1,'source_id':1,'brand_id':1,'skuBundleId':1,'dp':1, 'showDp':1, 'gross_price':1}).sort([('totalPoints',pymongo.DESCENDING),('bestSellerPoints',pymongo.DESCENDING),('nlcPoints',pymongo.DESCENDING),('rank',pymongo.DESCENDING)]))
|
| 14037 |
kshitij.so |
381 |
mobile_deals = []
|
|
|
382 |
tablet_deals = []
|
| 17469 |
kshitij.so |
383 |
accessories_deals = []
|
| 14037 |
kshitij.so |
384 |
for deal in all_deals:
|
| 17369 |
kshitij.so |
385 |
|
| 17469 |
kshitij.so |
386 |
|
| 17369 |
kshitij.so |
387 |
try:
|
|
|
388 |
fd_bundles.remove(deal.get('skuBundleId'))
|
|
|
389 |
except:
|
|
|
390 |
pass
|
|
|
391 |
|
| 14037 |
kshitij.so |
392 |
if actionsMap.get(deal['_id']) == 0:
|
|
|
393 |
fav_weight =.25
|
|
|
394 |
elif actionsMap.get(deal['_id']) == 1:
|
|
|
395 |
fav_weight = 1.5
|
|
|
396 |
else:
|
|
|
397 |
fav_weight = 1
|
|
|
398 |
|
|
|
399 |
if brandPrefMap.get(deal['brand'].strip().upper()) is not None:
|
| 17469 |
kshitij.so |
400 |
|
| 14037 |
kshitij.so |
401 |
brand_weight = 1
|
|
|
402 |
for brandInfo in brandPrefMap.get(deal['brand'].strip().upper()):
|
|
|
403 |
if brandInfo.get(deal['category_id']) is not None:
|
|
|
404 |
if brandInfo.get(deal['category_id']) == 1:
|
| 14055 |
kshitij.so |
405 |
brand_weight = 2.0
|
| 14037 |
kshitij.so |
406 |
else:
|
|
|
407 |
brand_weight = 1
|
|
|
408 |
|
|
|
409 |
if pricePrefMap.get(deal['category_id']) is not None:
|
|
|
410 |
|
|
|
411 |
if deal['available_price'] >= pricePrefMap.get(deal['category_id'])[0] and deal['available_price'] <= pricePrefMap.get(deal['category_id'])[1]:
|
|
|
412 |
asp_weight = 1.5
|
|
|
413 |
elif deal['available_price'] >= pricePrefMap.get(deal['category_id'])[0] - 0.5 * pricePrefMap.get(deal['category_id'])[0] and deal['available_price'] <= pricePrefMap.get(deal['category_id'])[1] + 0.5 * pricePrefMap.get(deal['category_id'])[1]:
|
|
|
414 |
asp_weight = 1.2
|
|
|
415 |
else:
|
|
|
416 |
asp_weight = 1
|
|
|
417 |
else:
|
|
|
418 |
asp_weight = 1
|
|
|
419 |
|
|
|
420 |
persPoints = deal['totalPoints'] * fav_weight * brand_weight * asp_weight
|
|
|
421 |
deal['persPoints'] = persPoints
|
|
|
422 |
|
|
|
423 |
if deal['category_id'] ==3:
|
|
|
424 |
mobile_deals.append(deal)
|
|
|
425 |
elif deal['category_id'] ==5:
|
|
|
426 |
tablet_deals.append(deal)
|
| 17469 |
kshitij.so |
427 |
elif deal['category_id'] ==6:
|
|
|
428 |
accessories_deals.append(deal)
|
| 14037 |
kshitij.so |
429 |
else:
|
|
|
430 |
continue
|
|
|
431 |
|
| 14144 |
kshitij.so |
432 |
session.close()
|
| 17367 |
kshitij.so |
433 |
|
|
|
434 |
mobile_deals = sorted(mobile_deals, key = lambda x: (x['persPoints'],x['totalPoints'],x['bestSellerPoints'], x['nlcPoints'], x['rank']),reverse=True)
|
|
|
435 |
tablet_deals = sorted(tablet_deals, key = lambda x: (x['persPoints'],x['totalPoints'],x['bestSellerPoints'], x['nlcPoints'], x['rank']),reverse=True)
|
| 17469 |
kshitij.so |
436 |
accessories_deals = sorted(accessories_deals, key = lambda x: (x['persPoints'],x['totalPoints'],x['bestSellerPoints'], x['nlcPoints'], x['rank']),reverse=True)
|
| 17367 |
kshitij.so |
437 |
|
|
|
438 |
|
| 17369 |
kshitij.so |
439 |
if len(fd_bundles) > 0:
|
|
|
440 |
print fd_bundles
|
|
|
441 |
print "There is still bundle in feature deals with points less than -100.Lets add info"
|
|
|
442 |
for skuBundleId in fd_bundles:
|
|
|
443 |
dummyDealObjList = __constructDummyDealObject(skuBundleId)
|
|
|
444 |
for dummyDealObj in dummyDealObjList:
|
|
|
445 |
if dummyDealObj['category_id'] ==3:
|
|
|
446 |
mobile_deals.append(dummyDealObj)
|
|
|
447 |
elif dummyDealObj['category_id'] ==5:
|
|
|
448 |
tablet_deals.append(dummyDealObj)
|
| 17469 |
kshitij.so |
449 |
elif dummyDealObj['category_id'] ==6:
|
|
|
450 |
accessories_deals.append(dummyDealObj)
|
| 17369 |
kshitij.so |
451 |
else:
|
|
|
452 |
pass
|
|
|
453 |
|
| 17469 |
kshitij.so |
454 |
for super_category, categoryFeaturedDeals in featuredDeals.iteritems():
|
|
|
455 |
for val in categoryFeaturedDeals.itervalues():
|
|
|
456 |
dummyDealObjList = __constructDummyDealObject(val.get('skuBundleId'))
|
|
|
457 |
for dummyDealObj in dummyDealObjList:
|
|
|
458 |
if super_category == dummyDealObj['category_id']:
|
|
|
459 |
continue
|
|
|
460 |
|
|
|
461 |
if super_category ==3:
|
|
|
462 |
mobile_deals.append(dummyDealObj)
|
|
|
463 |
elif super_category ==5:
|
|
|
464 |
tablet_deals.append(dummyDealObj)
|
|
|
465 |
elif super_category ==6:
|
|
|
466 |
accessories_deals.append(dummyDealObj)
|
|
|
467 |
else:
|
|
|
468 |
pass
|
|
|
469 |
|
| 17367 |
kshitij.so |
470 |
sortedMapMobiles = {}
|
|
|
471 |
rankMapMobiles = {}
|
|
|
472 |
rankMobiles = 0
|
|
|
473 |
|
|
|
474 |
blockedRanksMobiles = []
|
|
|
475 |
blockedSkuBundlesMobiles = []
|
|
|
476 |
blockedInfoMobiles = {}
|
|
|
477 |
|
|
|
478 |
featuredDealsMobiles = featuredDeals.get(3)
|
|
|
479 |
|
|
|
480 |
for k, v in featuredDealsMobiles.iteritems():
|
| 17469 |
kshitij.so |
481 |
blockedRanksMobiles.append(k-1)
|
|
|
482 |
blockedSkuBundlesMobiles.append(v.get('skuBundleId'))
|
| 17367 |
kshitij.so |
483 |
|
|
|
484 |
print "Blocked ranks ", blockedRanksMobiles
|
|
|
485 |
print "Blocked bundles ", blockedSkuBundlesMobiles
|
|
|
486 |
|
|
|
487 |
for sorted_deal in mobile_deals:
|
| 17369 |
kshitij.so |
488 |
|
| 17367 |
kshitij.so |
489 |
while(True):
|
|
|
490 |
if rankMobiles in blockedRanksMobiles:
|
|
|
491 |
print "skipping rank ",rankMobiles
|
|
|
492 |
rankMobiles = rankMobiles +1
|
|
|
493 |
else:
|
|
|
494 |
break
|
|
|
495 |
|
|
|
496 |
if sorted_deal['skuBundleId'] in blockedSkuBundlesMobiles:
|
|
|
497 |
print "Yes sorted deal in blocked ",sorted_deal['skuBundleId']
|
|
|
498 |
if blockedInfoMobiles.has_key(sorted_deal['skuBundleId']):
|
|
|
499 |
blockedInfoMobiles.get(sorted_deal['skuBundleId']).append(sorted_deal)
|
|
|
500 |
else:
|
|
|
501 |
blockedInfoMobiles[sorted_deal['skuBundleId']] = [sorted_deal]
|
|
|
502 |
continue
|
|
|
503 |
|
|
|
504 |
if sortedMapMobiles.get(sorted_deal['skuBundleId']) is None:
|
|
|
505 |
sortedMapMobiles[sorted_deal['skuBundleId']] = {rankMobiles:[sorted_deal]}
|
|
|
506 |
rankMapMobiles[rankMobiles] = (sortedMapMobiles[sorted_deal['skuBundleId']].values())[0]
|
|
|
507 |
rankMobiles = rankMobiles +1
|
|
|
508 |
else:
|
|
|
509 |
for temp_list in sortedMapMobiles.get(sorted_deal['skuBundleId']).itervalues():
|
|
|
510 |
temp_list.append(sorted_deal)
|
|
|
511 |
rankMapMobiles[(sortedMapMobiles.get(sorted_deal['skuBundleId']).keys())[0]] = temp_list
|
|
|
512 |
|
|
|
513 |
print "Blocked info ", blockedInfoMobiles
|
|
|
514 |
|
|
|
515 |
for rank in blockedRanksMobiles:
|
|
|
516 |
print "Adding rank ",rank
|
| 17369 |
kshitij.so |
517 |
if blockedInfoMobiles.get((featuredDealsMobiles.get(rank+1)).get('skuBundleId')) is not None:
|
|
|
518 |
rankMapMobiles[rank] = blockedInfoMobiles.get((featuredDealsMobiles.get(rank+1)).get('skuBundleId'))
|
|
|
519 |
print rankMapMobiles[rank]
|
| 17367 |
kshitij.so |
520 |
|
|
|
521 |
|
|
|
522 |
sortedMapTablets = {}
|
|
|
523 |
rankMapTablets = {}
|
|
|
524 |
rankTablets = 0
|
|
|
525 |
|
|
|
526 |
blockedRanksTablets = []
|
|
|
527 |
blockedSkuBundlesTablets = []
|
|
|
528 |
blockedInfoTablets = {}
|
|
|
529 |
|
|
|
530 |
featuredDealsTablets = featuredDeals.get(5)
|
|
|
531 |
|
|
|
532 |
|
|
|
533 |
for k, v in featuredDealsTablets.iteritems():
|
| 17469 |
kshitij.so |
534 |
blockedRanksTablets.append(k-1)
|
|
|
535 |
blockedSkuBundlesTablets.append(v.get('skuBundleId'))
|
|
|
536 |
|
| 17367 |
kshitij.so |
537 |
print "Blocked ranks ", blockedRanksTablets
|
|
|
538 |
print "Blocked bundles ", blockedSkuBundlesTablets
|
|
|
539 |
|
|
|
540 |
for sorted_deal in tablet_deals:
|
|
|
541 |
while(True):
|
|
|
542 |
if rankTablets in blockedRanksTablets:
|
|
|
543 |
print "skipping rank ",rankTablets
|
|
|
544 |
rankTablets = rankTablets +1
|
|
|
545 |
else:
|
|
|
546 |
break
|
|
|
547 |
|
|
|
548 |
if sorted_deal['skuBundleId'] in blockedSkuBundlesTablets:
|
|
|
549 |
if blockedInfoTablets.has_key(sorted_deal['skuBundleId']):
|
|
|
550 |
blockedInfoTablets.get(sorted_deal['skuBundleId']).append(sorted_deal)
|
|
|
551 |
else:
|
|
|
552 |
blockedInfoTablets[sorted_deal['skuBundleId']] = [sorted_deal]
|
|
|
553 |
continue
|
|
|
554 |
|
|
|
555 |
if sortedMapTablets.get(sorted_deal['skuBundleId']) is None:
|
|
|
556 |
sortedMapTablets[sorted_deal['skuBundleId']] = {rankTablets:[sorted_deal]}
|
|
|
557 |
rankMapTablets[rankTablets] = (sortedMapTablets[sorted_deal['skuBundleId']].values())[0]
|
|
|
558 |
rankTablets = rankTablets +1
|
|
|
559 |
else:
|
|
|
560 |
for temp_list in sortedMapTablets.get(sorted_deal['skuBundleId']).itervalues():
|
|
|
561 |
temp_list.append(sorted_deal)
|
|
|
562 |
rankMapTablets[(sortedMapTablets.get(sorted_deal['skuBundleId']).keys())[0]] = temp_list
|
|
|
563 |
|
|
|
564 |
for rank in blockedRanksTablets:
|
|
|
565 |
print "Adding rank ",rank
|
| 17369 |
kshitij.so |
566 |
if blockedInfoTablets.get((featuredDealsTablets.get(rank+1)).get('skuBundleId')) is not None:
|
|
|
567 |
rankMapTablets[rank] = blockedInfoTablets.get((featuredDealsTablets.get(rank+1)).get('skuBundleId'))
|
|
|
568 |
print rankMapTablets[rank]
|
| 17469 |
kshitij.so |
569 |
|
| 17367 |
kshitij.so |
570 |
|
| 17469 |
kshitij.so |
571 |
sortedMapAccessories = {}
|
|
|
572 |
rankMapAccessories = {}
|
|
|
573 |
rankAccessories = 0
|
|
|
574 |
|
|
|
575 |
blockedRanksAccessories = []
|
|
|
576 |
blockedSkuBundlesAccessories = []
|
|
|
577 |
blockedInfoAccessories = {}
|
|
|
578 |
|
|
|
579 |
featuredDealsAccessories = featuredDeals.get(6)
|
|
|
580 |
|
|
|
581 |
for k, v in featuredDealsAccessories.iteritems():
|
|
|
582 |
blockedRanksAccessories.append(k-1)
|
|
|
583 |
blockedSkuBundlesAccessories.append(v.get('skuBundleId'))
|
|
|
584 |
|
|
|
585 |
print "Blocked ranks ", blockedRanksAccessories
|
|
|
586 |
print "Blocked bundles ", blockedSkuBundlesAccessories
|
|
|
587 |
|
|
|
588 |
for sorted_deal in accessories_deals:
|
|
|
589 |
|
|
|
590 |
while(True):
|
|
|
591 |
if rankAccessories in blockedRanksAccessories:
|
|
|
592 |
print "skipping rank ",rankAccessories
|
|
|
593 |
rankAccessories = rankAccessories +1
|
|
|
594 |
else:
|
|
|
595 |
break
|
|
|
596 |
|
|
|
597 |
if sorted_deal['skuBundleId'] in blockedSkuBundlesAccessories:
|
|
|
598 |
print "Yes sorted deal in blocked ",sorted_deal['skuBundleId']
|
|
|
599 |
if blockedInfoAccessories.has_key(sorted_deal['skuBundleId']):
|
|
|
600 |
blockedInfoAccessories.get(sorted_deal['skuBundleId']).append(sorted_deal)
|
|
|
601 |
else:
|
|
|
602 |
blockedInfoAccessories[sorted_deal['skuBundleId']] = [sorted_deal]
|
|
|
603 |
continue
|
|
|
604 |
|
|
|
605 |
if sortedMapAccessories.get(sorted_deal['skuBundleId']) is None:
|
|
|
606 |
sortedMapAccessories[sorted_deal['skuBundleId']] = {rankAccessories:[sorted_deal]}
|
|
|
607 |
rankMapAccessories[rankAccessories] = (sortedMapAccessories[sorted_deal['skuBundleId']].values())[0]
|
|
|
608 |
rankAccessories = rankAccessories +1
|
|
|
609 |
else:
|
|
|
610 |
for temp_list in sortedMapAccessories.get(sorted_deal['skuBundleId']).itervalues():
|
|
|
611 |
temp_list.append(sorted_deal)
|
|
|
612 |
rankMapAccessories[(sortedMapAccessories.get(sorted_deal['skuBundleId']).keys())[0]] = temp_list
|
|
|
613 |
|
|
|
614 |
print "Blocked info ", blockedInfoAccessories
|
|
|
615 |
|
|
|
616 |
for rank in blockedRanksAccessories:
|
|
|
617 |
print "Adding rank acc ",rank
|
|
|
618 |
if blockedInfoAccessories.get((featuredDealsAccessories.get(rank+1)).get('skuBundleId')) is not None:
|
|
|
619 |
rankMapAccessories[rank] = blockedInfoAccessories.get((featuredDealsAccessories.get(rank+1)).get('skuBundleId'))
|
|
|
620 |
print rankMapAccessories[rank]
|
|
|
621 |
|
|
|
622 |
print rankMapAccessories
|
|
|
623 |
|
|
|
624 |
mem_cache_val = {3:mobile_deals, 5:tablet_deals, 6: accessories_deals,"3_rankMap": rankMapMobiles,"5_rankMap": rankMapTablets,"6_rankMap": rankMapAccessories }
|
| 14037 |
kshitij.so |
625 |
mc.set(str(userId), mem_cache_val)
|
|
|
626 |
|
|
|
627 |
|
| 14531 |
kshitij.so |
628 |
def __populateFeaturedDeals():
|
| 17367 |
kshitij.so |
629 |
print "Populating featured deals....."
|
|
|
630 |
featuredDealsMobiles = {}
|
|
|
631 |
featuredDealsTablets = {}
|
| 17469 |
kshitij.so |
632 |
featuredDealsAccessories = {}
|
| 17367 |
kshitij.so |
633 |
activeFeaturedDeals = get_mongo_connection().Catalog.FeaturedDeals.find({'startDate':{'$lte':to_java_date(datetime.now())},'endDate':{'$gte':to_java_date(datetime.now())}}).sort([('rank',pymongo.DESCENDING)])
|
| 14531 |
kshitij.so |
634 |
for activeFeaturedDeal in activeFeaturedDeals:
|
| 17367 |
kshitij.so |
635 |
deals = get_mongo_connection().Catalog.Deals.find({"skuBundleId":activeFeaturedDeal.get('skuBundleId'),"$or":[{"showDeal":1}, {"prepaidDeal":1}]})
|
|
|
636 |
for deal in deals:
|
|
|
637 |
if deal.get('available_price') <= activeFeaturedDeal.get('thresholdPrice'):
|
| 17469 |
kshitij.so |
638 |
for category_id, rank in activeFeaturedDeal['otherInfo'].iteritems():
|
|
|
639 |
f_deal = {'skuBundleId':activeFeaturedDeal.get('skuBundleId'), 'thresholdPrice':activeFeaturedDeal.get('thresholdPrice'), 'rank':rank,'category_id':int(category_id),'totalPoints':activeFeaturedDeal.get('totalPoints')}
|
|
|
640 |
if f_deal['category_id'] == 3:
|
|
|
641 |
featuredDealsMobiles[rank] = f_deal
|
|
|
642 |
elif f_deal['category_id']==5:
|
|
|
643 |
featuredDealsTablets[rank] = f_deal
|
|
|
644 |
elif f_deal['category_id']==6:
|
|
|
645 |
featuredDealsAccessories[rank] = f_deal
|
| 17367 |
kshitij.so |
646 |
break
|
| 17469 |
kshitij.so |
647 |
|
|
|
648 |
# f_deal = {'skuBundleId':activeFeaturedDeal.get('skuBundleId'), 'thresholdPrice':activeFeaturedDeal.get('thresholdPrice'), 'rank':activeFeaturedDeal.get('rank'),'category_id':activeFeaturedDeal.get('category_id'),'totalPoints':activeFeaturedDeal.get('totalPoints')}
|
|
|
649 |
# if activeFeaturedDeal.get('category_id') == 3:
|
|
|
650 |
# featuredDealsMobiles[activeFeaturedDeal.get('rank')] = f_deal
|
|
|
651 |
# else:
|
|
|
652 |
# featuredDealsTablets[activeFeaturedDeal.get('rank')] = f_deal
|
|
|
653 |
# break
|
|
|
654 |
|
| 17367 |
kshitij.so |
655 |
|
| 17469 |
kshitij.so |
656 |
mc.set("featured_deals", {3:featuredDealsMobiles,5:featuredDealsTablets,6:featuredDealsAccessories}, 600)
|
| 17367 |
kshitij.so |
657 |
print mc.get("featured_deals")
|
| 14037 |
kshitij.so |
658 |
|
| 14791 |
kshitij.so |
659 |
def getNewDeals(userId, category_id, offset, limit, sort, direction, filterData=None):
|
| 17469 |
kshitij.so |
660 |
if mc.get("category_cash_back") is None or not bool(mc.get("category_cash_back")):
|
| 13921 |
kshitij.so |
661 |
populateCashBack()
|
| 14037 |
kshitij.so |
662 |
|
| 16079 |
kshitij.so |
663 |
dealsListMap = []
|
| 14037 |
kshitij.so |
664 |
user_specific_deals = mc.get(str(userId))
|
|
|
665 |
if user_specific_deals is None:
|
|
|
666 |
__populateCache(userId)
|
|
|
667 |
user_specific_deals = mc.get(str(userId))
|
| 14038 |
kshitij.so |
668 |
else:
|
|
|
669 |
print "Getting user deals from cache"
|
| 14037 |
kshitij.so |
670 |
category_specific_deals = user_specific_deals.get(category_id)
|
|
|
671 |
|
| 17367 |
kshitij.so |
672 |
insert_featured_deals = False
|
| 14037 |
kshitij.so |
673 |
if sort is None or direction is None:
|
| 17367 |
kshitij.so |
674 |
insert_featured_deals = True
|
|
|
675 |
rankMap = user_specific_deals.get(str(category_id)+"_rankMap")
|
| 14037 |
kshitij.so |
676 |
else:
|
|
|
677 |
if sort == "bestSellerPoints":
|
|
|
678 |
sorted_deals = sorted(category_specific_deals, key = lambda x: (x['bestSellerPoints'], x['rank'], x['nlcPoints']),reverse=True)
|
|
|
679 |
else:
|
|
|
680 |
if direction == -1:
|
|
|
681 |
rev = True
|
|
|
682 |
else:
|
|
|
683 |
rev = False
|
|
|
684 |
sorted_deals = sorted(category_specific_deals, key = lambda x: (x['available_price']),reverse=rev)
|
|
|
685 |
|
| 14791 |
kshitij.so |
686 |
|
|
|
687 |
print "============================"
|
| 17367 |
kshitij.so |
688 |
filtered_deals = []
|
| 14791 |
kshitij.so |
689 |
if filterData is not None:
|
|
|
690 |
try:
|
| 17367 |
kshitij.so |
691 |
filtered_deals = filterDeals(category_specific_deals, filterData)
|
| 14791 |
kshitij.so |
692 |
except:
|
| 16067 |
kshitij.so |
693 |
traceback.print_exc()
|
| 14791 |
kshitij.so |
694 |
|
| 17367 |
kshitij.so |
695 |
if not insert_featured_deals:
|
|
|
696 |
sortedMap = {}
|
|
|
697 |
rankMap = {}
|
|
|
698 |
rank = 0
|
|
|
699 |
for sorted_deal in sorted_deals:
|
|
|
700 |
|
|
|
701 |
if len(filtered_deals) > 0 and sorted_deal['skuBundleId'] not in filtered_deals:
|
|
|
702 |
continue
|
|
|
703 |
|
|
|
704 |
if sortedMap.get(sorted_deal['skuBundleId']) is None:
|
|
|
705 |
sortedMap[sorted_deal['skuBundleId']] = {rank:[sorted_deal]}
|
|
|
706 |
rankMap[rank] = (sortedMap[sorted_deal['skuBundleId']].values())[0]
|
|
|
707 |
rank = rank +1
|
|
|
708 |
else:
|
|
|
709 |
for temp_list in sortedMap.get(sorted_deal['skuBundleId']).itervalues():
|
|
|
710 |
temp_list.append(sorted_deal)
|
|
|
711 |
rankMap[(sortedMap.get(sorted_deal['skuBundleId']).keys())[0]] = temp_list
|
|
|
712 |
else:
|
|
|
713 |
filterMap = {}
|
|
|
714 |
rank = 0
|
|
|
715 |
if len(filtered_deals) > 0:
|
|
|
716 |
try:
|
|
|
717 |
od = collections.OrderedDict(sorted(rankMap.items()))
|
|
|
718 |
except:
|
|
|
719 |
od = ordereddict.OrderedDict(sorted(rankMap.items()))
|
|
|
720 |
for k, v in od.iteritems():
|
|
|
721 |
if v[0].get('skuBundleId') in filtered_deals:
|
|
|
722 |
filterMap[rank] = v
|
|
|
723 |
rank =rank+1
|
|
|
724 |
rankMap = filterMap
|
|
|
725 |
|
| 16067 |
kshitij.so |
726 |
for dealList in [rankMap.get(k, []) for k in range(offset, offset+limit)]:
|
| 16079 |
kshitij.so |
727 |
temp = []
|
| 17367 |
kshitij.so |
728 |
if dealList is None or len(dealList)==0:
|
| 17369 |
kshitij.so |
729 |
print "Empty deal;lisr"
|
| 17367 |
kshitij.so |
730 |
continue
|
| 16067 |
kshitij.so |
731 |
for d in dealList:
|
|
|
732 |
item = list(get_mongo_connection().Catalog.MasterData.find({'_id':d['_id']}))
|
| 16320 |
kshitij.so |
733 |
if len(item) ==0:
|
|
|
734 |
continue
|
| 16079 |
kshitij.so |
735 |
item[0]['persPoints'] = d['persPoints']
|
|
|
736 |
if d['dealType'] == 1 and d['source_id'] ==1:
|
| 16511 |
kshitij.so |
737 |
try:
|
|
|
738 |
manualDeal = list(get_mongo_connection().Catalog.ManualDeals.find({'sku':d['_id'],'startDate':{'$lte':to_java_date(datetime.now())},'endDate':{'$gte':to_java_date(datetime.now())}}))
|
|
|
739 |
item[0]['marketPlaceUrl'] = manualDeal[0]['dealUrl'].strip()
|
|
|
740 |
except:
|
|
|
741 |
pass
|
| 16079 |
kshitij.so |
742 |
elif d['source_id'] ==3:
|
|
|
743 |
item[0]['marketPlaceUrl'] = item[0]['marketPlaceUrl']+'?supc='+item[0].get('identifier')
|
|
|
744 |
else:
|
|
|
745 |
pass
|
|
|
746 |
try:
|
|
|
747 |
cashBack = getCashBack(item[0]['_id'], item[0]['source_id'], item[0]['category_id'])
|
|
|
748 |
if not cashBack or cashBack.get('cash_back_status')!=1:
|
| 14037 |
kshitij.so |
749 |
item[0]['cash_back_type'] = 0
|
|
|
750 |
item[0]['cash_back'] = 0
|
| 16079 |
kshitij.so |
751 |
else:
|
| 17180 |
kshitij.so |
752 |
if cashBack.get('maxCashBack') is not None:
|
|
|
753 |
|
|
|
754 |
if cashBack.get('cash_back_type') ==1 and (float(cashBack.get('cash_back'))*item[0]['available_price'])/100 > cashBack.get('maxCashBack'):
|
|
|
755 |
cashBack['cash_back_type'] = 2
|
|
|
756 |
cashBack['cash_back'] = cashBack['maxCashBack']
|
|
|
757 |
elif cashBack.get('cash_back_type') ==2 and cashBack.get('cash_back') > cashBack.get('maxCashBack'):
|
|
|
758 |
cashBack['cash_back'] = cashBack['maxCashBack']
|
|
|
759 |
|
| 16079 |
kshitij.so |
760 |
item[0]['cash_back_type'] = int(cashBack['cash_back_type'])
|
|
|
761 |
item[0]['cash_back'] = cashBack['cash_back']
|
|
|
762 |
except:
|
|
|
763 |
print "Error in adding cashback to deals"
|
|
|
764 |
item[0]['cash_back_type'] = 0
|
|
|
765 |
item[0]['cash_back'] = 0
|
| 16252 |
kshitij.so |
766 |
try:
|
|
|
767 |
item[0]['dp'] = d['dp']
|
|
|
768 |
item[0]['showDp'] = d['showDp']
|
|
|
769 |
except:
|
|
|
770 |
item[0]['dp'] = 0.0
|
|
|
771 |
item[0]['showDp'] = 0
|
| 16483 |
kshitij.so |
772 |
try:
|
|
|
773 |
item[0]['thumbnail'] = item[0]['thumbnail'].strip()
|
|
|
774 |
except:
|
| 17115 |
manish.sha |
775 |
pass
|
| 16079 |
kshitij.so |
776 |
temp.append(item[0])
|
| 16125 |
kshitij.so |
777 |
if len(temp) > 1:
|
| 16126 |
kshitij.so |
778 |
temp = sorted(temp, key = lambda x: (x['available_price']),reverse=False)
|
| 16079 |
kshitij.so |
779 |
dealsListMap.append(temp)
|
|
|
780 |
return dealsListMap
|
| 14037 |
kshitij.so |
781 |
|
| 14791 |
kshitij.so |
782 |
def filterDeals(deals, filterData):
|
|
|
783 |
dealFiltered = []
|
|
|
784 |
brandsFiltered = []
|
|
|
785 |
filterArray = filterData.split('|')
|
|
|
786 |
for data in filterArray:
|
|
|
787 |
try:
|
|
|
788 |
filter, info = data.split(':')
|
|
|
789 |
except Exception as ex:
|
|
|
790 |
traceback.print_exc()
|
|
|
791 |
continue
|
|
|
792 |
if filter == 'dealFilter':
|
|
|
793 |
toFilter = info.split('^')
|
|
|
794 |
print "deal filter ",toFilter
|
|
|
795 |
if 'deals' in toFilter:
|
|
|
796 |
dealFiltered = deals
|
|
|
797 |
continue
|
|
|
798 |
for filterVal in toFilter:
|
|
|
799 |
if filterVal == 'dod':
|
|
|
800 |
for deal in deals:
|
|
|
801 |
if deal['dealType'] == 1:
|
|
|
802 |
dealFiltered.append(deal)
|
|
|
803 |
elif filter == 'brandFilter':
|
|
|
804 |
toFilter = info.split('^')
|
|
|
805 |
print "brand filter ",toFilter
|
|
|
806 |
if len(toFilter) == 0 or (len(toFilter)==1 and toFilter[0]==''):
|
|
|
807 |
brandsFiltered = deals
|
|
|
808 |
for deal in deals:
|
| 15151 |
kshitij.so |
809 |
if str(int(deal['brand_id'])) in toFilter:
|
| 14791 |
kshitij.so |
810 |
brandsFiltered.append(deal)
|
| 15040 |
kshitij.so |
811 |
if len(dealFiltered) == 0:
|
| 17367 |
kshitij.so |
812 |
return [trend['skuBundleId'] for trend in brandsFiltered]
|
|
|
813 |
return [i['skuBundleId'] for i in dealFiltered for j in brandsFiltered if i['_id']==j['_id']]
|
| 14791 |
kshitij.so |
814 |
|
|
|
815 |
|
| 14037 |
kshitij.so |
816 |
def getDeals(userId, category_id, offset, limit, sort, direction):
|
| 17469 |
kshitij.so |
817 |
if mc.get("category_cash_back") is None or not bool(mc.get("category_cash_back")):
|
| 14037 |
kshitij.so |
818 |
populateCashBack()
|
|
|
819 |
rank = 1
|
| 13771 |
kshitij.so |
820 |
deals = {}
|
| 13910 |
kshitij.so |
821 |
outer_query = []
|
|
|
822 |
outer_query.append({"showDeal":1})
|
|
|
823 |
query = {}
|
|
|
824 |
query['$gt'] = 0
|
|
|
825 |
outer_query.append({'totalPoints':query})
|
|
|
826 |
if category_id in (3,5):
|
|
|
827 |
outer_query.append({'category_id':category_id})
|
| 13803 |
kshitij.so |
828 |
if sort is None or direction is None:
|
|
|
829 |
direct = -1
|
| 13910 |
kshitij.so |
830 |
print outer_query
|
|
|
831 |
data = list(get_mongo_connection().Catalog.Deals.find({"$and":outer_query}).sort([('totalPoints',direct),('bestSellerPoints',direct),('nlcPoints',direct),('rank',direct)]).skip(offset).limit(limit))
|
| 13795 |
kshitij.so |
832 |
else:
|
| 13910 |
kshitij.so |
833 |
print outer_query
|
| 13803 |
kshitij.so |
834 |
direct = direction
|
| 13910 |
kshitij.so |
835 |
if sort == "bestSellerPoints":
|
|
|
836 |
print "yes,sorting by bestSellerPoints"
|
|
|
837 |
data = list(get_mongo_connection().Catalog.Deals.find({"$and":outer_query}).sort([('bestSellerPoints',direct),('rank',direct),('nlcPoints',direct)]).skip(offset).limit(limit))
|
|
|
838 |
else:
|
|
|
839 |
data = list(get_mongo_connection().Catalog.Deals.find({"$and":outer_query}).sort([(sort,direct)]).skip(offset).limit(limit))
|
| 13771 |
kshitij.so |
840 |
for d in data:
|
|
|
841 |
item = list(get_mongo_connection().Catalog.MasterData.find({'_id':d['_id']}))
|
|
|
842 |
if not deals.has_key(item[0]['identifier']):
|
| 13921 |
kshitij.so |
843 |
item[0]['dealRank'] = rank
|
|
|
844 |
try:
|
| 14761 |
kshitij.so |
845 |
cashBack = getCashBack(item[0]['_id'], item[0]['source_id'], item[0]['category_id'])
|
| 13921 |
kshitij.so |
846 |
if not cashBack or cashBack.get('cash_back_status')!=1:
|
| 13928 |
kshitij.so |
847 |
item[0]['cash_back_type'] = 0
|
|
|
848 |
item[0]['cash_back'] = 0
|
| 13921 |
kshitij.so |
849 |
else:
|
| 14766 |
kshitij.so |
850 |
item[0]['cash_back_type'] = int(cashBack['cash_back_type'])
|
| 13928 |
kshitij.so |
851 |
item[0]['cash_back'] = cashBack['cash_back']
|
| 13921 |
kshitij.so |
852 |
except:
|
|
|
853 |
print "Error in adding cashback to deals"
|
| 13928 |
kshitij.so |
854 |
item[0]['cash_back_type'] = 0
|
|
|
855 |
item[0]['cash_back'] = 0
|
| 13771 |
kshitij.so |
856 |
deals[item[0]['identifier']] = item[0]
|
| 13921 |
kshitij.so |
857 |
|
| 13771 |
kshitij.so |
858 |
rank +=1
|
| 13785 |
kshitij.so |
859 |
return sorted(deals.values(), key=itemgetter('dealRank'))
|
|
|
860 |
|
| 16222 |
kshitij.so |
861 |
def getItem(skuId,showDp=None):
|
| 16224 |
kshitij.so |
862 |
temp = []
|
| 17469 |
kshitij.so |
863 |
if mc.get("category_cash_back") is None or not bool(mc.get("category_cash_back")):
|
| 14113 |
kshitij.so |
864 |
populateCashBack()
|
| 13795 |
kshitij.so |
865 |
try:
|
| 16222 |
kshitij.so |
866 |
skuData = get_mongo_connection().Catalog.MasterData.find_one({'_id':int(skuId)})
|
|
|
867 |
if skuData is None:
|
|
|
868 |
raise
|
|
|
869 |
try:
|
|
|
870 |
cashBack = getCashBack(skuData['_id'], skuData['source_id'], skuData['category_id'])
|
|
|
871 |
if not cashBack or cashBack.get('cash_back_status')!=1:
|
|
|
872 |
skuData['cash_back_type'] = 0
|
|
|
873 |
skuData['cash_back'] = 0
|
|
|
874 |
else:
|
|
|
875 |
skuData['cash_back_type'] = cashBack['cash_back_type']
|
|
|
876 |
skuData['cash_back'] = cashBack['cash_back']
|
|
|
877 |
except:
|
|
|
878 |
print "Error in adding cashback to deals"
|
|
|
879 |
skuData['cash_back_type'] = 0
|
|
|
880 |
skuData['cash_back'] = 0
|
|
|
881 |
skuData['in_stock'] = int(skuData['in_stock'])
|
|
|
882 |
skuData['is_shortage'] = int(skuData['is_shortage'])
|
|
|
883 |
skuData['category_id'] = int(skuData['category_id'])
|
|
|
884 |
skuData['status'] = int(skuData['status'])
|
| 16483 |
kshitij.so |
885 |
try:
|
|
|
886 |
skuData['thumbnail'] = skuData['thumbnail'].strip()
|
|
|
887 |
except:
|
|
|
888 |
pass
|
| 16222 |
kshitij.so |
889 |
if showDp is not None:
|
|
|
890 |
dealerPrice = get_mongo_connection().Catalog.SkuDealerPrices.find_one({'skuBundleId':skuData['skuBundleId']})
|
|
|
891 |
skuData['dp'] = 0.0
|
|
|
892 |
skuData['showDp'] = 0
|
|
|
893 |
if dealerPrice is not None:
|
|
|
894 |
skuData['dp'] = dealerPrice['dp']
|
|
|
895 |
skuData['showDp'] = dealerPrice['showDp']
|
| 16224 |
kshitij.so |
896 |
temp.append(skuData)
|
|
|
897 |
return temp
|
| 13795 |
kshitij.so |
898 |
except:
|
| 16224 |
kshitij.so |
899 |
return []
|
| 13836 |
kshitij.so |
900 |
|
| 14761 |
kshitij.so |
901 |
def getCashBack(skuId, source_id, category_id):
|
| 17469 |
kshitij.so |
902 |
if mc.get("category_cash_back") is None or not bool(mc.get("category_cash_back")):
|
| 14761 |
kshitij.so |
903 |
populateCashBack()
|
|
|
904 |
itemCashBackMap = mc.get("item_cash_back")
|
| 13921 |
kshitij.so |
905 |
itemCashBack = itemCashBackMap.get(skuId)
|
|
|
906 |
if itemCashBack is not None:
|
|
|
907 |
return itemCashBack
|
| 14761 |
kshitij.so |
908 |
cashBackMap = mc.get("category_cash_back")
|
| 13921 |
kshitij.so |
909 |
sourceCashBack = cashBackMap.get(source_id)
|
|
|
910 |
if sourceCashBack is not None and len(sourceCashBack) > 0:
|
|
|
911 |
for cashBack in sourceCashBack:
|
|
|
912 |
if cashBack.get(category_id) is None:
|
|
|
913 |
continue
|
|
|
914 |
else:
|
|
|
915 |
return cashBack.get(category_id)
|
|
|
916 |
else:
|
|
|
917 |
return {}
|
| 16560 |
amit.gupta |
918 |
|
|
|
919 |
def getBundleBySourceSku(source_id, identifier):
|
| 17035 |
kshitij.so |
920 |
if source_id in (1,2,4,5,6,7):
|
| 16560 |
amit.gupta |
921 |
skuData = list(get_mongo_connection().Catalog.MasterData.find({'identifier':identifier.strip(), 'source_id':source_id}))
|
|
|
922 |
elif source_id == 3:
|
|
|
923 |
skuData = list(get_mongo_connection().Catalog.MasterData.find({'secondaryIdentifier':identifier.strip(), 'source_id':source_id}))
|
|
|
924 |
else:
|
|
|
925 |
return {}
|
|
|
926 |
|
|
|
927 |
if not skuData:
|
|
|
928 |
return {}
|
|
|
929 |
else:
|
| 16564 |
amit.gupta |
930 |
bundleId = skuData[0]["skuBundleId"]
|
| 17035 |
kshitij.so |
931 |
itemIds = list(get_mongo_connection().Catalog.MasterData.find({'skuBundleId':bundleId, 'in_stock':1, 'source_id':{"$in":[1,2,3,5,6,7]}},
|
| 16580 |
amit.gupta |
932 |
{"source_id":1, "available_price":1, "marketPlaceUrl":1, "gross_price":1, "codAvailable":1, "source_product_name":1, "offer":1, "coupon":1}))
|
| 16579 |
amit.gupta |
933 |
return {'products':itemIds}
|
| 16560 |
amit.gupta |
934 |
|
|
|
935 |
|
| 13921 |
kshitij.so |
936 |
|
| 15129 |
kshitij.so |
937 |
def getDealRank(identifier, source_id, userId):
|
| 17035 |
kshitij.so |
938 |
if source_id in (1,2,4,5,6,7):
|
| 15129 |
kshitij.so |
939 |
skuData = list(get_mongo_connection().Catalog.MasterData.find({'identifier':identifier.strip(), 'source_id':source_id}))
|
|
|
940 |
elif source_id == 3:
|
|
|
941 |
skuData = list(get_mongo_connection().Catalog.MasterData.find({'secondaryIdentifier':identifier.strip(), 'source_id':source_id}))
|
|
|
942 |
else:
|
| 16282 |
amit.gupta |
943 |
return {'rank':0, 'description':'Source not valid','maxNlc':None, 'minNlc':None,'status':None,'dp':None}
|
| 15349 |
kshitij.so |
944 |
if len(skuData) == 0:
|
| 16282 |
amit.gupta |
945 |
return {'rank':0, 'description':'No matching product identifier found','maxNlc':None, 'minNlc':None,'status':None,'dp':None}
|
| 15129 |
kshitij.so |
946 |
user_specific_deals = mc.get(str(userId))
|
|
|
947 |
if user_specific_deals is None:
|
|
|
948 |
__populateCache(userId)
|
|
|
949 |
user_specific_deals = mc.get(str(userId))
|
|
|
950 |
else:
|
|
|
951 |
print "Getting user deals from cache"
|
|
|
952 |
category_id = skuData[0]['category_id']
|
|
|
953 |
category_specific_deals = user_specific_deals.get(category_id)
|
| 16280 |
kshitij.so |
954 |
|
|
|
955 |
dealsData = get_mongo_connection().Catalog.Deals.find_one({'skuBundleId':skuData[0]['skuBundleId']})
|
|
|
956 |
if dealsData is None:
|
|
|
957 |
dealsData = {}
|
|
|
958 |
|
| 15129 |
kshitij.so |
959 |
if category_specific_deals is None or len(category_specific_deals) ==0:
|
| 16280 |
kshitij.so |
960 |
return {'rank':0,'description':'Category specific deals is empty','maxNlc':dealsData.get('maxNlc'),'minNlc':dealsData.get('minNlc'),'status':dealsData.get('status'),'dp':dealsData.get('dp')}
|
| 15129 |
kshitij.so |
961 |
sorted_deals = sorted(category_specific_deals, key = lambda x: (x['persPoints'],x['totalPoints'],x['bestSellerPoints'], x['nlcPoints'], x['rank']),reverse=True)
|
| 16168 |
kshitij.so |
962 |
sortedMap = {}
|
|
|
963 |
rankMap = {}
|
|
|
964 |
rank = 0
|
| 15129 |
kshitij.so |
965 |
for sorted_deal in sorted_deals:
|
| 16168 |
kshitij.so |
966 |
if sortedMap.get(sorted_deal['skuBundleId']) is None:
|
|
|
967 |
sortedMap[sorted_deal['skuBundleId']] = {rank:[sorted_deal]}
|
|
|
968 |
rankMap[rank] = (sortedMap[sorted_deal['skuBundleId']].values())[0]
|
|
|
969 |
rank = rank +1
|
|
|
970 |
else:
|
|
|
971 |
for temp_list in sortedMap.get(sorted_deal['skuBundleId']).itervalues():
|
|
|
972 |
temp_list.append(sorted_deal)
|
|
|
973 |
rankMap[(sortedMap.get(sorted_deal['skuBundleId']).keys())[0]] = temp_list
|
|
|
974 |
|
| 16187 |
kshitij.so |
975 |
for dealRank ,dealList in rankMap.iteritems():
|
| 16168 |
kshitij.so |
976 |
for d in dealList:
|
| 16186 |
kshitij.so |
977 |
if d['skuBundleId'] == skuData[0]['skuBundleId']:
|
| 16280 |
kshitij.so |
978 |
return {'rank':dealRank+1,'description':'Rank found','maxNlc':dealsData.get('maxNlc'),'minNlc':dealsData.get('minNlc'),'status':dealsData.get('status'),'dp':dealsData.get('dp')}
|
| 16168 |
kshitij.so |
979 |
|
| 16280 |
kshitij.so |
980 |
return {'rank':0,'description':'Rank not found','maxNlc':dealsData.get('maxNlc'),'minNlc':dealsData.get('minNlc'),'status':dealsData.get('status'),'dp':dealsData.get('dp')}
|
| 15129 |
kshitij.so |
981 |
|
|
|
982 |
|
| 13836 |
kshitij.so |
983 |
def getCashBackDetails(identifier, source_id):
|
| 17469 |
kshitij.so |
984 |
if mc.get("category_cash_back") is None or not bool(mc.get("category_cash_back")):
|
| 13921 |
kshitij.so |
985 |
populateCashBack()
|
| 13771 |
kshitij.so |
986 |
|
| 17035 |
kshitij.so |
987 |
if source_id in (1,2,4,5,6,7):
|
| 13839 |
kshitij.so |
988 |
skuData = list(get_mongo_connection().Catalog.MasterData.find({'identifier':identifier.strip(), 'source_id':source_id}))
|
| 13840 |
kshitij.so |
989 |
elif source_id == 3:
|
| 13839 |
kshitij.so |
990 |
skuData = list(get_mongo_connection().Catalog.MasterData.find({'secondaryIdentifier':identifier.strip(), 'source_id':source_id}))
|
| 13840 |
kshitij.so |
991 |
else:
|
|
|
992 |
return {}
|
| 13836 |
kshitij.so |
993 |
if len(skuData) > 0:
|
| 14761 |
kshitij.so |
994 |
itemCashBackMap = mc.get("item_cash_back")
|
| 13921 |
kshitij.so |
995 |
itemCashBack = itemCashBackMap.get(skuData[0]['_id'])
|
|
|
996 |
if itemCashBack is not None:
|
|
|
997 |
return itemCashBack
|
| 14761 |
kshitij.so |
998 |
cashBackMap = mc.get("category_cash_back")
|
| 13921 |
kshitij.so |
999 |
sourceCashBack = cashBackMap.get(source_id)
|
|
|
1000 |
if sourceCashBack is not None and len(sourceCashBack) > 0:
|
|
|
1001 |
for cashBack in sourceCashBack:
|
|
|
1002 |
if cashBack.get(skuData[0]['category_id']) is None:
|
|
|
1003 |
continue
|
|
|
1004 |
else:
|
|
|
1005 |
return cashBack.get(skuData[0]['category_id'])
|
| 13836 |
kshitij.so |
1006 |
else:
|
|
|
1007 |
return {}
|
|
|
1008 |
else:
|
|
|
1009 |
return {}
|
| 13986 |
amit.gupta |
1010 |
|
| 14398 |
amit.gupta |
1011 |
def getImgSrc(identifier, source_id):
|
|
|
1012 |
skuData = None
|
| 17035 |
kshitij.so |
1013 |
if source_id in (1,2,4,5,6,7):
|
| 14414 |
amit.gupta |
1014 |
skuData = get_mongo_connection().Catalog.MasterData.find_one({'identifier':identifier.strip(), 'source_id':source_id})
|
| 14398 |
amit.gupta |
1015 |
elif source_id == 3:
|
| 14414 |
amit.gupta |
1016 |
skuData = get_mongo_connection().Catalog.MasterData.find_one({'secondaryIdentifier':identifier.strip(), 'source_id':source_id})
|
| 14398 |
amit.gupta |
1017 |
if skuData is None:
|
|
|
1018 |
return {}
|
|
|
1019 |
else:
|
| 16483 |
kshitij.so |
1020 |
try:
|
|
|
1021 |
return {'thumbnail':skuData.get('thumbnail').strip()}
|
|
|
1022 |
except:
|
|
|
1023 |
return {'thumbnail':skuData.get('thumbnail')}
|
| 13986 |
amit.gupta |
1024 |
|
|
|
1025 |
def next_weekday(d, weekday):
|
|
|
1026 |
days_ahead = weekday - d.weekday()
|
|
|
1027 |
if days_ahead <= 0: # Target day already happened this week
|
|
|
1028 |
days_ahead += 7
|
|
|
1029 |
return d + timedelta(days_ahead)
|
|
|
1030 |
|
| 13771 |
kshitij.so |
1031 |
|
| 13970 |
kshitij.so |
1032 |
def getAllDealerPrices(offset, limit):
|
|
|
1033 |
data = []
|
|
|
1034 |
collection = get_mongo_connection().Catalog.SkuDealerPrices
|
|
|
1035 |
cursor = collection.find().skip(offset).limit(limit)
|
|
|
1036 |
for val in cursor:
|
| 15853 |
kshitij.so |
1037 |
master = get_mongo_connection().Catalog.MasterData.find_one({'skuBundleId':val['skuBundleId']})
|
|
|
1038 |
if master is not None:
|
|
|
1039 |
val['brand'] = master['brand']
|
|
|
1040 |
val['source_product_name'] = master['source_product_name']
|
| 13970 |
kshitij.so |
1041 |
else:
|
|
|
1042 |
val['brand'] = ""
|
|
|
1043 |
val['source_product_name'] = ""
|
| 16231 |
kshitij.so |
1044 |
val['showDp'] = int(val['showDp'])
|
| 13970 |
kshitij.so |
1045 |
data.append(val)
|
|
|
1046 |
return data
|
|
|
1047 |
|
| 15853 |
kshitij.so |
1048 |
def addSkuDealerPrice(data):
|
|
|
1049 |
collection = get_mongo_connection().Catalog.SkuDealerPrices
|
|
|
1050 |
cursor = collection.find_one({"skuBundleId":data['skuBundleId']})
|
|
|
1051 |
if cursor is not None:
|
|
|
1052 |
return {0:"BundleId information already present."}
|
| 13970 |
kshitij.so |
1053 |
else:
|
| 15853 |
kshitij.so |
1054 |
collection.insert(data)
|
|
|
1055 |
get_mongo_connection().Catalog.MasterData.update({'skuBundleId':data['skuBundleId']},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=True)
|
| 13970 |
kshitij.so |
1056 |
return {1:"Data added successfully"}
|
|
|
1057 |
|
|
|
1058 |
def updateSkuDealerPrice(data, _id):
|
|
|
1059 |
try:
|
|
|
1060 |
collection = get_mongo_connection().Catalog.SkuDealerPrices
|
|
|
1061 |
collection.update({'_id':ObjectId(_id)},{"$set":{'dp':data['dp']}},upsert=False, multi = False)
|
| 15853 |
kshitij.so |
1062 |
get_mongo_connection().Catalog.MasterData.update({'skuBundleId':data['skuBundleId']},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=True)
|
| 13970 |
kshitij.so |
1063 |
return {1:"Data updated successfully"}
|
|
|
1064 |
except:
|
|
|
1065 |
return {0:"Data not updated."}
|
|
|
1066 |
|
|
|
1067 |
def updateExceptionalNlc(data, _id):
|
|
|
1068 |
try:
|
|
|
1069 |
collection = get_mongo_connection().Catalog.ExceptionalNlc
|
|
|
1070 |
collection.update({'_id':ObjectId(_id)},{"$set":{'maxNlc':data['maxNlc'], 'minNlc':data['minNlc'], 'overrideNlc':data['overrideNlc']}},upsert=False, multi = False)
|
| 15853 |
kshitij.so |
1071 |
get_mongo_connection().Catalog.MasterData.update({'skuBundleId':data['skuBundleId']},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=True)
|
| 13970 |
kshitij.so |
1072 |
return {1:"Data updated successfully"}
|
|
|
1073 |
except:
|
|
|
1074 |
return {0:"Data not updated."}
|
|
|
1075 |
|
| 14041 |
kshitij.so |
1076 |
def resetCache(userId):
|
| 14043 |
kshitij.so |
1077 |
try:
|
|
|
1078 |
mc.delete(userId)
|
|
|
1079 |
return {1:'Cache cleared.'}
|
|
|
1080 |
except:
|
|
|
1081 |
return {0:'Unable to clear cache.'}
|
|
|
1082 |
|
| 15853 |
kshitij.so |
1083 |
def updateCollection(data):
|
| 14083 |
kshitij.so |
1084 |
print data
|
| 15853 |
kshitij.so |
1085 |
try:
|
|
|
1086 |
collection = get_mongo_connection().Catalog[data['class']]
|
|
|
1087 |
class_name = data.pop('class')
|
|
|
1088 |
_id = data.pop('oid')
|
|
|
1089 |
result = collection.update({'_id':ObjectId(_id)},{"$set":data},upsert=False, multi = False)
|
|
|
1090 |
if class_name != "Notifications":
|
|
|
1091 |
record = list(collection.find({'_id':ObjectId(_id)}))
|
|
|
1092 |
if class_name !="CategoryDiscount":
|
|
|
1093 |
if record[0].has_key('sku'):
|
|
|
1094 |
field = '_id'
|
|
|
1095 |
val = record[0]['sku']
|
| 14852 |
kshitij.so |
1096 |
else:
|
| 15853 |
kshitij.so |
1097 |
field = 'skuBundleId'
|
|
|
1098 |
val = record[0]['skuBundleId']
|
|
|
1099 |
get_mongo_connection().Catalog.MasterData.update({field:val},{"$set":{'updatedOn':to_java_date(datetime.now())}},upsert=False, multi = True)
|
|
|
1100 |
else:
|
|
|
1101 |
get_mongo_connection().Catalog.MasterData.update({'brand':re.compile(record[0]['brand'], re.IGNORECASE),'category_id':record[0]['category_id']}, \
|
|
|
1102 |
{"$set":{'updatedOn':to_java_date(datetime.now())}},upsert=False,multi=True)
|
| 16233 |
kshitij.so |
1103 |
if class_name =='SkuDealerPrices':
|
| 16237 |
kshitij.so |
1104 |
get_mongo_connection().Catalog.Deals.update({'skuBundleId':val},{"$set":data},upsert=False, multi=True)
|
| 15853 |
kshitij.so |
1105 |
return {1:"Data updated successfully"}
|
|
|
1106 |
except Exception as e:
|
|
|
1107 |
print e
|
|
|
1108 |
return {0:"Data not updated."}
|
| 14575 |
kshitij.so |
1109 |
|
| 14076 |
kshitij.so |
1110 |
|
| 14553 |
kshitij.so |
1111 |
def addNegativeDeals(data, multi):
|
|
|
1112 |
if multi !=1:
|
|
|
1113 |
collection = get_mongo_connection().Catalog.NegativeDeals
|
|
|
1114 |
cursor = collection.find({"sku":data['sku']})
|
|
|
1115 |
if cursor.count() > 0:
|
|
|
1116 |
return {0:"Sku information already present."}
|
|
|
1117 |
else:
|
|
|
1118 |
collection.insert(data)
|
|
|
1119 |
return {1:"Data added successfully"}
|
| 14481 |
kshitij.so |
1120 |
else:
|
| 14553 |
kshitij.so |
1121 |
skuIds = __getBundledSkusfromSku(data['sku'])
|
|
|
1122 |
for sku in skuIds:
|
|
|
1123 |
data['sku'] = sku.get('_id')
|
|
|
1124 |
collection = get_mongo_connection().Catalog.NegativeDeals
|
|
|
1125 |
cursor = collection.find({"sku":data['sku']})
|
|
|
1126 |
if cursor.count() > 0:
|
|
|
1127 |
continue
|
|
|
1128 |
else:
|
| 14558 |
kshitij.so |
1129 |
data.pop('_id',None)
|
| 14553 |
kshitij.so |
1130 |
collection.insert(data)
|
| 14481 |
kshitij.so |
1131 |
return {1:"Data added successfully"}
|
|
|
1132 |
|
|
|
1133 |
def getAllNegativeDeals(offset, limit):
|
|
|
1134 |
data = []
|
|
|
1135 |
collection = get_mongo_connection().Catalog.NegativeDeals
|
|
|
1136 |
cursor = collection.find().skip(offset).limit(limit)
|
|
|
1137 |
for val in cursor:
|
|
|
1138 |
master = list(get_mongo_connection().Catalog.MasterData.find({'_id':val['sku']}))
|
|
|
1139 |
if len(master) > 0:
|
|
|
1140 |
val['brand'] = master[0]['brand']
|
|
|
1141 |
val['source_product_name'] = master[0]['source_product_name']
|
|
|
1142 |
val['skuBundleId'] = master[0]['skuBundleId']
|
|
|
1143 |
else:
|
|
|
1144 |
val['brand'] = ""
|
|
|
1145 |
val['source_product_name'] = ""
|
|
|
1146 |
val['skuBundleId'] = ""
|
|
|
1147 |
data.append(val)
|
|
|
1148 |
return data
|
|
|
1149 |
|
|
|
1150 |
def getAllManualDeals(offset, limit):
|
|
|
1151 |
data = []
|
|
|
1152 |
collection = get_mongo_connection().Catalog.ManualDeals
|
| 15090 |
kshitij.so |
1153 |
cursor = collection.find().skip(offset).limit(limit)
|
| 14481 |
kshitij.so |
1154 |
for val in cursor:
|
|
|
1155 |
master = list(get_mongo_connection().Catalog.MasterData.find({'_id':val['sku']}))
|
|
|
1156 |
if len(master) > 0:
|
|
|
1157 |
val['brand'] = master[0]['brand']
|
|
|
1158 |
val['source_product_name'] = master[0]['source_product_name']
|
|
|
1159 |
val['skuBundleId'] = master[0]['skuBundleId']
|
|
|
1160 |
else:
|
|
|
1161 |
val['brand'] = ""
|
|
|
1162 |
val['source_product_name'] = ""
|
|
|
1163 |
val['skuBundleId'] = ""
|
|
|
1164 |
data.append(val)
|
|
|
1165 |
return data
|
| 14076 |
kshitij.so |
1166 |
|
| 14553 |
kshitij.so |
1167 |
def addManualDeal(data, multi):
|
|
|
1168 |
if multi !=1:
|
|
|
1169 |
collection = get_mongo_connection().Catalog.ManualDeals
|
| 15090 |
kshitij.so |
1170 |
cursor = collection.find({'sku':data['sku']})
|
| 14553 |
kshitij.so |
1171 |
if cursor.count() > 0:
|
|
|
1172 |
return {0:"Sku information already present."}
|
|
|
1173 |
else:
|
|
|
1174 |
collection.insert(data)
|
|
|
1175 |
get_mongo_connection().Catalog.MasterData.update({'_id':data['sku']},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=False)
|
|
|
1176 |
return {1:"Data added successfully"}
|
| 14481 |
kshitij.so |
1177 |
else:
|
| 14553 |
kshitij.so |
1178 |
skuIds = __getBundledSkusfromSku(data['sku'])
|
|
|
1179 |
for sku in skuIds:
|
|
|
1180 |
data['sku'] = sku.get('_id')
|
|
|
1181 |
collection = get_mongo_connection().Catalog.ManualDeals
|
| 15090 |
kshitij.so |
1182 |
cursor = collection.find({'sku':data['sku']})
|
| 14553 |
kshitij.so |
1183 |
if cursor.count() > 0:
|
|
|
1184 |
continue
|
|
|
1185 |
else:
|
| 14558 |
kshitij.so |
1186 |
data.pop('_id',None)
|
| 14553 |
kshitij.so |
1187 |
collection.insert(data)
|
|
|
1188 |
get_mongo_connection().Catalog.MasterData.update({'skuBundleId':sku.get('skuBundleId')},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=True)
|
| 14481 |
kshitij.so |
1189 |
return {1:"Data added successfully"}
|
| 14553 |
kshitij.so |
1190 |
|
| 14481 |
kshitij.so |
1191 |
def deleteDocument(data):
|
| 15853 |
kshitij.so |
1192 |
print "inside detete document"
|
| 14481 |
kshitij.so |
1193 |
print data
|
|
|
1194 |
try:
|
|
|
1195 |
collection = get_mongo_connection().Catalog[data['class']]
|
|
|
1196 |
class_name = data.pop('class')
|
|
|
1197 |
_id = data.pop('oid')
|
|
|
1198 |
record = list(collection.find({'_id':ObjectId(_id)}))
|
|
|
1199 |
collection.remove({'_id':ObjectId(_id)})
|
| 15075 |
kshitij.so |
1200 |
if class_name != "Notifications":
|
|
|
1201 |
if class_name !="CategoryDiscount":
|
| 15853 |
kshitij.so |
1202 |
print record[0]
|
|
|
1203 |
if record[0].has_key('sku'):
|
|
|
1204 |
field = '_id'
|
|
|
1205 |
val = record[0]['sku']
|
|
|
1206 |
else:
|
|
|
1207 |
field = 'skuBundleId'
|
|
|
1208 |
val = record[0]['skuBundleId']
|
|
|
1209 |
print "Updating master"
|
|
|
1210 |
print field
|
|
|
1211 |
print val
|
|
|
1212 |
get_mongo_connection().Catalog.MasterData.update({field:val},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=True)
|
| 15075 |
kshitij.so |
1213 |
else:
|
|
|
1214 |
get_mongo_connection().Catalog.MasterData.update({'brand':re.compile(record[0]['brand'], re.IGNORECASE),'category_id':record[0]['category_id']}, \
|
|
|
1215 |
{"$set":{'updatedOn':to_java_date(datetime.now())}},upsert=False,multi=True)
|
| 14481 |
kshitij.so |
1216 |
return {1:"Document deleted successfully"}
|
|
|
1217 |
except Exception as e:
|
|
|
1218 |
print e
|
|
|
1219 |
return {0:"Document not deleted."}
|
| 13970 |
kshitij.so |
1220 |
|
| 14482 |
kshitij.so |
1221 |
def searchMaster(offset, limit, search_term):
|
|
|
1222 |
data = []
|
| 14531 |
kshitij.so |
1223 |
if search_term is not None:
|
| 14551 |
kshitij.so |
1224 |
terms = search_term.split(' ')
|
|
|
1225 |
outer_query = []
|
|
|
1226 |
for term in terms:
|
|
|
1227 |
outer_query.append({"source_product_name":re.compile(term, re.IGNORECASE)})
|
| 14531 |
kshitij.so |
1228 |
try:
|
| 14551 |
kshitij.so |
1229 |
collection = get_mongo_connection().Catalog.MasterData.find({"$and":outer_query,'source_id':{'$in':SOURCE_MAP.keys()}}).skip(offset).limit(limit)
|
| 14531 |
kshitij.so |
1230 |
for record in collection:
|
|
|
1231 |
data.append(record)
|
|
|
1232 |
except:
|
|
|
1233 |
pass
|
|
|
1234 |
else:
|
|
|
1235 |
collection = get_mongo_connection().Catalog.MasterData.find({'source_id':{'$in':SOURCE_MAP.keys()}}).skip(offset).limit(limit)
|
| 14482 |
kshitij.so |
1236 |
for record in collection:
|
|
|
1237 |
data.append(record)
|
|
|
1238 |
return data
|
| 14481 |
kshitij.so |
1239 |
|
| 14495 |
kshitij.so |
1240 |
def getAllFeaturedDeals(offset, limit):
|
|
|
1241 |
data = []
|
|
|
1242 |
collection = get_mongo_connection().Catalog.FeaturedDeals
|
| 17367 |
kshitij.so |
1243 |
cursor = collection.find({})
|
| 14495 |
kshitij.so |
1244 |
for val in cursor:
|
| 17367 |
kshitij.so |
1245 |
master = list(get_mongo_connection().Catalog.MasterData.find({'skuBundleId':val['skuBundleId']}))
|
| 14495 |
kshitij.so |
1246 |
if len(master) > 0:
|
|
|
1247 |
val['brand'] = master[0]['brand']
|
|
|
1248 |
val['source_product_name'] = master[0]['source_product_name']
|
|
|
1249 |
val['skuBundleId'] = master[0]['skuBundleId']
|
|
|
1250 |
else:
|
|
|
1251 |
val['brand'] = ""
|
|
|
1252 |
val['source_product_name'] = ""
|
|
|
1253 |
val['skuBundleId'] = ""
|
|
|
1254 |
data.append(val)
|
|
|
1255 |
return data
|
|
|
1256 |
|
| 14553 |
kshitij.so |
1257 |
def addFeaturedDeal(data, multi):
|
| 17367 |
kshitij.so |
1258 |
collection = get_mongo_connection().Catalog.FeaturedDeals
|
|
|
1259 |
cursor = collection.find({'skuBundleId':data['skuBundleId']})
|
|
|
1260 |
master = get_mongo_connection().Catalog.MasterData.find_one({'skuBundleId':data['skuBundleId']})
|
|
|
1261 |
if master is None:
|
|
|
1262 |
return {0:"BundleId is wrong"}
|
| 17469 |
kshitij.so |
1263 |
otherInfoObj = data['otherInfo']
|
|
|
1264 |
toPop = []
|
|
|
1265 |
for x,y in otherInfoObj.iteritems():
|
|
|
1266 |
if y==0:
|
|
|
1267 |
toPop.append(x)
|
|
|
1268 |
|
|
|
1269 |
for popItem in toPop:
|
|
|
1270 |
otherInfoObj.pop(popItem)
|
|
|
1271 |
if len(otherInfoObj.keys())==0:
|
|
|
1272 |
return {0:"No rank info to add"}
|
|
|
1273 |
|
|
|
1274 |
for x,y in otherInfoObj.iteritems():
|
|
|
1275 |
exist = get_mongo_connection().Catalog.FeaturedDeals.find({'otherInfo.'+x:y})
|
|
|
1276 |
if exist.count() >0:
|
|
|
1277 |
return {0:"Rank already assigned bundleId %s"%(exist[0]['skuBundleId'])}
|
| 17367 |
kshitij.so |
1278 |
if cursor.count() > 0:
|
|
|
1279 |
return {0:"SkuBundleId information already present."}
|
| 14495 |
kshitij.so |
1280 |
else:
|
| 17367 |
kshitij.so |
1281 |
collection.insert(data)
|
| 14495 |
kshitij.so |
1282 |
return {1:"Data added successfully"}
|
|
|
1283 |
|
| 14499 |
kshitij.so |
1284 |
def searchCollection(class_name, sku, skuBundleId):
|
| 14497 |
kshitij.so |
1285 |
data = []
|
|
|
1286 |
collection = get_mongo_connection().Catalog[class_name]
|
| 15076 |
kshitij.so |
1287 |
if class_name == "Notifications":
|
|
|
1288 |
cursor = collection.find({'skuBundleId':skuBundleId})
|
|
|
1289 |
for val in cursor:
|
|
|
1290 |
master = list(get_mongo_connection().Catalog.MasterData.find({'skuBundleId':val['skuBundleId']}))
|
|
|
1291 |
if len(master) > 0:
|
|
|
1292 |
val['brand'] = master[0]['brand']
|
|
|
1293 |
val['model_name'] = master[0]['model_name']
|
|
|
1294 |
val['skuBundleId'] = master[0]['skuBundleId']
|
|
|
1295 |
else:
|
|
|
1296 |
val['brand'] = ""
|
|
|
1297 |
val['model_name'] = ""
|
|
|
1298 |
val['skuBundleId'] = val['skuBundleId']
|
|
|
1299 |
data.append(val)
|
| 15095 |
kshitij.so |
1300 |
return data
|
| 15853 |
kshitij.so |
1301 |
master = None
|
| 14499 |
kshitij.so |
1302 |
if sku is not None:
|
| 15853 |
kshitij.so |
1303 |
if COLLECTION_MAP.has_key(class_name):
|
|
|
1304 |
master = get_mongo_connection().Catalog.MasterData.find_one({'_id':sku})
|
|
|
1305 |
cursor = collection.find({'skuBundleId':master['skuBundleId']})
|
|
|
1306 |
else:
|
|
|
1307 |
cursor = collection.find({'sku':sku})
|
| 14499 |
kshitij.so |
1308 |
for val in cursor:
|
| 15853 |
kshitij.so |
1309 |
if master is None:
|
|
|
1310 |
master = get_mongo_connection().Catalog.MasterData.find_one({'_id':val['sku']})
|
|
|
1311 |
if master is not None:
|
|
|
1312 |
val['brand'] = master['brand']
|
|
|
1313 |
val['source_product_name'] = master['source_product_name']
|
|
|
1314 |
val['skuBundleId'] = master['skuBundleId']
|
| 14499 |
kshitij.so |
1315 |
else:
|
|
|
1316 |
val['brand'] = ""
|
|
|
1317 |
val['source_product_name'] = ""
|
|
|
1318 |
val['skuBundleId'] = ""
|
|
|
1319 |
data.append(val)
|
|
|
1320 |
return data
|
|
|
1321 |
else:
|
| 15853 |
kshitij.so |
1322 |
if not COLLECTION_MAP.has_key(class_name):
|
|
|
1323 |
skuIds = get_mongo_connection().Catalog.MasterData.find({'skuBundleId':skuBundleId}).distinct('_id')
|
|
|
1324 |
for sku in skuIds:
|
|
|
1325 |
cursor = collection.find({'sku':sku})
|
|
|
1326 |
for val in cursor:
|
|
|
1327 |
master = list(get_mongo_connection().Catalog.MasterData.find({'_id':val['sku']}))
|
|
|
1328 |
if len(master) > 0:
|
|
|
1329 |
val['brand'] = master[0]['brand']
|
|
|
1330 |
val['source_product_name'] = master[0]['source_product_name']
|
|
|
1331 |
val['skuBundleId'] = master[0]['skuBundleId']
|
|
|
1332 |
else:
|
|
|
1333 |
val['brand'] = ""
|
|
|
1334 |
val['source_product_name'] = ""
|
|
|
1335 |
val['skuBundleId'] = ""
|
|
|
1336 |
data.append(val)
|
|
|
1337 |
return data
|
|
|
1338 |
else:
|
|
|
1339 |
cursor = collection.find({'skuBundleId':skuBundleId})
|
| 14499 |
kshitij.so |
1340 |
for val in cursor:
|
| 15853 |
kshitij.so |
1341 |
master = list(get_mongo_connection().Catalog.MasterData.find({'skuBundleId':val['skuBundleId']}))
|
| 14499 |
kshitij.so |
1342 |
if len(master) > 0:
|
|
|
1343 |
val['brand'] = master[0]['brand']
|
|
|
1344 |
val['source_product_name'] = master[0]['source_product_name']
|
|
|
1345 |
else:
|
|
|
1346 |
val['brand'] = ""
|
|
|
1347 |
val['source_product_name'] = ""
|
|
|
1348 |
data.append(val)
|
| 15853 |
kshitij.so |
1349 |
return data
|
| 14495 |
kshitij.so |
1350 |
|
| 15074 |
kshitij.so |
1351 |
def __getBrandIdForBrand(brandName, category_id):
|
|
|
1352 |
brandInfo = Brands.query.filter(Brands.category_id==category_id).filter(Brands.name == brandName).all()
|
|
|
1353 |
if brandInfo is None or len(brandInfo)!=1:
|
|
|
1354 |
raise
|
|
|
1355 |
else:
|
|
|
1356 |
return brandInfo[0].id
|
|
|
1357 |
|
| 14588 |
kshitij.so |
1358 |
def addNewItem(data):
|
| 14594 |
kshitij.so |
1359 |
try:
|
|
|
1360 |
data['updatedOn'] = to_java_date(datetime.now())
|
|
|
1361 |
data['addedOn'] = to_java_date(datetime.now())
|
|
|
1362 |
data['priceUpdatedOn'] = to_java_date(datetime.now())
|
|
|
1363 |
max_id = list(get_mongo_connection().Catalog.MasterData.find().sort([('_id',pymongo.DESCENDING)]).limit(1))
|
|
|
1364 |
max_bundle = list(get_mongo_connection().Catalog.MasterData.find().sort([('skuBundleId',pymongo.DESCENDING)]).limit(1))
|
|
|
1365 |
data['_id'] = max_id[0]['_id'] + 1
|
|
|
1366 |
data['skuBundleId'] = max_bundle[0]['skuBundleId'] + 1
|
|
|
1367 |
data['identifier'] = str(data['identifier'])
|
|
|
1368 |
data['secondaryIdentifier'] = str(data['secondaryIdentifier'])
|
| 17115 |
manish.sha |
1369 |
data['model_name'] = str(data['model_name'])
|
| 15074 |
kshitij.so |
1370 |
data['brand_id'] = __getBrandIdForBrand(data['brand'], data['category_id'])
|
| 14594 |
kshitij.so |
1371 |
get_mongo_connection().Catalog.MasterData.insert(data)
|
|
|
1372 |
return {1:'Data added successfully'}
|
|
|
1373 |
except Exception as e:
|
|
|
1374 |
print e
|
|
|
1375 |
return {0:'Unable to add data.'}
|
| 15130 |
kshitij.so |
1376 |
finally:
|
|
|
1377 |
session.close()
|
| 14588 |
kshitij.so |
1378 |
|
|
|
1379 |
def addItemToExistingBundle(data):
|
|
|
1380 |
try:
|
|
|
1381 |
data['updatedOn'] = to_java_date(datetime.now())
|
|
|
1382 |
data['addedOn'] = to_java_date(datetime.now())
|
|
|
1383 |
data['priceUpdatedOn'] = to_java_date(datetime.now())
|
| 14593 |
kshitij.so |
1384 |
max_id = list(get_mongo_connection().Catalog.MasterData.find().sort([('_id',pymongo.DESCENDING)]).limit(1))
|
| 14590 |
kshitij.so |
1385 |
data['_id'] = max_id[0]['_id'] + 1
|
| 14594 |
kshitij.so |
1386 |
data['identifier'] = str(data['identifier'])
|
|
|
1387 |
data['secondaryIdentifier'] = str(data['secondaryIdentifier'])
|
| 17115 |
manish.sha |
1388 |
data['model_name'] = str(data['model_name'])
|
| 15074 |
kshitij.so |
1389 |
data['brand_id'] = __getBrandIdForBrand(data['brand'], data['category_id'])
|
| 14588 |
kshitij.so |
1390 |
get_mongo_connection().Catalog.MasterData.insert(data)
|
|
|
1391 |
return {1:'Data added successfully.'}
|
| 14594 |
kshitij.so |
1392 |
except Exception as e:
|
|
|
1393 |
print e
|
| 14588 |
kshitij.so |
1394 |
return {0:'Unable to add data.'}
|
| 15130 |
kshitij.so |
1395 |
finally:
|
|
|
1396 |
session.close()
|
| 14588 |
kshitij.so |
1397 |
|
|
|
1398 |
def updateMaster(data, multi):
|
| 15130 |
kshitij.so |
1399 |
try:
|
|
|
1400 |
print data
|
|
|
1401 |
if multi != 1:
|
|
|
1402 |
_id = data.pop('_id')
|
|
|
1403 |
skuBundleId = data.pop('skuBundleId')
|
|
|
1404 |
data['updatedOn'] = to_java_date(datetime.now())
|
|
|
1405 |
data['identifier'] = str(data['identifier'])
|
|
|
1406 |
data['secondaryIdentifier'] = str(data['secondaryIdentifier'])
|
| 17115 |
manish.sha |
1407 |
data['model_name'] = str(data['model_name'])
|
| 15130 |
kshitij.so |
1408 |
data['brand_id'] = __getBrandIdForBrand(data['brand'], data['category_id'])
|
|
|
1409 |
get_mongo_connection().Catalog.MasterData.update({'_id':_id},{"$set":data},upsert=False)
|
|
|
1410 |
return {1:'Data updated successfully.'}
|
|
|
1411 |
else:
|
|
|
1412 |
_id = data.pop('_id')
|
|
|
1413 |
skuBundleId = data.pop('skuBundleId')
|
|
|
1414 |
data['updatedOn'] = to_java_date(datetime.now())
|
|
|
1415 |
data['identifier'] = str(data['identifier'])
|
|
|
1416 |
data['secondaryIdentifier'] = str(data['secondaryIdentifier'])
|
|
|
1417 |
data['brand_id'] = __getBrandIdForBrand(data['brand'], data['category_id'])
|
| 17115 |
manish.sha |
1418 |
data['model_name'] = str(data['model_name'])
|
| 15130 |
kshitij.so |
1419 |
get_mongo_connection().Catalog.MasterData.update({'_id':_id},{"$set":data},upsert=False)
|
|
|
1420 |
similarItems = get_mongo_connection().Catalog.MasterData.find({'skuBundleId':skuBundleId})
|
|
|
1421 |
for item in similarItems:
|
|
|
1422 |
if item['_id'] == _id:
|
|
|
1423 |
continue
|
|
|
1424 |
item['updatedOn'] = to_java_date(datetime.now())
|
|
|
1425 |
item['thumbnail'] = data['thumbnail']
|
|
|
1426 |
item['category'] = data['category']
|
|
|
1427 |
item['category_id'] = data['category_id']
|
|
|
1428 |
item['tagline'] = data['tagline']
|
|
|
1429 |
item['is_shortage'] = data['is_shortage']
|
|
|
1430 |
item['mrp'] = data['mrp']
|
|
|
1431 |
item['status'] = data['status']
|
|
|
1432 |
item['maxPrice'] = data['maxPrice']
|
|
|
1433 |
item['brand_id'] = data['brand_id']
|
|
|
1434 |
similar_item_id = item.pop('_id')
|
|
|
1435 |
get_mongo_connection().Catalog.MasterData.update({'_id':similar_item_id},{"$set":item},upsert=False)
|
|
|
1436 |
return {1:'Data updated successfully.'}
|
|
|
1437 |
finally:
|
|
|
1438 |
session.close()
|
| 14619 |
kshitij.so |
1439 |
|
|
|
1440 |
def getLiveCricScore():
|
|
|
1441 |
return mc.get('liveScore')
|
| 14852 |
kshitij.so |
1442 |
|
|
|
1443 |
def addBundleToNotification(data):
|
|
|
1444 |
try:
|
| 15069 |
kshitij.so |
1445 |
collection = get_mongo_connection().Catalog.Notifications
|
| 14852 |
kshitij.so |
1446 |
cursor = collection.find({'skuBundleId':data['skuBundleId']})
|
|
|
1447 |
if cursor.count() > 0:
|
|
|
1448 |
return {0:"SkuBundleId information already present."}
|
|
|
1449 |
else:
|
|
|
1450 |
collection.insert(data)
|
|
|
1451 |
return {1:'Data updated successfully.'}
|
|
|
1452 |
except:
|
|
|
1453 |
return {0:'Unable to add data.'}
|
|
|
1454 |
|
|
|
1455 |
def getAllNotifications(offset, limit):
|
|
|
1456 |
data = []
|
| 15069 |
kshitij.so |
1457 |
collection = get_mongo_connection().Catalog.Notifications
|
| 16450 |
kshitij.so |
1458 |
cursor = collection.find().sort([('endDate',pymongo.DESCENDING)]).skip(offset).limit(limit)
|
| 14852 |
kshitij.so |
1459 |
for val in cursor:
|
| 15072 |
kshitij.so |
1460 |
master = list(get_mongo_connection().Catalog.MasterData.find({'skuBundleId':val['skuBundleId']}))
|
| 14852 |
kshitij.so |
1461 |
if len(master) > 0:
|
|
|
1462 |
val['brand'] = master[0]['brand']
|
| 15071 |
kshitij.so |
1463 |
val['model_name'] = master[0]['model_name']
|
| 14852 |
kshitij.so |
1464 |
val['skuBundleId'] = master[0]['skuBundleId']
|
|
|
1465 |
else:
|
|
|
1466 |
val['brand'] = ""
|
| 15071 |
kshitij.so |
1467 |
val['model_name'] = ""
|
|
|
1468 |
val['skuBundleId'] = val['skuBundleId']
|
| 14852 |
kshitij.so |
1469 |
data.append(val)
|
|
|
1470 |
return data
|
| 14997 |
kshitij.so |
1471 |
|
|
|
1472 |
def getBrandsForFilter(category_id):
|
|
|
1473 |
if mc.get("brandFilter") is None:
|
| 15095 |
kshitij.so |
1474 |
print "Populating brand data for category_id %d" %(category_id)
|
| 17469 |
kshitij.so |
1475 |
tabData, mobData, accData = [], [], []
|
| 14997 |
kshitij.so |
1476 |
mobileDeals = get_mongo_connection().Catalog.Deals.aggregate([
|
| 16170 |
kshitij.so |
1477 |
{"$match":{"category_id":3,"showDeal":1,"totalPoints":{"$gt":-100}}
|
| 14997 |
kshitij.so |
1478 |
},
|
|
|
1479 |
{"$group" :
|
|
|
1480 |
{'_id':{'brand_id':'$brand_id','brand':'$brand'},'count':{'$sum':1}}
|
|
|
1481 |
}
|
|
|
1482 |
])
|
| 14588 |
kshitij.so |
1483 |
|
| 14997 |
kshitij.so |
1484 |
tabletDeals = get_mongo_connection().Catalog.Deals.aggregate([
|
| 16170 |
kshitij.so |
1485 |
{"$match":{"category_id":5,"showDeal":1,"totalPoints":{"$gt":-100}}
|
| 14997 |
kshitij.so |
1486 |
},
|
|
|
1487 |
{"$group" :
|
|
|
1488 |
{'_id':{'brand_id':'$brand_id','brand':'$brand'},'count':{'$sum':1}}
|
|
|
1489 |
}
|
|
|
1490 |
])
|
|
|
1491 |
|
| 17469 |
kshitij.so |
1492 |
accessoriesDeals = get_mongo_connection().Catalog.Deals.aggregate([
|
|
|
1493 |
{"$match":{"category_id":6,"showDeal":1,"totalPoints":{"$gt":-100}}
|
|
|
1494 |
},
|
|
|
1495 |
{"$group" :
|
|
|
1496 |
{'_id':{'brand_id':'$brand_id','brand':'$brand'},'count':{'$sum':1}}
|
|
|
1497 |
}
|
|
|
1498 |
])
|
|
|
1499 |
|
| 14997 |
kshitij.so |
1500 |
allDeals = get_mongo_connection().Catalog.Deals.aggregate([
|
| 16170 |
kshitij.so |
1501 |
{"$match":{"showDeal":1,"totalPoints":{"$gt":-100}}
|
| 14997 |
kshitij.so |
1502 |
},
|
|
|
1503 |
{"$group" :
|
|
|
1504 |
{'_id':{'brand_id':'$brand_id','brand':'$brand'},'count':{'$sum':1}}
|
|
|
1505 |
}
|
|
|
1506 |
])
|
|
|
1507 |
#print mobileDeals
|
|
|
1508 |
#print "==========Mobile data ends=========="
|
|
|
1509 |
|
|
|
1510 |
#print tabletDeals
|
|
|
1511 |
#print "==========Tablet data ends=========="
|
|
|
1512 |
|
|
|
1513 |
#print allDeals
|
|
|
1514 |
#print "==========All deal data ends========="
|
|
|
1515 |
|
|
|
1516 |
for mobileDeal in mobileDeals['result']:
|
|
|
1517 |
if mobileDeal.get('_id').get('brand_id') != 0:
|
|
|
1518 |
tempMap = {}
|
|
|
1519 |
tempMap['brand'] = mobileDeal.get('_id').get('brand')
|
|
|
1520 |
tempMap['brand_id'] = mobileDeal.get('_id').get('brand_id')
|
|
|
1521 |
tempMap['count'] = mobileDeal.get('count')
|
|
|
1522 |
mobData.append(tempMap)
|
|
|
1523 |
|
|
|
1524 |
for tabletDeal in tabletDeals['result']:
|
|
|
1525 |
if tabletDeal.get('_id').get('brand_id') != 0:
|
|
|
1526 |
tempMap = {}
|
|
|
1527 |
tempMap['brand'] = tabletDeal.get('_id').get('brand')
|
|
|
1528 |
tempMap['brand_id'] = tabletDeal.get('_id').get('brand_id')
|
|
|
1529 |
tempMap['count'] = tabletDeal.get('count')
|
|
|
1530 |
tabData.append(tempMap)
|
|
|
1531 |
|
| 17469 |
kshitij.so |
1532 |
for accessoryDeal in accessoriesDeals['result']:
|
|
|
1533 |
if accessoryDeal.get('_id').get('brand_id') != 0:
|
|
|
1534 |
tempMap = {}
|
|
|
1535 |
tempMap['brand'] = accessoryDeal.get('_id').get('brand')
|
|
|
1536 |
tempMap['brand_id'] = accessoryDeal.get('_id').get('brand_id')
|
|
|
1537 |
tempMap['count'] = accessoryDeal.get('count')
|
|
|
1538 |
accData.append(tempMap)
|
| 14997 |
kshitij.so |
1539 |
|
| 17469 |
kshitij.so |
1540 |
|
| 14997 |
kshitij.so |
1541 |
brandMap = {}
|
|
|
1542 |
for allDeal in allDeals['result']:
|
|
|
1543 |
if allDeal.get('_id').get('brand_id') != 0:
|
|
|
1544 |
if brandMap.has_key(allDeal.get('_id').get('brand')):
|
| 15002 |
kshitij.so |
1545 |
brand_ids = brandMap.get(allDeal.get('_id').get('brand')).get('brand_ids')
|
| 14997 |
kshitij.so |
1546 |
brand_ids.append(allDeal.get('_id').get('brand_id'))
|
| 15003 |
kshitij.so |
1547 |
brandMap[allDeal.get('_id').get('brand')] = {'brand_ids':brand_ids,'count':brandMap.get(allDeal.get('_id').get('brand')).get('count') + allDeal.get('count')}
|
| 14997 |
kshitij.so |
1548 |
else:
|
|
|
1549 |
temp = []
|
|
|
1550 |
temp.append(allDeal.get('_id').get('brand_id'))
|
| 15002 |
kshitij.so |
1551 |
brandMap[allDeal.get('_id').get('brand')] = {'brand_ids':temp,'count':allDeal.get('count')}
|
| 14997 |
kshitij.so |
1552 |
|
| 17469 |
kshitij.so |
1553 |
mc.set("brandFilter",{0:brandMap, 3:mobData, 5:tabData, 6:accData}, 600)
|
| 14997 |
kshitij.so |
1554 |
|
| 15062 |
kshitij.so |
1555 |
return sorted(mc.get("brandFilter").get(category_id), key = lambda x: (-x['count'], x['brand']))
|
| 15375 |
kshitij.so |
1556 |
|
| 15459 |
kshitij.so |
1557 |
def getStaticDeals(offset, limit, category_id, direction):
|
| 15375 |
kshitij.so |
1558 |
user_specific_deals = mc.get("staticDeals")
|
|
|
1559 |
if user_specific_deals is None:
|
|
|
1560 |
__populateStaticDeals()
|
|
|
1561 |
user_specific_deals = mc.get("staticDeals")
|
| 15459 |
kshitij.so |
1562 |
rev = False
|
|
|
1563 |
if direction is None or direction == -1:
|
|
|
1564 |
rev=True
|
|
|
1565 |
return sorted((user_specific_deals.get(category_id))[offset:offset+limit],reverse=rev)
|
| 15375 |
kshitij.so |
1566 |
|
|
|
1567 |
def __populateStaticDeals():
|
|
|
1568 |
print "Populating memcache for static deals"
|
|
|
1569 |
outer_query = []
|
|
|
1570 |
outer_query.append({"showDeal":1})
|
|
|
1571 |
query = {}
|
| 16170 |
kshitij.so |
1572 |
query['$gt'] = -100
|
| 15375 |
kshitij.so |
1573 |
outer_query.append({'totalPoints':query})
|
|
|
1574 |
all_deals = list(get_mongo_connection().Catalog.Deals.find({"$and":outer_query},{'_id':1,'category_id':1,'brand':1,'totalPoints':1,'bestSellerPoints':1,'nlcPoints':1,'rank':1,'available_price':1,'dealType':1,'source_id':1,'brand_id':1,'skuBundleId':1}).sort([('totalPoints',pymongo.DESCENDING),('bestSellerPoints',pymongo.DESCENDING),('nlcPoints',pymongo.DESCENDING),('rank',pymongo.DESCENDING)]))
|
|
|
1575 |
mobile_deals = []
|
|
|
1576 |
tablet_deals = []
|
|
|
1577 |
for deal in all_deals:
|
|
|
1578 |
item = get_mongo_connection().Catalog.MasterData.find({'_id':deal['_id']})
|
|
|
1579 |
if deal['category_id'] ==3:
|
|
|
1580 |
mobile_deals.append(getItemObjForStaticDeals(item[0]))
|
|
|
1581 |
elif deal['category_id'] ==5:
|
|
|
1582 |
tablet_deals.append(getItemObjForStaticDeals(item[0]))
|
|
|
1583 |
else:
|
|
|
1584 |
continue
|
|
|
1585 |
|
|
|
1586 |
random.shuffle(mobile_deals,random.random)
|
|
|
1587 |
random.shuffle(tablet_deals,random.random)
|
|
|
1588 |
|
|
|
1589 |
mem_cache_val = {3:mobile_deals, 5:tablet_deals}
|
|
|
1590 |
mc.set("staticDeals", mem_cache_val, 3600)
|
|
|
1591 |
|
|
|
1592 |
def getItemObjForStaticDeals(item):
|
| 17469 |
kshitij.so |
1593 |
return {'marketPlaceUrl':item.get('marketPlaceUrl'),'available_price':int(item.get('available_price')),'source_product_name':item.get('source_product_name'),'thumbnail':item.get('thumbnail'),'source_id':int(item.get('source_id'))}
|
| 16300 |
manas |
1594 |
|
|
|
1595 |
def getItemByMerchantIdentifier(identifier, source_id):
|
|
|
1596 |
skuData = None
|
| 17035 |
kshitij.so |
1597 |
if source_id in (1,2,4,5,6,7):
|
| 16300 |
manas |
1598 |
skuData = get_mongo_connection().Catalog.MasterData.find_one({'identifier':identifier.strip(), 'source_id':source_id})
|
|
|
1599 |
elif source_id == 3:
|
|
|
1600 |
skuData = get_mongo_connection().Catalog.MasterData.find_one({'secondaryIdentifier':identifier.strip(), 'source_id':source_id})
|
|
|
1601 |
if skuData is None:
|
|
|
1602 |
return {}
|
|
|
1603 |
else:
|
|
|
1604 |
return skuData
|
| 15375 |
kshitij.so |
1605 |
|
| 16364 |
kshitij.so |
1606 |
def getDealsForNotification(skuBundleIds):
|
|
|
1607 |
bundles= [int(skuBundleId) for skuBundleId in skuBundleIds.split(',')]
|
|
|
1608 |
print bundles
|
| 16406 |
kshitij.so |
1609 |
dealsList = []
|
| 16364 |
kshitij.so |
1610 |
dealsListMap = []
|
| 16406 |
kshitij.so |
1611 |
for bundleId in bundles:
|
|
|
1612 |
outer_query = []
|
|
|
1613 |
outer_query.append({ "$or": [ { "showDeal": 1} , { "prepaidDeal": 1 } ] })
|
|
|
1614 |
outer_query.append({'skuBundleId':bundleId})
|
|
|
1615 |
deals = get_mongo_connection().Catalog.Deals.find({"$and":outer_query})
|
|
|
1616 |
for deal in deals:
|
|
|
1617 |
dealsList.append(deal)
|
| 16364 |
kshitij.so |
1618 |
sortedMap = {}
|
|
|
1619 |
rankMap = {}
|
|
|
1620 |
rank = 0
|
| 16406 |
kshitij.so |
1621 |
for sorted_deal in dealsList:
|
| 16364 |
kshitij.so |
1622 |
if sortedMap.get(sorted_deal['skuBundleId']) is None:
|
|
|
1623 |
sortedMap[sorted_deal['skuBundleId']] = {rank:[sorted_deal]}
|
|
|
1624 |
rankMap[rank] = (sortedMap[sorted_deal['skuBundleId']].values())[0]
|
|
|
1625 |
rank = rank +1
|
|
|
1626 |
else:
|
|
|
1627 |
for temp_list in sortedMap.get(sorted_deal['skuBundleId']).itervalues():
|
|
|
1628 |
temp_list.append(sorted_deal)
|
|
|
1629 |
rankMap[(sortedMap.get(sorted_deal['skuBundleId']).keys())[0]] = temp_list
|
|
|
1630 |
|
| 16367 |
kshitij.so |
1631 |
for dealList in [rankMap.get(k, []) for k in range(0, len(bundles))]:
|
| 16364 |
kshitij.so |
1632 |
temp = []
|
|
|
1633 |
for d in dealList:
|
|
|
1634 |
item = list(get_mongo_connection().Catalog.MasterData.find({'_id':d['_id']}))
|
|
|
1635 |
if len(item) ==0:
|
|
|
1636 |
continue
|
|
|
1637 |
if d['dealType'] == 1 and d['source_id'] ==1:
|
|
|
1638 |
item[0]['marketPlaceUrl'] = "http://www.amazon.in/dp/%s"%(item[0]['identifier'].strip())
|
|
|
1639 |
elif d['source_id'] ==3:
|
|
|
1640 |
item[0]['marketPlaceUrl'] = item[0]['marketPlaceUrl']+'?supc='+item[0].get('identifier')
|
|
|
1641 |
else:
|
|
|
1642 |
pass
|
|
|
1643 |
try:
|
|
|
1644 |
cashBack = getCashBack(item[0]['_id'], item[0]['source_id'], item[0]['category_id'])
|
|
|
1645 |
if not cashBack or cashBack.get('cash_back_status')!=1:
|
|
|
1646 |
item[0]['cash_back_type'] = 0
|
|
|
1647 |
item[0]['cash_back'] = 0
|
|
|
1648 |
else:
|
|
|
1649 |
item[0]['cash_back_type'] = int(cashBack['cash_back_type'])
|
|
|
1650 |
item[0]['cash_back'] = cashBack['cash_back']
|
|
|
1651 |
except:
|
|
|
1652 |
print "Error in adding cashback to deals"
|
|
|
1653 |
item[0]['cash_back_type'] = 0
|
|
|
1654 |
item[0]['cash_back'] = 0
|
|
|
1655 |
try:
|
|
|
1656 |
item[0]['dp'] = d['dp']
|
|
|
1657 |
item[0]['showDp'] = d['showDp']
|
|
|
1658 |
except:
|
|
|
1659 |
item[0]['dp'] = 0.0
|
|
|
1660 |
item[0]['showDp'] = 0
|
|
|
1661 |
temp.append(item[0])
|
|
|
1662 |
if len(temp) > 1:
|
|
|
1663 |
temp = sorted(temp, key = lambda x: (x['available_price']),reverse=False)
|
|
|
1664 |
dealsListMap.append(temp)
|
|
|
1665 |
return dealsListMap
|
|
|
1666 |
|
| 16373 |
manas |
1667 |
def getSkuBrandData(sku):
|
|
|
1668 |
if sku is None:
|
|
|
1669 |
return {}
|
|
|
1670 |
else:
|
|
|
1671 |
orders = get_mongo_connection().Catalog.MasterData.find_one({'skuBundleId':sku})
|
|
|
1672 |
if orders is None:
|
|
|
1673 |
return {}
|
|
|
1674 |
return orders
|
| 16488 |
kshitij.so |
1675 |
|
|
|
1676 |
def addDealPoints(data):
|
|
|
1677 |
collection = get_mongo_connection().Catalog.DealPoints
|
|
|
1678 |
cursor = collection.find({'skuBundleId':data['skuBundleId']})
|
|
|
1679 |
if cursor.count() > 0:
|
|
|
1680 |
return {0:"Sku information already present."}
|
|
|
1681 |
else:
|
|
|
1682 |
collection.insert(data)
|
|
|
1683 |
get_mongo_connection().Catalog.MasterData.update({'skuBundleId':data['skuBundleId']},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=True)
|
|
|
1684 |
return {1:"Data added successfully"}
|
|
|
1685 |
|
|
|
1686 |
def getAllBundlesWithDealPoints(offset, limit):
|
|
|
1687 |
data = []
|
|
|
1688 |
collection = get_mongo_connection().Catalog.DealPoints
|
|
|
1689 |
cursor = collection.find().sort([('endDate',pymongo.DESCENDING)]).skip(offset).limit(limit)
|
|
|
1690 |
for val in cursor:
|
|
|
1691 |
master = get_mongo_connection().Catalog.MasterData.find_one({'skuBundleId':val.get('skuBundleId')})
|
|
|
1692 |
if master is not None:
|
|
|
1693 |
val['brand'] = master['brand']
|
|
|
1694 |
val['source_product_name'] = master['product_name']
|
|
|
1695 |
else:
|
|
|
1696 |
val['brand'] = ""
|
|
|
1697 |
val['source_product_name'] = ""
|
|
|
1698 |
data.append(val)
|
|
|
1699 |
return data
|
| 16546 |
kshitij.so |
1700 |
|
|
|
1701 |
def generateRedirectUrl(retailer_id, app_id):
|
|
|
1702 |
try:
|
| 16663 |
manish.sha |
1703 |
if retailer_id <= 0:
|
|
|
1704 |
return {'url':"","message":"Retailer Id not valid"}
|
| 16546 |
kshitij.so |
1705 |
d_app_offer = app_offers.get_by(id=app_id)
|
| 16605 |
manish.sha |
1706 |
except:
|
|
|
1707 |
traceback.print_exc()
|
| 16546 |
kshitij.so |
1708 |
finally:
|
|
|
1709 |
session.close()
|
|
|
1710 |
if d_app_offer is None:
|
|
|
1711 |
return {'url':"","message":"App id doesn't exist"}
|
| 16364 |
kshitij.so |
1712 |
|
| 16915 |
manish.sha |
1713 |
final_user_payout = 0
|
|
|
1714 |
if d_app_offer.override_payout:
|
|
|
1715 |
final_user_payout = d_app_offer.overriden_payout
|
|
|
1716 |
else:
|
|
|
1717 |
final_user_payout = d_app_offer.user_payout
|
| 16546 |
kshitij.so |
1718 |
|
| 16915 |
manish.sha |
1719 |
appTransactions = AppTransactions(app_id, retailer_id, to_java_date(datetime.now()), None, 1, CB_INIT, 1, CB_INIT, None, None, d_app_offer.offer_price, d_app_offer.overriden_payout, d_app_offer.override_payout, d_app_offer.user_payout, final_user_payout)
|
|
|
1720 |
|
| 16546 |
kshitij.so |
1721 |
get_mongo_connection().AppOrder.AppTransaction.insert(appTransactions.__dict__)
|
|
|
1722 |
embedd = str((appTransactions.__dict__).get('_id'))
|
| 16548 |
kshitij.so |
1723 |
try:
|
|
|
1724 |
index = d_app_offer.link.index(".freeb.co.in")
|
|
|
1725 |
except:
|
| 16605 |
manish.sha |
1726 |
traceback.print_exc()
|
| 16548 |
kshitij.so |
1727 |
return {'url':"","message":"Substring not found"}
|
|
|
1728 |
redirect_url = d_app_offer.link[0:index]+"."+embedd+d_app_offer.link[index:]
|
| 16546 |
kshitij.so |
1729 |
get_mongo_connection().AppOrder.AppTransaction.update({'_id':ObjectId(embedd)},{"$set":{'redirect_url':redirect_url}})
|
| 16548 |
kshitij.so |
1730 |
return {'url':redirect_url,"message":"Success"}
|
| 16556 |
kshitij.so |
1731 |
|
|
|
1732 |
def addPayout(payout, transaction_id):
|
|
|
1733 |
try:
|
| 16764 |
manish.sha |
1734 |
print 'Got Response for Transaction Id:- '+ str(transaction_id)+ ' and Actual Payout:- '+str(payout)
|
| 16556 |
kshitij.so |
1735 |
transaction = list(get_mongo_connection().AppOrder.AppTransaction.find({'_id':ObjectId(transaction_id)}))
|
|
|
1736 |
if len(transaction) > 0:
|
|
|
1737 |
if (transaction[0])['payout_status'] ==1:
|
| 16753 |
manish.sha |
1738 |
get_mongo_connection().AppOrder.AppTransaction.update({'_id':ObjectId(transaction_id)},{"$set":{'payout_amount':float(payout), 'payout_description': CB_APPROVED,'payout_status':2, 'cashback_status': 2, 'cash_back_description': CB_APPROVED, 'payout_time':to_java_date(datetime.now())}})
|
| 16782 |
manish.sha |
1739 |
|
|
|
1740 |
approvedAppTransaction = approved_app_transactions.get_by(transaction_id=transaction_id)
|
|
|
1741 |
if approvedAppTransaction is None:
|
|
|
1742 |
approvedAppTransaction = approved_app_transactions()
|
| 16919 |
manish.sha |
1743 |
approvedAppTransaction.app_id = transaction[0].get('app_id')
|
| 16782 |
manish.sha |
1744 |
approvedAppTransaction.cash_back_description = CB_APPROVED
|
| 16919 |
manish.sha |
1745 |
approvedAppTransaction.retailer_id = transaction[0].get('retailer_id')
|
| 16782 |
manish.sha |
1746 |
approvedAppTransaction.transaction_id = transaction_id
|
| 16919 |
manish.sha |
1747 |
approvedAppTransaction.transaction_time = to_py_date(long(transaction[0].get('transaction_time')))
|
|
|
1748 |
approvedAppTransaction.redirect_url = transaction[0].get('redirect_url')
|
| 16782 |
manish.sha |
1749 |
approvedAppTransaction.payout_status = 2
|
|
|
1750 |
approvedAppTransaction.payout_description = CB_APPROVED
|
|
|
1751 |
approvedAppTransaction.cashback_status = 2
|
|
|
1752 |
approvedAppTransaction.payout_amount = long(payout)
|
|
|
1753 |
approvedAppTransaction.payout_time = datetime.now()
|
| 16919 |
manish.sha |
1754 |
approvedAppTransaction.offer_price = long(transaction[0].get('offer_price'))
|
|
|
1755 |
approvedAppTransaction.overridenCashBack = transaction[0].get('overridenCashBack')
|
|
|
1756 |
approvedAppTransaction.isCashBackOverriden = transaction[0].get('isCashBackOverriden')
|
|
|
1757 |
approvedAppTransaction.user_payout = transaction[0].get('user_payout')
|
| 16782 |
manish.sha |
1758 |
approvedAppTransaction.cashBackConsidered = False
|
| 16915 |
manish.sha |
1759 |
if transaction[0].get('final_user_payout') is not None:
|
|
|
1760 |
approvedAppTransaction.final_user_payout = transaction[0].get('final_user_payout')
|
|
|
1761 |
else:
|
| 16919 |
manish.sha |
1762 |
if transaction[0].get('isCashBackOverriden'):
|
|
|
1763 |
approvedAppTransaction.final_user_payout = transaction[0].get('overridenCashBack')
|
| 16915 |
manish.sha |
1764 |
else:
|
| 16919 |
manish.sha |
1765 |
approvedAppTransaction.final_user_payout = transaction[0].get('user_payout')
|
| 16782 |
manish.sha |
1766 |
session.commit()
|
|
|
1767 |
|
|
|
1768 |
updateResult = _updateApprovedCashbackToUser(approvedAppTransaction.id)
|
| 16631 |
manish.sha |
1769 |
else:
|
| 16783 |
manish.sha |
1770 |
approvedAppTransaction.payout_amount = long(payout)
|
|
|
1771 |
approvedAppTransaction.payout_time = datetime.now()
|
|
|
1772 |
if approvedAppTransaction.cashBackConsidered == False:
|
|
|
1773 |
updateResult = _updateApprovedCashbackToUser(approvedAppTransaction.id)
|
|
|
1774 |
session.commit()
|
| 16782 |
manish.sha |
1775 |
|
|
|
1776 |
'''
|
|
|
1777 |
try:
|
|
|
1778 |
if int(transaction[0]['offer_price']) != payout or int(transaction[0]['user_payout']) < payout:
|
|
|
1779 |
_sendAlertForAppPayouts(int(transaction[0]['app_id']), int(transaction[0]['offer_price']), int(transaction[0]['user_payout']), payout)
|
|
|
1780 |
except:
|
|
|
1781 |
print traceback.print_exc()
|
|
|
1782 |
'''
|
| 16556 |
kshitij.so |
1783 |
return {'status':'ok','message':'Payout updated'}
|
|
|
1784 |
elif (transaction[0])['payout_status'] ==2:
|
|
|
1785 |
return {'status':'ok','message':'Payout already processed'}
|
|
|
1786 |
else:
|
|
|
1787 |
return {'status':'fail','message':'Something is wrong'}
|
|
|
1788 |
else:
|
|
|
1789 |
return {'status':'fail','message':'transaction_id not found'}
|
|
|
1790 |
except:
|
| 16657 |
manish.sha |
1791 |
print traceback.print_exc()
|
| 16631 |
manish.sha |
1792 |
try:
|
| 16753 |
manish.sha |
1793 |
get_mongo_connection().AppOrder.AppTransaction.update({'_id':ObjectId(transaction_id)},{"$set":{'payout_amount':None, 'payout_description': CB_INIT,'payout_status':1, 'cashback_status': 1, 'cash_back_description': CB_INIT, 'payout_time':None}})
|
| 16631 |
manish.sha |
1794 |
except:
|
|
|
1795 |
print 'Data Inconsistency in Cashback Process'
|
| 16636 |
manish.sha |
1796 |
print traceback.print_exc()
|
| 16559 |
kshitij.so |
1797 |
return {'status':'fail','message':'Something is wrong'}
|
| 16885 |
kshitij.so |
1798 |
finally:
|
|
|
1799 |
session.close()
|
| 16556 |
kshitij.so |
1800 |
|
| 16631 |
manish.sha |
1801 |
def _updateApprovedCashbackToUser(approvedAppTransactionId):
|
|
|
1802 |
approvedAppTransaction = approved_app_transactions.get_by(id=approvedAppTransactionId)
|
| 16915 |
manish.sha |
1803 |
if approvedAppTransaction.retailer_id < 0:
|
|
|
1804 |
return False
|
|
|
1805 |
|
| 16631 |
manish.sha |
1806 |
currentMonth = datetime.today().month
|
|
|
1807 |
currentDay = datetime.today().day
|
|
|
1808 |
currentYear = datetime.today().year
|
|
|
1809 |
fortNight = (currentMonth - 1)*2 + (currentDay/15)
|
|
|
1810 |
if currentDay == 30 or currentDay ==31:
|
|
|
1811 |
fortNight = fortNight-1
|
|
|
1812 |
userAppCashbackObj = user_app_cashbacks.query.filter(user_app_cashbacks.yearVal==currentYear).filter(user_app_cashbacks.user_id==approvedAppTransaction.retailer_id).filter(user_app_cashbacks.fortnightOfYear==fortNight).filter(user_app_cashbacks.status=='Approved').first()
|
|
|
1813 |
userAppInstallObj = user_app_installs.query.filter(user_app_installs.user_id==approvedAppTransaction.retailer_id).filter(user_app_installs.app_id==approvedAppTransaction.app_id).filter(user_app_installs.transaction_date==datetime(currentYear, currentMonth, currentDay, 0, 0, 0, 0).date()).first()
|
|
|
1814 |
try:
|
|
|
1815 |
if userAppCashbackObj is None:
|
|
|
1816 |
userAppCashbackObj = user_app_cashbacks()
|
|
|
1817 |
userAppCashbackObj.user_id = approvedAppTransaction.retailer_id
|
|
|
1818 |
userAppCashbackObj.status = 'Approved'
|
| 16915 |
manish.sha |
1819 |
userAppCashbackObj.amount = approvedAppTransaction.final_user_payout
|
| 16631 |
manish.sha |
1820 |
userAppCashbackObj.fortnightOfYear = fortNight
|
|
|
1821 |
userAppCashbackObj.yearVal = currentYear
|
|
|
1822 |
else:
|
| 16915 |
manish.sha |
1823 |
userAppCashbackObj.amount = userAppCashbackObj.amount + approvedAppTransaction.final_user_payout
|
| 16631 |
manish.sha |
1824 |
|
|
|
1825 |
if userAppInstallObj is None:
|
|
|
1826 |
app_offer = app_offers.get_by(id=approvedAppTransaction.app_id)
|
|
|
1827 |
userAppInstallObj = user_app_installs()
|
|
|
1828 |
userAppInstallObj.user_id = approvedAppTransaction.retailer_id
|
|
|
1829 |
userAppInstallObj.fortnightOfYear = fortNight
|
|
|
1830 |
userAppInstallObj.transaction_date = datetime(currentYear, currentMonth, currentDay, 0, 0, 0, 0).date()
|
|
|
1831 |
userAppInstallObj.app_id = approvedAppTransaction.app_id
|
|
|
1832 |
userAppInstallObj.app_name = app_offer.app_name
|
|
|
1833 |
userAppInstallObj.installCount = 1
|
| 16915 |
manish.sha |
1834 |
userAppInstallObj.payoutAmount = approvedAppTransaction.final_user_payout
|
| 16631 |
manish.sha |
1835 |
else:
|
|
|
1836 |
userAppInstallObj.installCount = userAppInstallObj.installCount + 1
|
| 16915 |
manish.sha |
1837 |
userAppInstallObj.payoutAmount = userAppInstallObj.payoutAmount +approvedAppTransaction.final_user_payout
|
| 16631 |
manish.sha |
1838 |
|
|
|
1839 |
approvedAppTransaction.cashBackConsidered = True
|
|
|
1840 |
session.commit()
|
|
|
1841 |
return True
|
|
|
1842 |
except:
|
|
|
1843 |
session.rollback()
|
| 16636 |
manish.sha |
1844 |
print traceback.print_exc()
|
| 16631 |
manish.sha |
1845 |
return False
|
| 16693 |
manish.sha |
1846 |
|
|
|
1847 |
def _sendAlertForAppPayouts(app_id, offerPrice, userPayout, payout):
|
|
|
1848 |
m = Email('localhost')
|
|
|
1849 |
mFrom = "dtr@shop2020.in"
|
|
|
1850 |
m.setFrom(mFrom)
|
|
|
1851 |
mTo = ['rajneesh.arora@saholic.com','kshitij.sood@saholic.com','chaitnaya.vats@saholic.com','manoj.kumar@saholic.com','manish.sharma@shop2020.in']
|
|
|
1852 |
for receipient in mTo:
|
|
|
1853 |
m.addRecipient(receipient)
|
|
|
1854 |
appOffer = app_offers.get_by(id=app_id)
|
|
|
1855 |
if offerPrice != payout:
|
|
|
1856 |
m.setSubject("Mismatch in Offer Price and Actual Pay Out for App Id:- "+str(appOffer.id)+" App Name:- "+str(appOffer.app_name))
|
|
|
1857 |
message1 = "Offer Price:- "+ str(appOffer.offer_price) + "\n" + "Actual Pay Out:- "+ str(payout)
|
|
|
1858 |
m.setTextBody(message1)
|
|
|
1859 |
if userPayout > payout:
|
|
|
1860 |
m.setSubject("User Pay Out greater than actual PayOut for App Id:- "+str(appOffer.id)+" App Name:- "+str(appOffer.app_name))
|
|
|
1861 |
message2 = "User Pay Out Price:- "+ str(appOffer.user_payout) + "\n" + "Actual Pay Out:- "+ str(payout)
|
|
|
1862 |
m.setTextBody(message2)
|
|
|
1863 |
m.send()
|
| 16631 |
manish.sha |
1864 |
|
| 16789 |
amit.gupta |
1865 |
def rejectCashback(orderId, subOrderId):
|
| 16833 |
amit.gupta |
1866 |
cashBack = get_mongo_connection().Dtr.merchantOrder.update({"orderId":orderId, "subOrders.merchantSubOrderId":subOrderId},
|
| 16789 |
amit.gupta |
1867 |
{"$set":{"subOrders.$.cashBackStatus":CB_REJECTED}})
|
| 16837 |
amit.gupta |
1868 |
print cashBack
|
| 16836 |
amit.gupta |
1869 |
return cashBack.get("nModified")
|
| 16894 |
manish.sha |
1870 |
|
|
|
1871 |
def getAppOffers(retailer_id):
|
|
|
1872 |
if not bool(mc.get("cached_app_offers_"+str(retailer_id))):
|
|
|
1873 |
populateAppOffers(retailer_id)
|
|
|
1874 |
return mc.get("cached_app_offers_"+str(retailer_id))
|
|
|
1875 |
|
|
|
1876 |
def populateAppOffers(retailerId):
|
|
|
1877 |
retailerId = int(retailerId)
|
|
|
1878 |
#offset = req.get_param_as_int("offset")
|
|
|
1879 |
#limit = req.get_param_as_int("limit")
|
| 16941 |
manish.sha |
1880 |
nonPriortizedOffers = session.query(app_offers.id).join((appmasters,appmasters.id==app_offers.appmaster_id)).filter(app_offers.affiliate_id==retailerId).filter(appmasters.showApp==True).filter(app_offers.show==True).filter(app_offers.offer_active==True).filter(app_offers.offer_price>0).filter(appmasters.rank==0).order_by(desc('user_payout')).all()
|
|
|
1881 |
priortizeders = session.query(app_offers.id, appmasters.rank).join((appmasters,appmasters.id==app_offers.appmaster_id)).filter(app_offers.affiliate_id==retailerId).filter(appmasters.showApp==True).filter(app_offers.show==True).filter(app_offers.offer_active==True).filter(app_offers.offer_price>0).filter(appmasters.rank>0).order_by(asc(appmasters.rank)).all()
|
| 16894 |
manish.sha |
1882 |
#session.query(app_offers.id,app_offers.appmaster_id, app_offers.app_name, app_offers.affiliate_offer_id, app_offers.image_url, app_offers.downloads, app_offers.link, app_offers.offer_price, app_offers.offerCategory, app_offers.package_name, app_offers.promoImage, app_offers.ratings, case([(app_offers.override_payout == True, app_offers.overriden_payout)], else_=app_offers.user_payout).label('user_payout'), case([(appmasters.shortDescription != None, appmasters.shortDescription)], else_=None).label('shortDescription'), case([(appmasters.longDescription != None, appmasters.longDescription)], else_=None).label('longDescription'), appmasters.customerOneLiner, appmasters.retailerOneLiner,app_offers.priority, app_offers.offerCondition, app_offers.location).join((appmasters,appmasters.id==app_offers.appmaster_id)).filter(app_offers.affiliate_id==retailerId).filter(appmasters.showApp==True).filter(app_offers.show==True).filter(app_offers.offer_active==True).filter(app_offers.offer_price>0).order_by(case([(app_offers.priority.in_(tuple(nullCheckList)), 1)], else_=0), asc(app_offers.priority),desc('user_payout')).all()
|
|
|
1883 |
|
|
|
1884 |
appOffersMap = {}
|
|
|
1885 |
priorityList = []
|
|
|
1886 |
priorityMap = {}
|
|
|
1887 |
for offer in priortizeders:
|
| 16941 |
manish.sha |
1888 |
if priorityMap.has_key(long(offer[1])):
|
|
|
1889 |
offersVal = priorityMap.get(long(offer[1]))
|
|
|
1890 |
offersVal.append(offer)
|
|
|
1891 |
priorityMap[long(offer[1])]=offersVal
|
|
|
1892 |
else:
|
|
|
1893 |
offersVal = []
|
|
|
1894 |
offersVal.append(offer)
|
|
|
1895 |
priorityMap[long(offer[1])]=offersVal
|
|
|
1896 |
|
| 16894 |
manish.sha |
1897 |
priorityList = sorted(priorityMap)
|
|
|
1898 |
|
|
|
1899 |
maxCount = len(nonPriortizedOffers) + len(priortizeders)
|
|
|
1900 |
|
| 16909 |
manish.sha |
1901 |
if priorityList is not None and len(priorityList)>0:
|
|
|
1902 |
if maxCount < max(priorityList):
|
|
|
1903 |
maxCount = max(priorityList)
|
| 16894 |
manish.sha |
1904 |
|
|
|
1905 |
count = 1
|
|
|
1906 |
blockedPlaces = []
|
|
|
1907 |
availablePlaces = []
|
|
|
1908 |
while count <= maxCount:
|
|
|
1909 |
if count in priorityList:
|
|
|
1910 |
blockedPlaces.append(count)
|
|
|
1911 |
else:
|
|
|
1912 |
availablePlaces.append(count)
|
|
|
1913 |
count = count +1
|
| 16941 |
manish.sha |
1914 |
print 'Blocked Places', blockedPlaces
|
| 16894 |
manish.sha |
1915 |
for val in blockedPlaces:
|
| 16941 |
manish.sha |
1916 |
key = val
|
|
|
1917 |
for offerObj in priorityMap.get(val):
|
|
|
1918 |
while appOffersMap.has_key(key):
|
|
|
1919 |
key = key+1
|
|
|
1920 |
appOffersMap[key] = long(offerObj[0])
|
|
|
1921 |
if key in availablePlaces:
|
|
|
1922 |
availablePlaces.remove(key)
|
|
|
1923 |
|
|
|
1924 |
print 'Available Places', availablePlaces
|
|
|
1925 |
|
| 16894 |
manish.sha |
1926 |
i=0
|
|
|
1927 |
for val in availablePlaces:
|
| 16899 |
manish.sha |
1928 |
if i<len(nonPriortizedOffers):
|
| 16902 |
manish.sha |
1929 |
appOffersMap[val]= long(nonPriortizedOffers[i][0])
|
| 16899 |
manish.sha |
1930 |
else:
|
|
|
1931 |
break
|
|
|
1932 |
i=i+1
|
| 16901 |
manish.sha |
1933 |
print 'AppOffersMap', appOffersMap
|
| 16894 |
manish.sha |
1934 |
|
|
|
1935 |
finalAppOffersMap = {}
|
|
|
1936 |
if len(appOffersMap) > 0:
|
|
|
1937 |
for key in sorted(appOffersMap):
|
|
|
1938 |
finalAppOffersMap[key] = appOffersMap[key]
|
|
|
1939 |
|
|
|
1940 |
mc.set("cached_app_offers_"+str(retailerId), finalAppOffersMap, 120)
|
|
|
1941 |
else:
|
|
|
1942 |
print 'No Offers'
|
|
|
1943 |
mc.set("cached_app_offers_"+str(retailerId), {}, 10)
|
| 17280 |
manish.sha |
1944 |
|
|
|
1945 |
def sendNotification(userIds, campaignName, title, message,notificationtype, url, expiresat='2999-01-01'):
|
|
|
1946 |
campaignId = addNotificationCampaign(campaignName, title, message, notificationtype, url, None)
|
|
|
1947 |
payload = {}
|
|
|
1948 |
payload["user_id"]= userIds[0]
|
|
|
1949 |
payload["type"]="pending"
|
|
|
1950 |
payload["notification_campaign_id"]= campaignId
|
|
|
1951 |
payload["status"]=0
|
| 16546 |
kshitij.so |
1952 |
|
| 17280 |
manish.sha |
1953 |
payloadList = []
|
|
|
1954 |
payloadList.append(payload)
|
| 17281 |
manish.sha |
1955 |
jsonObj = json.dumps([dict(pn) for pn in payloadList])
|
|
|
1956 |
print jsonObj
|
|
|
1957 |
pushpostrequest = urllib2.Request("http://45.33.50.227:3001/addPushNotification")
|
|
|
1958 |
pushpostrequest.add_header('Content-Type', 'application/json')
|
|
|
1959 |
response = urllib2.urlopen(pushpostrequest, jsonObj).read()
|
| 17280 |
manish.sha |
1960 |
print response
|
|
|
1961 |
|
|
|
1962 |
def addNotificationCampaign(name, title, message, type, url, sql):
|
|
|
1963 |
notificationCampaign = notification_campaigns()
|
|
|
1964 |
notificationCampaign.name = name
|
|
|
1965 |
notificationCampaign.title = title
|
|
|
1966 |
notificationCampaign.type = type
|
|
|
1967 |
notificationCampaign.message = message
|
|
|
1968 |
notificationCampaign.url = url
|
|
|
1969 |
notificationCampaign.sql = sql
|
|
|
1970 |
notificationCampaign.expiresat = datetime(2999, 1, 1)
|
|
|
1971 |
notificationCampaign.status = 'active'
|
|
|
1972 |
notificationCampaign.created = datetime.now()
|
|
|
1973 |
|
|
|
1974 |
session.commit()
|
|
|
1975 |
campaignId = notificationCampaign.id
|
|
|
1976 |
|
|
|
1977 |
session.close()
|
|
|
1978 |
return campaignId
|
| 17302 |
kshitij.so |
1979 |
|
|
|
1980 |
def getDummyDeals(categoryId, offset, limit):
|
|
|
1981 |
outer_query = []
|
|
|
1982 |
outer_query.append({"showDeal":1})
|
|
|
1983 |
outer_query.append({"category_id":categoryId})
|
|
|
1984 |
query = {}
|
|
|
1985 |
query['$gt'] = -100
|
|
|
1986 |
outer_query.append({'totalPoints':query})
|
|
|
1987 |
all_deals = list(get_mongo_connection().Catalog.Deals.find({"$and":outer_query},{'_id':1}).sort([('totalPoints',pymongo.DESCENDING),('bestSellerPoints',pymongo.DESCENDING),('nlcPoints',pymongo.DESCENDING),('rank',pymongo.DESCENDING)]).skip(offset).limit(limit))
|
|
|
1988 |
returnObj = []
|
|
|
1989 |
for deal in all_deals:
|
| 17306 |
kshitij.so |
1990 |
item = list(get_mongo_connection().Catalog.MasterData.find({'_id':deal['_id']}))
|
| 17305 |
kshitij.so |
1991 |
returnObj.append(getItemObjForStaticDeals(item[0]))
|
| 17302 |
kshitij.so |
1992 |
return returnObj
|
| 17367 |
kshitij.so |
1993 |
|
| 17469 |
kshitij.so |
1994 |
def searchDummyDeals(search_term , limit, offset):
|
| 17367 |
kshitij.so |
1995 |
data = []
|
|
|
1996 |
uniqueMap = {}
|
|
|
1997 |
if search_term is not None:
|
|
|
1998 |
terms = search_term.split(' ')
|
|
|
1999 |
outer_query = []
|
|
|
2000 |
for term in terms:
|
|
|
2001 |
outer_query.append({"source_product_name":re.compile(term, re.IGNORECASE)})
|
|
|
2002 |
try:
|
|
|
2003 |
collection = get_mongo_connection().Catalog.MasterData.find({"$and":outer_query,'source_id':{'$in':SOURCE_MAP.keys()}})
|
|
|
2004 |
for record in collection:
|
|
|
2005 |
data.append(record)
|
|
|
2006 |
except:
|
|
|
2007 |
pass
|
|
|
2008 |
else:
|
|
|
2009 |
collection = get_mongo_connection().Catalog.MasterData.find({'source_id':{'$in':SOURCE_MAP.keys()}})
|
|
|
2010 |
for record in collection:
|
|
|
2011 |
data.append(record)
|
|
|
2012 |
for x in data:
|
|
|
2013 |
if not uniqueMap.has_key(x['skuBundleId']):
|
| 17469 |
kshitij.so |
2014 |
uniqueMap[x['skuBundleId']] = {'source_product_name':x['source_product_name'],'skuBundleId':x['skuBundleId'],'thumbnail':x['thumbnail']}
|
| 17367 |
kshitij.so |
2015 |
|
| 17469 |
kshitij.so |
2016 |
if (offset + limit) > len(uniqueMap.values()):
|
|
|
2017 |
limit = len(uniqueMap.values()) - offset - 1
|
|
|
2018 |
|
|
|
2019 |
count = 0
|
|
|
2020 |
# for x in uniqueMap.values():
|
|
|
2021 |
# print count,
|
|
|
2022 |
# print '\t',
|
|
|
2023 |
# print x
|
|
|
2024 |
# count = count+1
|
| 17367 |
kshitij.so |
2025 |
|
| 17469 |
kshitij.so |
2026 |
print offset
|
|
|
2027 |
print limit
|
|
|
2028 |
|
|
|
2029 |
return uniqueMap.values()[offset:limit+offset]
|
| 17367 |
kshitij.so |
2030 |
|
| 17469 |
kshitij.so |
2031 |
|
|
|
2032 |
def getDummyPricing(skuBundleId):
|
|
|
2033 |
collection = get_mongo_connection().Catalog.MasterData.find({'source_id':{'$in':SOURCE_MAP.keys()},'skuBundleId':skuBundleId,'in_stock':1})
|
|
|
2034 |
print collection.count()
|
|
|
2035 |
cheapest = 99999999
|
|
|
2036 |
cheapestDetails= None
|
|
|
2037 |
returnMap = {}
|
|
|
2038 |
|
|
|
2039 |
for d in collection:
|
|
|
2040 |
if d['available_price'] < cheapest:
|
|
|
2041 |
cheapestDetails = d
|
|
|
2042 |
cheapest = int(d['available_price'])
|
|
|
2043 |
if returnMap.has_key(d['source_id']):
|
|
|
2044 |
d = getItemObjForStaticDeals(d)
|
|
|
2045 |
d['toShowStore'] = 0
|
|
|
2046 |
returnMap[d['source_id']].append(d)
|
|
|
2047 |
else:
|
|
|
2048 |
temp = []
|
|
|
2049 |
d = getItemObjForStaticDeals(d)
|
|
|
2050 |
d['toShowStore'] = 1
|
|
|
2051 |
temp.append(d)
|
|
|
2052 |
returnMap[d['source_id']] = temp
|
|
|
2053 |
returnMap['cheapest'] = cheapestDetails
|
|
|
2054 |
for y in returnMap.itervalues():
|
|
|
2055 |
if isinstance(y, (list, tuple)):
|
|
|
2056 |
(y[len(y)-1])['lastElement'] = 1
|
|
|
2057 |
else:
|
|
|
2058 |
pass
|
|
|
2059 |
if returnMap['cheapest'] ==None:
|
|
|
2060 |
dum = get_mongo_connection().Catalog.MasterData.find_one({'skuBundleId':skuBundleId,'source_id':{"$in":SOURCE_MAP.keys()}})
|
|
|
2061 |
returnMap['cheapest'] = {'thumbnail':dum['thumbnail'],'source_product_name':dum['source_product_name']}
|
|
|
2062 |
return returnMap
|
| 17280 |
manish.sha |
2063 |
|
| 13572 |
kshitij.so |
2064 |
def main():
|
| 17469 |
kshitij.so |
2065 |
featuredDeals = mc.get("featured_deals")
|
| 17369 |
kshitij.so |
2066 |
print resetCache("47")
|
| 17367 |
kshitij.so |
2067 |
print datetime.now()
|
| 17469 |
kshitij.so |
2068 |
x= getNewDeals(47, 6, 0, 20, None, None, None)
|
| 17369 |
kshitij.so |
2069 |
for y in x:
|
|
|
2070 |
print y[0]['skuBundleId'],
|
|
|
2071 |
print '\t',
|
|
|
2072 |
print y[0]['brand']
|
| 17367 |
kshitij.so |
2073 |
print datetime.now()
|
| 17469 |
kshitij.so |
2074 |
|
|
|
2075 |
|
|
|
2076 |
|
| 13572 |
kshitij.so |
2077 |
if __name__=='__main__':
|
| 13932 |
amit.gupta |
2078 |
main()
|
| 17469 |
kshitij.so |
2079 |
|