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