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