| 13829 |
kshitij.so |
1 |
import urllib2
|
|
|
2 |
import simplejson as json
|
|
|
3 |
import pymongo
|
| 15951 |
kshitij.so |
4 |
from dtr.utils.utils import to_java_date, getNlcPoints, transformUrl
|
| 13918 |
kshitij.so |
5 |
from datetime import datetime, timedelta
|
| 13829 |
kshitij.so |
6 |
from operator import itemgetter
|
|
|
7 |
from dtr.utils.AmazonPriceOnlyScraper import AmazonScraper
|
| 14309 |
kshitij.so |
8 |
from dtr.utils import AmazonDealScraper
|
| 16410 |
kshitij.so |
9 |
from dtr.utils import FlipkartScraper,NewFlipkartScraper, ShopCluesScraper, \
|
| 17013 |
manish.sha |
10 |
PaytmOfferScraper, PaytmScraper, HomeShop18Scraper
|
| 14324 |
kshitij.so |
11 |
from dtr.storage.MemCache import MemCache
|
| 14334 |
kshitij.so |
12 |
from functools import partial
|
|
|
13 |
import threading
|
| 14760 |
kshitij.so |
14 |
from dtr.utils.utils import getCashBack
|
| 14794 |
kshitij.so |
15 |
import traceback
|
| 15174 |
kshitij.so |
16 |
from shop2020.config.client.ConfigClient import ConfigClient
|
| 16065 |
kshitij.so |
17 |
import chardet
|
| 16415 |
kshitij.so |
18 |
from dtr.CouponMaster import addToPaytmMaster
|
| 19210 |
kshitij.so |
19 |
from math import floor
|
| 13829 |
kshitij.so |
20 |
|
| 15174 |
kshitij.so |
21 |
config_client = ConfigClient()
|
|
|
22 |
host_memCache = config_client.get_property('mem_cache_host_dtr')
|
|
|
23 |
host = config_client.get_property('mongo_dtr_host')
|
| 14324 |
kshitij.so |
24 |
|
| 18722 |
kshitij.so |
25 |
saholicPricingHost = config_client.get_property('dtr_pricing_host')
|
|
|
26 |
|
| 15174 |
kshitij.so |
27 |
mc = MemCache(host_memCache)
|
|
|
28 |
|
|
|
29 |
|
| 15902 |
kshitij.so |
30 |
con = None
|
| 17043 |
kshitij.so |
31 |
SOURCE_MAP = {'AMAZON':1,'FLIPKART':2,'SNAPDEAL':3,'SAHOLIC':4, 'SHOPCLUES.COM':5,'PAYTM.COM':6,'HOMESHOP18':7}
|
| 13829 |
kshitij.so |
32 |
|
|
|
33 |
headers = {
|
|
|
34 |
'User-agent':'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11',
|
|
|
35 |
'Accept' : 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
|
|
|
36 |
'Accept-Language' : 'en-US,en;q=0.8',
|
|
|
37 |
'Accept-Charset' : 'ISO-8859-1,utf-8;q=0.7,*;q=0.3'
|
|
|
38 |
}
|
|
|
39 |
|
| 15608 |
kshitij.so |
40 |
|
| 15174 |
kshitij.so |
41 |
def get_mongo_connection(port=27017):
|
| 13829 |
kshitij.so |
42 |
global con
|
|
|
43 |
if con is None:
|
|
|
44 |
print "Establishing connection %s host and port %d" %(host,port)
|
|
|
45 |
try:
|
|
|
46 |
con = pymongo.MongoClient(host, port)
|
|
|
47 |
except Exception, e:
|
|
|
48 |
print e
|
|
|
49 |
return None
|
|
|
50 |
return con
|
|
|
51 |
|
| 19153 |
kshitij.so |
52 |
def calculateCashBack(data, inputPrice):
|
|
|
53 |
try:
|
|
|
54 |
cashBack = getCashBack(data['_id'], data['source_id'], data['category_id'], mc, 'localhost')
|
|
|
55 |
print "CashBack is ",cashBack
|
|
|
56 |
if not cashBack or cashBack.get('cash_back_status')!=1:
|
|
|
57 |
data['cash_back_type'] = 0
|
|
|
58 |
data['cash_back'] = 0
|
|
|
59 |
else:
|
|
|
60 |
if cashBack['cash_back_type'] in (1,2):
|
|
|
61 |
|
|
|
62 |
if cashBack.get('maxCashBack') is not None:
|
|
|
63 |
|
|
|
64 |
if cashBack.get('cash_back_type') ==1 and (float(cashBack.get('cash_back'))*data['available_price'])/100 > cashBack.get('maxCashBack'):
|
|
|
65 |
cashBack['cash_back_type'] = 2
|
|
|
66 |
cashBack['cash_back'] = cashBack['maxCashBack']
|
|
|
67 |
elif cashBack.get('cash_back_type') ==2 and cashBack.get('cash_back') > cashBack.get('maxCashBack'):
|
|
|
68 |
cashBack['cash_back'] = cashBack['maxCashBack']
|
|
|
69 |
else:
|
|
|
70 |
pass
|
|
|
71 |
|
|
|
72 |
data['cash_back_type'] = cashBack['cash_back_type']
|
|
|
73 |
data['cash_back'] = float(cashBack['cash_back'])
|
|
|
74 |
else:
|
|
|
75 |
data['cash_back_type'] = 0
|
|
|
76 |
data['cash_back'] = 0
|
|
|
77 |
except Exception as cashBackEx:
|
|
|
78 |
traceback.print_exc()
|
|
|
79 |
print "Error calculating cashback."
|
|
|
80 |
data['cash_back_type'] = 0
|
|
|
81 |
data['cash_back'] = 0
|
|
|
82 |
|
|
|
83 |
if data['cash_back_type'] == 1:
|
| 19210 |
kshitij.so |
84 |
data['netPriceAfterCashBack'] = inputPrice - floor(float(inputPrice)*data['cash_back']/100)
|
| 19153 |
kshitij.so |
85 |
elif data['cash_back_type'] == 2:
|
|
|
86 |
data['netPriceAfterCashBack'] = inputPrice - data['cash_back']
|
|
|
87 |
else:
|
|
|
88 |
data['netPriceAfterCashBack'] = inputPrice
|
|
|
89 |
|
|
|
90 |
return data
|
|
|
91 |
|
| 14828 |
kshitij.so |
92 |
def returnLatestPrice(data, source_id, ignoreLastUpdated = True):
|
| 13918 |
kshitij.so |
93 |
now = datetime.now()
|
| 13829 |
kshitij.so |
94 |
if source_id == 1:
|
|
|
95 |
try:
|
| 13918 |
kshitij.so |
96 |
if data['identifier'] is None or len(data['identifier'].strip())==0:
|
| 13829 |
kshitij.so |
97 |
return {}
|
| 13918 |
kshitij.so |
98 |
|
| 19153 |
kshitij.so |
99 |
if data['dealFlag'] ==1 and data['dealType'] ==1:
|
|
|
100 |
data['marketPlaceUrl'] = data['dealUrl'].strip()
|
|
|
101 |
|
|
|
102 |
|
| 16500 |
kshitij.so |
103 |
if data.get('ignorePricing') ==1:
|
| 16117 |
kshitij.so |
104 |
return {'_id':data['_id'],'available_price':data['available_price'],'in_stock':data['in_stock'],'source_id':1,'source_product_name':data['source_product_name'],'marketPlaceUrl':data['marketPlaceUrl'],'thumbnail':data['thumbnail'],'coupon':data['coupon'], 'codAvailable':data['codAvailable'], 'tagline': data['tagline'], 'offer': data['offer']}
|
| 15615 |
kshitij.so |
105 |
|
| 13918 |
kshitij.so |
106 |
try:
|
| 14828 |
kshitij.so |
107 |
if ignoreLastUpdated and data['priceUpdatedOn'] > to_java_date(now - timedelta(minutes=5)):
|
| 13918 |
kshitij.so |
108 |
print "sku id is already updated",data['_id']
|
| 16117 |
kshitij.so |
109 |
return {'_id':data['_id'],'available_price':data['available_price'],'in_stock':data['in_stock'],'source_id':1,'source_product_name':data['source_product_name'],'marketPlaceUrl':data['marketPlaceUrl'],'thumbnail':data['thumbnail'],'coupon':data['coupon'], 'codAvailable':data['codAvailable'], 'tagline': data['tagline'], 'offer': data['offer']}
|
| 13918 |
kshitij.so |
110 |
except:
|
|
|
111 |
pass
|
|
|
112 |
|
|
|
113 |
|
| 15956 |
kshitij.so |
114 |
url = "http://www.amazon.in/gp/aw/ol/%s?o=New&op=1"%(data['identifier'])
|
| 13829 |
kshitij.so |
115 |
lowestPrice = 0.0
|
| 14309 |
kshitij.so |
116 |
try:
|
|
|
117 |
if data['dealFlag'] ==1 and data['dealType'] ==1:
|
|
|
118 |
print "Inside deal"
|
| 16510 |
kshitij.so |
119 |
deal_url = data['marketPlaceUrl']
|
| 14309 |
kshitij.so |
120 |
print deal_url
|
| 15213 |
kshitij.so |
121 |
dealScraperAmazon = AmazonDealScraper.AmazonScraper(True)
|
| 14309 |
kshitij.so |
122 |
lowestPrice = dealScraperAmazon.read(deal_url)
|
|
|
123 |
print lowestPrice
|
|
|
124 |
if lowestPrice == 0:
|
|
|
125 |
raise
|
|
|
126 |
else:
|
| 15213 |
kshitij.so |
127 |
scraperAmazon = AmazonScraper(True)
|
| 14309 |
kshitij.so |
128 |
lowestPrice = scraperAmazon.read(url)
|
|
|
129 |
except Exception as e:
|
|
|
130 |
print e
|
| 15213 |
kshitij.so |
131 |
scraperAmazon = AmazonScraper(True)
|
| 14309 |
kshitij.so |
132 |
lowestPrice = scraperAmazon.read(url)
|
| 13929 |
kshitij.so |
133 |
print "LowestPrice ",lowestPrice
|
| 13829 |
kshitij.so |
134 |
inStock = 0
|
|
|
135 |
if lowestPrice > 0:
|
|
|
136 |
inStock = 1
|
|
|
137 |
if lowestPrice > 0:
|
| 13971 |
kshitij.so |
138 |
get_mongo_connection().Catalog.MasterData.update({'_id':data['_id']}, {'$set' : {'available_price':lowestPrice,'updatedOn':to_java_date(now),'priceUpdatedOn':to_java_date(now),'in_stock':inStock}}, multi=True)
|
| 16024 |
kshitij.so |
139 |
get_mongo_connection().Catalog.Deals.update({'_id':data['_id']}, {'$set' : {'available_price':lowestPrice , 'in_stock':inStock,'dealType':data['dealType'],'codAvailable':data['codAvailable']}}, multi=True)
|
| 13829 |
kshitij.so |
140 |
else:
|
| 13929 |
kshitij.so |
141 |
lowestPrice = data['available_price']
|
| 13977 |
kshitij.so |
142 |
get_mongo_connection().Catalog.MasterData.update({'_id':data['_id']}, {'$set' : {'updatedOn':to_java_date(now),'in_stock':0,'priceUpdatedOn':to_java_date(now)}}, multi=True)
|
| 16024 |
kshitij.so |
143 |
get_mongo_connection().Catalog.Deals.update({'_id':data['_id']}, {'$set' : {'in_stock':0,'dealType':data['dealType'],'codAvailable':data['codAvailable']}}, multi=True)
|
| 13918 |
kshitij.so |
144 |
|
| 16117 |
kshitij.so |
145 |
return {'_id':data['_id'],'available_price':lowestPrice,'in_stock':inStock,'source_id':1,'source_product_name':data['source_product_name'],'marketPlaceUrl':data['marketPlaceUrl'],'thumbnail':data['thumbnail'], 'coupon':data['coupon'], 'codAvailable':data['codAvailable'], 'tagline': data['tagline'], 'offer': data['offer']}
|
| 14834 |
kshitij.so |
146 |
except Exception as e:
|
|
|
147 |
print "Exception for _id %d and source %s"%(data['_id'], source_id)
|
|
|
148 |
print e
|
| 16117 |
kshitij.so |
149 |
return {'_id':data['_id'],'available_price':data['available_price'],'in_stock':data['in_stock'],'source_id':1,'source_product_name':data['source_product_name'],'marketPlaceUrl':data['marketPlaceUrl'],'thumbnail':data['thumbnail'], 'coupon':data['coupon'], 'codAvailable':data['codAvailable'], 'tagline': data['tagline'], 'offer': data['offer']}
|
| 13829 |
kshitij.so |
150 |
|
| 14203 |
kshitij.so |
151 |
elif source_id ==4:
|
| 14207 |
kshitij.so |
152 |
|
| 14203 |
kshitij.so |
153 |
try:
|
| 14212 |
kshitij.so |
154 |
if data['identifier'] is None or len(data['identifier'].strip())==0:
|
|
|
155 |
return {}
|
|
|
156 |
|
| 16500 |
kshitij.so |
157 |
if data.get('ignorePricing') ==1:
|
| 18739 |
kshitij.so |
158 |
return {'_id':data['_id'],'available_price':data['available_price'],'in_stock':data['in_stock'],'source_id':4,'source_product_name':data['source_product_name'],'marketPlaceUrl':data['marketPlaceUrl'],'thumbnail':data['thumbnail'], 'coupon':data['coupon'], 'codAvailable':data['codAvailable'], 'tagline': data['tagline'], 'offer': data['offer'], 'packQuantity':data['quantity']}
|
| 16500 |
kshitij.so |
159 |
|
| 18722 |
kshitij.so |
160 |
# try:
|
|
|
161 |
# if ignoreLastUpdated and data['priceUpdatedOn'] > to_java_date(now - timedelta(minutes=5)):
|
|
|
162 |
# print "sku id is already updated",data['_id']
|
|
|
163 |
# return {'_id':data['_id'],'available_price':data['available_price'],'in_stock':data['in_stock'],'source_id':4,'source_product_name':data['source_product_name'],'marketPlaceUrl':data['marketPlaceUrl'],'thumbnail':data['thumbnail'], 'coupon':data['coupon'], 'codAvailable':data['codAvailable'], 'tagline': data['tagline'], 'offer': data['offer']}
|
|
|
164 |
# except:
|
|
|
165 |
# pass
|
|
|
166 |
#
|
|
|
167 |
url = "http://"+saholicPricingHost+":8080/mobileapi/dtr-pricing?id=%s"%(data['identifier'])
|
| 14212 |
kshitij.so |
168 |
lowestPrice = 0.0
|
|
|
169 |
instock = 0
|
|
|
170 |
req = urllib2.Request(url,headers=headers)
|
|
|
171 |
response = urllib2.urlopen(req)
|
|
|
172 |
json_input = response.read()
|
|
|
173 |
response.close()
|
|
|
174 |
priceInfo = json.loads(json_input)
|
| 17456 |
kshitij.so |
175 |
print "PriceInfo ",data['identifier']
|
|
|
176 |
print priceInfo
|
| 14212 |
kshitij.so |
177 |
lowestPrice = priceInfo['response']['sellingPrice']
|
| 18722 |
kshitij.so |
178 |
cheapestBulkPrice = None
|
|
|
179 |
try:
|
|
|
180 |
bulkPricing = priceInfo['response']['bulkPricing']
|
|
|
181 |
for k,v in bulkPricing.iteritems():
|
|
|
182 |
if cheapestBulkPrice is None:
|
|
|
183 |
cheapestBulkPrice = v
|
|
|
184 |
continue
|
|
|
185 |
if cheapestBulkPrice > v:
|
|
|
186 |
cheapestBulkPrice = v
|
|
|
187 |
except:
|
|
|
188 |
cheapestBulkPrice = 0
|
|
|
189 |
|
| 14212 |
kshitij.so |
190 |
if lowestPrice > 0:
|
|
|
191 |
instock = 1
|
|
|
192 |
if instock == 1:
|
|
|
193 |
get_mongo_connection().Catalog.MasterData.update({'_id':data['_id']}, {'$set' : {'available_price':lowestPrice,'updatedOn':to_java_date(now),'priceUpdatedOn':to_java_date(now),'in_stock':instock}}, multi=True)
|
| 16024 |
kshitij.so |
194 |
get_mongo_connection().Catalog.Deals.update({'_id':data['_id']}, {'$set' : {'available_price':lowestPrice , 'in_stock':instock,'codAvailable':data['codAvailable']}}, multi=True)
|
| 14212 |
kshitij.so |
195 |
else:
|
|
|
196 |
lowestPrice = data['available_price']
|
|
|
197 |
get_mongo_connection().Catalog.MasterData.update({'_id':data['_id']}, {'$set' : {'updatedOn':to_java_date(now),'in_stock':instock,'priceUpdatedOn':to_java_date(now)}}, multi=True)
|
| 16024 |
kshitij.so |
198 |
get_mongo_connection().Catalog.Deals.update({'_id':data['_id']}, {'$set' : {'in_stock':instock,'codAvailable':data['codAvailable']}}, multi=True)
|
| 14212 |
kshitij.so |
199 |
|
| 18739 |
kshitij.so |
200 |
return {'_id':data['_id'],'available_price':lowestPrice,'in_stock':instock,'source_id':4,'source_product_name':data['source_product_name'],'marketPlaceUrl':data['marketPlaceUrl'],'thumbnail':data['thumbnail'],'coupon':data['coupon'], 'codAvailable':data['codAvailable'],'tagline': data['tagline'], 'offer': data['offer'], 'cheapestBulkPrice': cheapestBulkPrice, 'packQuantity':data['quantity']}
|
| 14834 |
kshitij.so |
201 |
|
|
|
202 |
except Exception as e:
|
|
|
203 |
print "Exception for _id %d and source %s"%(data['_id'], source_id)
|
|
|
204 |
print e
|
| 18739 |
kshitij.so |
205 |
return {'_id':data['_id'],'available_price':data['available_price'],'in_stock':data['in_stock'],'source_id':4,'source_product_name':data['source_product_name'],'marketPlaceUrl':data['marketPlaceUrl'],'thumbnail':data['thumbnail'],'coupon':data['coupon'], 'codAvailable':data['codAvailable'],'tagline': data['tagline'], 'offer': data['offer'],'packQuantity':data['quantity']}
|
| 14203 |
kshitij.so |
206 |
|
| 14207 |
kshitij.so |
207 |
|
| 13829 |
kshitij.so |
208 |
elif source_id ==3:
|
|
|
209 |
try:
|
| 13918 |
kshitij.so |
210 |
if data['identifier'] is None or len(data['identifier'].strip())==0:
|
| 13829 |
kshitij.so |
211 |
return {}
|
| 13918 |
kshitij.so |
212 |
|
| 16500 |
kshitij.so |
213 |
if data.get('ignorePricing') ==1:
|
| 16206 |
kshitij.so |
214 |
print "Ignored items returning for %d"%(data['_id'])
|
| 16265 |
kshitij.so |
215 |
return {'_id':data['_id'],'available_price':data['available_price'],'in_stock':data['in_stock'],'source_id':3,'source_product_name':data['source_product_name'],'marketPlaceUrl':data['marketPlaceUrl'],'thumbnail':data['thumbnail'],'coupon':data['coupon'], 'codAvailable':data['codAvailable'], 'tagline': data['tagline'], 'offer': data['offer']}
|
| 16206 |
kshitij.so |
216 |
|
| 13918 |
kshitij.so |
217 |
try:
|
| 14828 |
kshitij.so |
218 |
if ignoreLastUpdated and data['priceUpdatedOn'] > to_java_date(now - timedelta(minutes=5)):
|
| 13920 |
kshitij.so |
219 |
print "sku id is already updated",data['_id']
|
| 16205 |
kshitij.so |
220 |
return {'_id':data['_id'],'available_price':data['available_price'],'in_stock':data['in_stock'],'source_id':3,'source_product_name':data['source_product_name'],'marketPlaceUrl':data['marketPlaceUrl'],'thumbnail':data['thumbnail'],'coupon':data['coupon'], 'codAvailable':data['codAvailable'],'tagline': data['tagline'], 'offer': data['offer']}
|
| 13919 |
kshitij.so |
221 |
|
|
|
222 |
except Exception as e:
|
| 13920 |
kshitij.so |
223 |
print "Exception snapdeal"
|
| 13919 |
kshitij.so |
224 |
print e
|
| 13918 |
kshitij.so |
225 |
|
| 17295 |
kshitij.so |
226 |
url="http://www.snapdeal.com/acors/json/v2/gvbps?supc=%s&catUrl=&bn=&catId=175&start=0&count=10000&scoreCategoryUrl=mobiles-mobile-phones&make2Order=false&auto=false&isO2OVendorRequired=true"%(data['identifier'])
|
| 13829 |
kshitij.so |
227 |
req = urllib2.Request(url,headers=headers)
|
|
|
228 |
response = urllib2.urlopen(req)
|
| 16065 |
kshitij.so |
229 |
snapdeal_data = response.read()
|
|
|
230 |
encoding = chardet.detect(snapdeal_data)
|
|
|
231 |
try:
|
|
|
232 |
snapdeal_data = snapdeal_data.decode(encoding.get('encoding'))
|
|
|
233 |
except:
|
|
|
234 |
snapdeal_data = snapdeal_data.decode(encoding.get('latin-1'))
|
|
|
235 |
vendorInfo = json.loads(snapdeal_data)
|
| 14188 |
kshitij.so |
236 |
response.close()
|
| 13829 |
kshitij.so |
237 |
lowestOfferPrice = 0
|
|
|
238 |
inStock = 0
|
| 15253 |
kshitij.so |
239 |
buyBoxPrice = 0
|
|
|
240 |
isBuyBox = 1
|
| 15819 |
kshitij.so |
241 |
try:
|
|
|
242 |
buyBoxStock = vendorInfo['primaryVendor']['buyableInventory']
|
|
|
243 |
if buyBoxStock >0:
|
|
|
244 |
buyBoxPrice = vendorInfo['primaryVendor']['sellingPrice']
|
|
|
245 |
except:
|
|
|
246 |
pass
|
|
|
247 |
sortedVendorsData = sorted(vendorInfo['vendors'], key=itemgetter('sellingPrice'))
|
| 15253 |
kshitij.so |
248 |
for sortedVendorData in sortedVendorsData:
|
|
|
249 |
lowestOfferPrice = float(sortedVendorData['sellingPrice'])
|
|
|
250 |
try:
|
|
|
251 |
stock = sortedVendorData['buyableInventory']
|
|
|
252 |
except:
|
|
|
253 |
stock = 0
|
| 13829 |
kshitij.so |
254 |
if stock > 0 and lowestOfferPrice > 0:
|
|
|
255 |
inStock = 1
|
|
|
256 |
break
|
|
|
257 |
|
|
|
258 |
print lowestOfferPrice
|
|
|
259 |
print inStock
|
|
|
260 |
print "*************"
|
| 15253 |
kshitij.so |
261 |
|
|
|
262 |
if buyBoxPrice != lowestOfferPrice:
|
|
|
263 |
isBuyBox = 0
|
|
|
264 |
|
| 13829 |
kshitij.so |
265 |
if inStock == 1:
|
| 15253 |
kshitij.so |
266 |
get_mongo_connection().Catalog.MasterData.update({'_id':data['_id']}, {'$set' : {'available_price':lowestOfferPrice,'updatedOn':to_java_date(now),'priceUpdatedOn':to_java_date(now),'in_stock':inStock,'buyBoxFlag':isBuyBox}}, multi=True)
|
| 16024 |
kshitij.so |
267 |
get_mongo_connection().Catalog.Deals.update({'_id':data['_id']}, {'$set' : {'available_price':lowestOfferPrice , 'in_stock':inStock,'codAvailable':data['codAvailable']}}, multi=True)
|
| 13829 |
kshitij.so |
268 |
else:
|
| 13929 |
kshitij.so |
269 |
lowestOfferPrice = data['available_price']
|
| 15253 |
kshitij.so |
270 |
get_mongo_connection().Catalog.MasterData.update({'_id':data['_id']}, {'$set' : {'updatedOn':to_java_date(now),'in_stock':inStock,'priceUpdatedOn':to_java_date(now),'buyBoxFlag':isBuyBox}}, multi=True)
|
| 16024 |
kshitij.so |
271 |
get_mongo_connection().Catalog.Deals.update({'_id':data['_id']}, {'$set' : {'in_stock':inStock,'codAvailable':data['codAvailable']}}, multi=True)
|
| 13918 |
kshitij.so |
272 |
|
| 16117 |
kshitij.so |
273 |
return {'_id':data['_id'],'available_price':lowestOfferPrice,'in_stock':inStock,'source_id':3,'source_product_name':data['source_product_name'],'marketPlaceUrl':data['marketPlaceUrl'],'thumbnail':data['thumbnail'],'coupon':data['coupon'], 'codAvailable':data['codAvailable'], 'tagline': data['tagline'], 'offer': data['offer']}
|
| 14834 |
kshitij.so |
274 |
except Exception as e:
|
| 15266 |
kshitij.so |
275 |
print traceback.print_exc()
|
| 14834 |
kshitij.so |
276 |
print "Exception for _id %d and source %s"%(data['_id'], source_id)
|
|
|
277 |
print e
|
| 16117 |
kshitij.so |
278 |
return {'_id':data['_id'],'available_price':data['available_price'],'in_stock':data['in_stock'],'source_id':3,'source_product_name':data['source_product_name'],'marketPlaceUrl':data['marketPlaceUrl'],'thumbnail':data['thumbnail'],'coupon':data['coupon'], 'codAvailable':data['codAvailable'], 'tagline': data['tagline'], 'offer': data['offer']}
|
| 13829 |
kshitij.so |
279 |
|
|
|
280 |
elif source_id == 2:
|
|
|
281 |
try:
|
| 13918 |
kshitij.so |
282 |
if data['identifier'] is None or len(data['identifier'].strip())==0:
|
| 13829 |
kshitij.so |
283 |
return {}
|
| 13918 |
kshitij.so |
284 |
|
| 16500 |
kshitij.so |
285 |
if data.get('ignorePricing') ==1:
|
| 15608 |
kshitij.so |
286 |
print "Ignored items returning for %d"%(data['_id'])
|
| 16117 |
kshitij.so |
287 |
return {'_id':data['_id'],'available_price':data['available_price'],'in_stock':data['in_stock'],'source_id':2,'source_product_name':data['source_product_name'],'marketPlaceUrl':data['marketPlaceUrl'],'thumbnail':data['thumbnail'],'coupon':data['coupon'], 'codAvailable':data['codAvailable'], 'tagline': data['tagline'], 'offer': data['offer']}
|
| 15608 |
kshitij.so |
288 |
|
| 13918 |
kshitij.so |
289 |
try:
|
| 14828 |
kshitij.so |
290 |
if ignoreLastUpdated and data['priceUpdatedOn'] > to_java_date(now - timedelta(minutes=5)):
|
| 13918 |
kshitij.so |
291 |
print "sku id is already updated",data['_id']
|
| 16117 |
kshitij.so |
292 |
return {'_id':data['_id'],'available_price':data['available_price'],'in_stock':data['in_stock'],'source_id':2,'source_product_name':data['source_product_name'],'marketPlaceUrl':data['marketPlaceUrl'],'thumbnail':data['thumbnail'],'coupon':data['coupon'], 'codAvailable':data['codAvailable'], 'tagline': data['tagline'], 'offer': data['offer']}
|
| 13918 |
kshitij.so |
293 |
except:
|
|
|
294 |
pass
|
|
|
295 |
|
|
|
296 |
lowestSp = 0
|
|
|
297 |
inStock = 0
|
| 15253 |
kshitij.so |
298 |
buyBoxPrice = 0
|
|
|
299 |
isBuyBox = 0
|
| 14189 |
kshitij.so |
300 |
scraperProductPage = NewFlipkartScraper.FlipkartProductPageScraper()
|
| 14121 |
kshitij.so |
301 |
try:
|
| 17262 |
kshitij.so |
302 |
result = scraperProductPage.read(data['identifier'])
|
|
|
303 |
print result
|
|
|
304 |
if result.get('lowestSp')!=0:
|
|
|
305 |
lowestSp = result.get('lowestSp')
|
|
|
306 |
inStock = result.get('inStock')
|
|
|
307 |
buyBoxPrice = result.get('buyBoxPrice')
|
| 14121 |
kshitij.so |
308 |
except:
|
|
|
309 |
print "Unable to scrape product page ",data['identifier']
|
| 13829 |
kshitij.so |
310 |
print lowestSp
|
|
|
311 |
print inStock
|
| 15253 |
kshitij.so |
312 |
if buyBoxPrice is not None and buyBoxPrice == lowestSp:
|
|
|
313 |
isBuyBox = 1
|
| 13829 |
kshitij.so |
314 |
if lowestSp > 0:
|
| 15253 |
kshitij.so |
315 |
get_mongo_connection().Catalog.MasterData.update({'_id':data['_id']}, {'$set' : {'available_price':lowestSp,'updatedOn':to_java_date(now),'priceUpdatedOn':to_java_date(now),'in_stock':inStock,'buyBoxFlag':isBuyBox}}, multi=True)
|
| 16024 |
kshitij.so |
316 |
get_mongo_connection().Catalog.Deals.update({'_id':data['_id']}, {'$set' : {'available_price':lowestSp , 'in_stock':inStock,'codAvailable':data['codAvailable']}}, multi=True)
|
| 13829 |
kshitij.so |
317 |
else:
|
| 13929 |
kshitij.so |
318 |
lowestSp = data['available_price']
|
| 15253 |
kshitij.so |
319 |
get_mongo_connection().Catalog.MasterData.update({'_id':data['_id']}, {'$set' : {'updatedOn':to_java_date(now),'in_stock':inStock,'priceUpdatedOn':to_java_date(now),'buyBoxFlag':isBuyBox}}, multi=True)
|
| 16024 |
kshitij.so |
320 |
get_mongo_connection().Catalog.Deals.update({'_id':data['_id']}, {'$set' : {'in_stock':inStock,'codAvailable':data['codAvailable']}}, multi=True)
|
| 13918 |
kshitij.so |
321 |
|
| 16117 |
kshitij.so |
322 |
return {'_id':data['_id'],'available_price':lowestSp,'in_stock':inStock,'source_id':2,'source_product_name':data['source_product_name'],'marketPlaceUrl':data['marketPlaceUrl'],'thumbnail':data['thumbnail'],'coupon':data['coupon'], 'codAvailable':data['codAvailable'], 'tagline': data['tagline'], 'offer': data['offer']}
|
| 14342 |
kshitij.so |
323 |
|
| 14834 |
kshitij.so |
324 |
except Exception as e:
|
|
|
325 |
print "Exception for _id %d and source %s"%(data['_id'], source_id)
|
|
|
326 |
print e
|
| 16117 |
kshitij.so |
327 |
return {'_id':data['_id'],'available_price':data['available_price'],'in_stock':data['in_stock'],'source_id':2,'source_product_name':data['source_product_name'],'marketPlaceUrl':data['marketPlaceUrl'],'thumbnail':data['thumbnail'],'coupon':data['coupon'], 'codAvailable':data['codAvailable'], 'tagline': data['tagline'], 'offer': data['offer']}
|
| 15902 |
kshitij.so |
328 |
|
|
|
329 |
elif source_id == 5:
|
|
|
330 |
try:
|
| 16500 |
kshitij.so |
331 |
if data.get('ignorePricing') ==1:
|
| 15902 |
kshitij.so |
332 |
print "Ignored items returning for %d"%(data['_id'])
|
| 16117 |
kshitij.so |
333 |
return {'_id':data['_id'],'available_price':data['available_price'],'in_stock':data['in_stock'],'source_id':5,'source_product_name':data['source_product_name'],'marketPlaceUrl':data['marketPlaceUrl'],'thumbnail':data['thumbnail'],'coupon':data['coupon'], 'codAvailable':data['codAvailable'], 'tagline': data['tagline'], 'offer': data['offer']}
|
| 15902 |
kshitij.so |
334 |
|
|
|
335 |
try:
|
|
|
336 |
if ignoreLastUpdated and data['priceUpdatedOn'] > to_java_date(now - timedelta(minutes=5)):
|
|
|
337 |
print "sku id is already updated",data['_id']
|
| 16117 |
kshitij.so |
338 |
return {'_id':data['_id'],'available_price':data['available_price'],'in_stock':data['in_stock'],'source_id':5,'source_product_name':data['source_product_name'],'marketPlaceUrl':data['marketPlaceUrl'],'thumbnail':data['thumbnail'],'coupon':data['coupon'], 'codAvailable':data['codAvailable'], 'tagline': data['tagline'], 'offer': data['offer']}
|
| 15902 |
kshitij.so |
339 |
except:
|
|
|
340 |
pass
|
|
|
341 |
|
|
|
342 |
|
|
|
343 |
url = data['marketPlaceUrl']
|
|
|
344 |
lowestPrice = 0.0
|
|
|
345 |
try:
|
|
|
346 |
sc = ShopCluesScraper.ShopCluesScraper()
|
| 15951 |
kshitij.so |
347 |
url = transformUrl(url, 5)
|
| 15902 |
kshitij.so |
348 |
productInfo = sc.read(url)
|
|
|
349 |
except Exception as e:
|
| 16177 |
kshitij.so |
350 |
traceback.print_exc()
|
| 16176 |
kshitij.so |
351 |
productInfo = {}
|
| 16022 |
kshitij.so |
352 |
productInfo['price'] = 0.0
|
|
|
353 |
productInfo['inStock'] = 0
|
|
|
354 |
productInfo['isCod'] = 0
|
| 16178 |
kshitij.so |
355 |
productInfo['coupon'] = ""
|
| 16022 |
kshitij.so |
356 |
|
| 15902 |
kshitij.so |
357 |
print "LowestPrice ",productInfo['price']
|
|
|
358 |
if productInfo['price'] > 0 and productInfo['inStock']==1:
|
|
|
359 |
get_mongo_connection().Catalog.MasterData.update({'_id':data['_id']}, {'$set' : {'available_price':productInfo['price'],'coupon':productInfo['coupon'],'codAvailable':productInfo['isCod'],'updatedOn':to_java_date(now),'priceUpdatedOn':to_java_date(now),'in_stock':productInfo['inStock']}})
|
| 16024 |
kshitij.so |
360 |
get_mongo_connection().Catalog.Deals.update({'_id':data['_id']}, {'$set' : {'available_price':productInfo['price'] , 'in_stock':productInfo['inStock'],'dealType':data['dealType'], 'rank':data['rank'],'codAvailable':productInfo['isCod']}})
|
| 15902 |
kshitij.so |
361 |
else:
|
|
|
362 |
lowestPrice = data['available_price']
|
|
|
363 |
get_mongo_connection().Catalog.MasterData.update({'_id':data['_id']}, {'$set' : {'updatedOn':to_java_date(now),'in_stock':0,'priceUpdatedOn':to_java_date(now)}})
|
| 16024 |
kshitij.so |
364 |
get_mongo_connection().Catalog.Deals.update({'_id':data['_id']}, {'$set' : {'in_stock':0,'dealType':data['dealType'],'rank':data['rank'],'codAvailable':productInfo['isCod']}})
|
| 15902 |
kshitij.so |
365 |
|
| 16117 |
kshitij.so |
366 |
return {'_id':data['_id'],'available_price':productInfo['price'],'in_stock':productInfo['inStock'],'source_id':5,'source_product_name':data['source_product_name'],'marketPlaceUrl':data['marketPlaceUrl'],'thumbnail':data['thumbnail'], 'coupon':productInfo['coupon'],'codAvailable':productInfo['isCod'], 'tagline': data['tagline'], 'offer': data['offer']}
|
| 15902 |
kshitij.so |
367 |
except Exception as e:
|
|
|
368 |
print "Exception for _id %d and source %s"%(data['_id'], source_id)
|
| 16177 |
kshitij.so |
369 |
traceback.print_exc()
|
| 16117 |
kshitij.so |
370 |
return {'_id':data['_id'],'available_price':data['available_price'],'in_stock':data['in_stock'],'source_id':5,'source_product_name':data['source_product_name'],'marketPlaceUrl':data['marketPlaceUrl'],'thumbnail':data['thumbnail'],'coupon':data['coupon'], 'codAvailable':data['codAvailable'], 'tagline': data['tagline'], 'offer': data['offer']}
|
| 16410 |
kshitij.so |
371 |
|
|
|
372 |
elif source_id == 6:
|
|
|
373 |
try:
|
| 16500 |
kshitij.so |
374 |
if data.get('ignorePricing') ==1:
|
| 16410 |
kshitij.so |
375 |
print "Ignored items returning for %d"%(data['_id'])
|
| 16491 |
kshitij.so |
376 |
return {'_id':data['_id'],'available_price':data['available_price'],'in_stock':data['in_stock'],'source_id':6,'source_product_name':data['source_product_name'],'marketPlaceUrl':data['marketPlaceUrl'],'thumbnail':data['thumbnail'],'coupon':data['coupon'], 'codAvailable':data['codAvailable'], 'tagline': data['tagline'], 'offer': data['offer'],'gross_price':data.get('gross_price')}
|
| 16410 |
kshitij.so |
377 |
|
|
|
378 |
try:
|
|
|
379 |
if ignoreLastUpdated and data['priceUpdatedOn'] > to_java_date(now - timedelta(minutes=5)):
|
|
|
380 |
print "sku id is already updated",data['_id']
|
| 16491 |
kshitij.so |
381 |
return {'_id':data['_id'],'available_price':data['available_price'],'in_stock':data['in_stock'],'source_id':6,'source_product_name':data['source_product_name'],'marketPlaceUrl':data['marketPlaceUrl'],'thumbnail':data['thumbnail'],'coupon':data['coupon'], 'codAvailable':data['codAvailable'], 'tagline': data['tagline'], 'offer': data['offer'],'gross_price':data.get('gross_price')}
|
| 16410 |
kshitij.so |
382 |
except:
|
|
|
383 |
pass
|
|
|
384 |
|
|
|
385 |
paytmScraper = PaytmScraper.PaytmScraper()
|
|
|
386 |
url = "https://catalog.paytm.com/v1/mobile/product/%s"%(data['identifier'].strip())
|
|
|
387 |
try:
|
|
|
388 |
result = paytmScraper.read(url)
|
| 18282 |
kshitij.so |
389 |
print result
|
| 16410 |
kshitij.so |
390 |
effective_price = result.get('offerPrice')
|
| 16462 |
kshitij.so |
391 |
gross_price = effective_price
|
| 18282 |
kshitij.so |
392 |
shareUrl = result.get('shareUrl')
|
|
|
393 |
if shareUrl is None:
|
|
|
394 |
shareUrl = data['marketPlaceUrl']
|
| 16410 |
kshitij.so |
395 |
coupon = ""
|
|
|
396 |
try:
|
|
|
397 |
offers = PaytmOfferScraper.fetchOffers(result['offerUrl'])
|
| 16415 |
kshitij.so |
398 |
try:
|
|
|
399 |
addToPaytmMaster(offers.get('codes'))
|
|
|
400 |
except:
|
|
|
401 |
print "Error in adding coupon"
|
|
|
402 |
traceback.print_exc()
|
| 16410 |
kshitij.so |
403 |
bestOffer = {}
|
|
|
404 |
for offer_data in offers.get('codes'):
|
| 16415 |
kshitij.so |
405 |
if effective_price > offer_data.get('effective_price'):
|
| 16410 |
kshitij.so |
406 |
effective_price = offer_data.get('effective_price')
|
|
|
407 |
bestOffer = offer_data
|
|
|
408 |
coupon = bestOffer.get('code')
|
|
|
409 |
except:
|
|
|
410 |
pass
|
| 16469 |
kshitij.so |
411 |
|
|
|
412 |
"""Temp fix"""
|
|
|
413 |
if len(coupon) > 0:
|
|
|
414 |
result['codAvailable'] = 0
|
|
|
415 |
|
| 16410 |
kshitij.so |
416 |
available_price = effective_price
|
|
|
417 |
if result['inStock']:
|
|
|
418 |
inStock = 1
|
| 18282 |
kshitij.so |
419 |
get_mongo_connection().Catalog.MasterData.update({'_id':data['_id']}, {'$set' : {'available_price':available_price,'updatedOn':to_java_date(datetime.now()),'priceUpdatedOn':to_java_date(datetime.now()),'in_stock':1,'buyBoxFlag':1,'codAvailable':result.get('codAvailable'),'coupon':coupon,'gross_price':gross_price,'marketPlaceUrl':shareUrl}})
|
| 16462 |
kshitij.so |
420 |
get_mongo_connection().Catalog.Deals.update({'_id':data['_id']}, {'$set' : {'available_price':available_price , 'in_stock':1,'codAvailable':result.get('codAvailable'),'gross_price':gross_price}})
|
| 16410 |
kshitij.so |
421 |
else:
|
|
|
422 |
inStock = 0
|
| 18282 |
kshitij.so |
423 |
get_mongo_connection().Catalog.MasterData.update({'_id':data['_id']}, {'$set' : {'updatedOn':to_java_date(datetime.now()),'in_stock':0,'priceUpdatedOn':to_java_date(datetime.now()),'buyBoxFlag':1,'codAvailable':result.get('codAvailable'),'coupon':coupon,'marketPlaceUrl':shareUrl}})
|
| 16415 |
kshitij.so |
424 |
get_mongo_connection().Catalog.Deals.update({'_id':data['_id']}, {'$set' : {'in_stock':0,'codAvailable':result.get('codAvailable')}})
|
| 16410 |
kshitij.so |
425 |
|
|
|
426 |
except:
|
|
|
427 |
inStock = 0
|
|
|
428 |
get_mongo_connection().Catalog.MasterData.update({'_id':data['_id']}, {'$set' : {'updatedOn':to_java_date(datetime.now()),'in_stock':0,'priceUpdatedOn':to_java_date(datetime.now()),'buyBoxFlag':1}})
|
|
|
429 |
get_mongo_connection().Catalog.Deals.update({'_id':data['_id']}, {'$set' : {'in_stock':0}})
|
|
|
430 |
|
|
|
431 |
|
| 18282 |
kshitij.so |
432 |
return {'_id':data['_id'],'available_price':available_price,'in_stock':inStock,'source_id':6,'source_product_name':data['source_product_name'],'marketPlaceUrl':shareUrl,'thumbnail':data['thumbnail'], 'coupon':coupon,'codAvailable':result['codAvailable'], 'tagline': data['tagline'], 'offer': data['offer'],'gross_price':gross_price}
|
| 16410 |
kshitij.so |
433 |
except Exception as e:
|
|
|
434 |
print "Exception for _id %d and source %s"%(data['_id'], source_id)
|
|
|
435 |
traceback.print_exc()
|
| 16462 |
kshitij.so |
436 |
return {'_id':data['_id'],'available_price':data['available_price'],'in_stock':data['in_stock'],'source_id':6,'source_product_name':data['source_product_name'],'marketPlaceUrl':data['marketPlaceUrl'],'thumbnail':data['thumbnail'],'coupon':data['coupon'], 'codAvailable':data['codAvailable'], 'tagline': data['tagline'], 'offer': data['offer'],'gross_price':data.get('gross_price')}
|
| 17013 |
manish.sha |
437 |
|
|
|
438 |
elif source_id ==7:
|
|
|
439 |
try:
|
|
|
440 |
if data['identifier'] is None or len(data['identifier'].strip())==0:
|
|
|
441 |
return {}
|
|
|
442 |
|
|
|
443 |
if data.get('ignorePricing') ==1:
|
|
|
444 |
print "Ignored items returning for %d"%(data['_id'])
|
|
|
445 |
return {'_id':data['_id'],'available_price':data['available_price'],'in_stock':data['in_stock'],'source_id':7,'source_product_name':data['source_product_name'],'marketPlaceUrl':data['marketPlaceUrl'],'thumbnail':data['thumbnail'],'coupon':data['coupon'], 'codAvailable':data['codAvailable'], 'tagline': data['tagline'], 'offer': data['offer']}
|
|
|
446 |
|
|
|
447 |
try:
|
|
|
448 |
if ignoreLastUpdated and data['priceUpdatedOn'] > to_java_date(now - timedelta(minutes=5)):
|
|
|
449 |
print "sku id is already updated",data['_id']
|
|
|
450 |
return {'_id':data['_id'],'available_price':data['available_price'],'in_stock':data['in_stock'],'source_id':7,'source_product_name':data['source_product_name'],'marketPlaceUrl':data['marketPlaceUrl'],'thumbnail':data['thumbnail'],'coupon':data['coupon'], 'codAvailable':data['codAvailable'],'tagline': data['tagline'], 'offer': data['offer']}
|
|
|
451 |
|
|
|
452 |
except Exception as e:
|
|
|
453 |
print "Exception snapdeal"
|
|
|
454 |
print e
|
|
|
455 |
|
|
|
456 |
response = None
|
|
|
457 |
|
|
|
458 |
try:
|
| 17043 |
kshitij.so |
459 |
scraper = HomeShop18Scraper.HomeShop18Scraper()
|
| 17013 |
manish.sha |
460 |
response = scraper.read('http://m.homeshop18.com/product.mobi?productId=%s'%(str(data['identifier'])))
|
|
|
461 |
except Exception as e:
|
|
|
462 |
print e
|
| 17043 |
kshitij.so |
463 |
scraper = HomeShop18Scraper.HomeShop18Scraper()
|
| 17013 |
manish.sha |
464 |
response = scraper.read('http://m.homeshop18.com/product.mobi?productId=%s'%(str(data['identifier'])))
|
|
|
465 |
|
|
|
466 |
lowestOfferPrice = 0
|
|
|
467 |
inStock = 0
|
|
|
468 |
|
|
|
469 |
if response is not None:
|
| 17043 |
kshitij.so |
470 |
lowestOfferPrice = float(response['price']+response['shippingCharge'])
|
| 17013 |
manish.sha |
471 |
inStock = response['inStock']
|
|
|
472 |
|
|
|
473 |
print lowestOfferPrice
|
|
|
474 |
print inStock
|
|
|
475 |
print "*************"
|
|
|
476 |
|
| 17036 |
kshitij.so |
477 |
if lowestOfferPrice ==0:
|
|
|
478 |
inStock = 0
|
| 17013 |
manish.sha |
479 |
|
| 17036 |
kshitij.so |
480 |
|
| 17013 |
manish.sha |
481 |
if inStock == 1:
|
| 17036 |
kshitij.so |
482 |
get_mongo_connection().Catalog.MasterData.update({'_id':data['_id']}, {'$set' : {'available_price':lowestOfferPrice,'updatedOn':to_java_date(now),'priceUpdatedOn':to_java_date(now),'in_stock':inStock}}, multi=True)
|
| 17013 |
manish.sha |
483 |
get_mongo_connection().Catalog.Deals.update({'_id':data['_id']}, {'$set' : {'available_price':lowestOfferPrice , 'in_stock':inStock,'codAvailable':data['codAvailable']}}, multi=True)
|
|
|
484 |
else:
|
|
|
485 |
lowestOfferPrice = data['available_price']
|
| 17036 |
kshitij.so |
486 |
get_mongo_connection().Catalog.MasterData.update({'_id':data['_id']}, {'$set' : {'updatedOn':to_java_date(now),'in_stock':inStock,'priceUpdatedOn':to_java_date(now)}}, multi=True)
|
| 17013 |
manish.sha |
487 |
get_mongo_connection().Catalog.Deals.update({'_id':data['_id']}, {'$set' : {'in_stock':inStock,'codAvailable':data['codAvailable']}}, multi=True)
|
|
|
488 |
|
|
|
489 |
return {'_id':data['_id'],'available_price':lowestOfferPrice,'in_stock':inStock,'source_id':7,'source_product_name':data['source_product_name'],'marketPlaceUrl':data['marketPlaceUrl'],'thumbnail':data['thumbnail'],'coupon':data['coupon'], 'codAvailable':data['codAvailable'], 'tagline': data['tagline'], 'offer': data['offer']}
|
|
|
490 |
except Exception as e:
|
|
|
491 |
print traceback.print_exc()
|
|
|
492 |
print "Exception for _id %d and source %s"%(data['_id'], source_id)
|
|
|
493 |
print e
|
|
|
494 |
return {'_id':data['_id'],'available_price':data['available_price'],'in_stock':data['in_stock'],'source_id':7,'source_product_name':data['source_product_name'],'marketPlaceUrl':data['marketPlaceUrl'],'thumbnail':data['thumbnail'],'coupon':data['coupon'], 'codAvailable':data['codAvailable'], 'tagline': data['tagline'], 'offer': data['offer']}
|
| 15902 |
kshitij.so |
495 |
|
| 13829 |
kshitij.so |
496 |
else:
|
|
|
497 |
return {}
|
| 15902 |
kshitij.so |
498 |
|
|
|
499 |
|
| 13918 |
kshitij.so |
500 |
|
| 16498 |
kshitij.so |
501 |
def recomputePoints(deal):
|
| 15253 |
kshitij.so |
502 |
try:
|
| 16498 |
kshitij.so |
503 |
nlcPoints = getNlcPoints(deal)
|
| 15253 |
kshitij.so |
504 |
except:
|
| 16498 |
kshitij.so |
505 |
traceback.print_exc()
|
| 15253 |
kshitij.so |
506 |
nlcPoints = deal['nlcPoints']
|
| 16498 |
kshitij.so |
507 |
|
|
|
508 |
bundleDealPoints = list(get_mongo_connection().Catalog.DealPoints.find({'skuBundleId':deal['skuBundleId'],'startDate':{'$lte':to_java_date(datetime.now())},'endDate':{'$gte':to_java_date(datetime.now())}}))
|
|
|
509 |
if len(bundleDealPoints) > 0:
|
|
|
510 |
manualDealThresholdPrice = bundleDealPoints[0]['dealThresholdPrice']
|
|
|
511 |
dealPoints = bundleDealPoints[0]['dealPoints']
|
| 15253 |
kshitij.so |
512 |
else:
|
|
|
513 |
dealPoints = 0
|
| 16498 |
kshitij.so |
514 |
manualDealThresholdPrice = None
|
| 16508 |
kshitij.so |
515 |
|
|
|
516 |
if deal['available_price'] > manualDealThresholdPrice:
|
|
|
517 |
dealPoints = 0
|
|
|
518 |
|
| 16498 |
kshitij.so |
519 |
|
|
|
520 |
if dealPoints != deal['dealPoints'] or manualDealThresholdPrice != deal['manualDealThresholdPrice'] or nlcPoints != deal['nlcPoints']:
|
|
|
521 |
get_mongo_connection().Catalog.Deals.update({'_id':deal['_id']},{"$set":{'totalPoints':deal['totalPoints'] - deal['nlcPoints'] + nlcPoints - deal['dealPoints'] +dealPoints , 'nlcPoints': nlcPoints, 'dealPoints': dealPoints, 'manualDealThresholdPrice': manualDealThresholdPrice}})
|
| 15253 |
kshitij.so |
522 |
|
| 15266 |
kshitij.so |
523 |
|
|
|
524 |
def populateNegativeDeals():
|
|
|
525 |
negativeDeals = get_mongo_connection().Catalog.NegativeDeals.find().distinct('sku')
|
|
|
526 |
mc.set("negative_deals", negativeDeals, 600)
|
|
|
527 |
|
|
|
528 |
def recomputeDeal(item):
|
| 16017 |
kshitij.so |
529 |
|
| 13918 |
kshitij.so |
530 |
"""Lets recompute deal for this bundle"""
|
| 15266 |
kshitij.so |
531 |
print "Recomputing for bundleId",item.get('skuBundleId')
|
|
|
532 |
skuBundleId = item['skuBundleId']
|
| 13829 |
kshitij.so |
533 |
|
| 19153 |
kshitij.so |
534 |
similarItems = list(get_mongo_connection().Catalog.Deals.find({'skuBundleId':skuBundleId}).sort([('netPriceAfterCashBack',pymongo.ASCENDING)]))
|
| 13918 |
kshitij.so |
535 |
bestPrice = float("inf")
|
|
|
536 |
bestOne = None
|
|
|
537 |
bestSellerPoints = 0
|
|
|
538 |
toUpdate = []
|
| 16017 |
kshitij.so |
539 |
prepaidBestPrice = float("inf")
|
|
|
540 |
prepaidBestOne = None
|
|
|
541 |
prepaidBestSellerPoints = 0
|
| 13918 |
kshitij.so |
542 |
for similarItem in similarItems:
|
| 16498 |
kshitij.so |
543 |
try:
|
|
|
544 |
recomputePoints(similarItem)
|
|
|
545 |
except:
|
|
|
546 |
traceback.print_exc()
|
| 16017 |
kshitij.so |
547 |
if similarItem['codAvailable'] ==1:
|
|
|
548 |
if mc.get("negative_deals") is None:
|
|
|
549 |
populateNegativeDeals()
|
| 16172 |
kshitij.so |
550 |
if similarItem['in_stock'] == 0 or similarItem['_id'] in mc.get("negative_deals"):
|
| 16017 |
kshitij.so |
551 |
get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0, 'prepaidDeal':0 }})
|
|
|
552 |
continue
|
| 17674 |
kshitij.so |
553 |
if similarItem['source_id'] == SOURCE_MAP.get('SHOPCLUES.COM') and similarItem['rank']==0 and similarItem['category_id']!=6:
|
| 16017 |
kshitij.so |
554 |
get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0,'prepaidDeal':0 }})
|
|
|
555 |
continue
|
| 19153 |
kshitij.so |
556 |
if similarItem['netPriceAfterCashBack'] < bestPrice:
|
| 16017 |
kshitij.so |
557 |
bestOne = similarItem
|
| 19153 |
kshitij.so |
558 |
bestPrice = similarItem['netPriceAfterCashBack']
|
| 16017 |
kshitij.so |
559 |
bestSellerPoints = similarItem['bestSellerPoints']
|
| 19153 |
kshitij.so |
560 |
elif similarItem['netPriceAfterCashBack'] == bestPrice and bestSellerPoints < similarItem['bestSellerPoints']:
|
| 16017 |
kshitij.so |
561 |
bestOne = similarItem
|
| 19153 |
kshitij.so |
562 |
bestPrice = similarItem['netPriceAfterCashBack']
|
| 16017 |
kshitij.so |
563 |
bestSellerPoints = similarItem['bestSellerPoints']
|
|
|
564 |
else:
|
|
|
565 |
pass
|
| 13918 |
kshitij.so |
566 |
else:
|
| 16017 |
kshitij.so |
567 |
if mc.get("negative_deals") is None:
|
|
|
568 |
populateNegativeDeals()
|
| 16172 |
kshitij.so |
569 |
if similarItem['in_stock'] == 0 or similarItem['_id'] in mc.get("negative_deals"):
|
| 16017 |
kshitij.so |
570 |
get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0, 'prepaidDeal':0 }})
|
|
|
571 |
continue
|
| 17751 |
kshitij.so |
572 |
if similarItem['source_id'] == SOURCE_MAP.get('SHOPCLUES.COM') and similarItem['rank']==0 and similarItem['category_id']!=6:
|
| 16017 |
kshitij.so |
573 |
get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0,'prepaidDeal':0 }})
|
|
|
574 |
continue
|
| 19153 |
kshitij.so |
575 |
if similarItem['netPriceAfterCashBack'] < prepaidBestPrice:
|
| 16017 |
kshitij.so |
576 |
prepaidBestOne = similarItem
|
| 19153 |
kshitij.so |
577 |
prepaidBestPrice = similarItem['netPriceAfterCashBack']
|
| 16017 |
kshitij.so |
578 |
prepaidBestSellerPoints = similarItem['bestSellerPoints']
|
| 19153 |
kshitij.so |
579 |
elif similarItem['netPriceAfterCashBack'] == prepaidBestPrice and prepaidBestSellerPoints < similarItem['bestSellerPoints']:
|
| 16017 |
kshitij.so |
580 |
prepaidBestOne = similarItem
|
| 19153 |
kshitij.so |
581 |
prepaidBestPrice = similarItem['netPriceAfterCashBack']
|
| 16017 |
kshitij.so |
582 |
prepaidBestSellerPoints = similarItem['bestSellerPoints']
|
|
|
583 |
else:
|
|
|
584 |
pass
|
| 17456 |
kshitij.so |
585 |
#print "bestOne ", bestOne
|
|
|
586 |
#print "prepaid best one", prepaidBestOne
|
| 16024 |
kshitij.so |
587 |
if bestOne is not None or prepaidBestOne is not None:
|
| 13918 |
kshitij.so |
588 |
for similarItem in similarItems:
|
|
|
589 |
toUpdate.append(similarItem['_id'])
|
| 16023 |
kshitij.so |
590 |
if bestOne is not None:
|
|
|
591 |
toUpdate.remove(bestOne['_id'])
|
|
|
592 |
get_mongo_connection().Catalog.Deals.update({ '_id' : bestOne['_id'] }, {'$set':{'showDeal':1,'prepaidDeal':0 }})
|
|
|
593 |
if prepaidBestOne is not None:
|
| 16069 |
kshitij.so |
594 |
if bestOne is not None:
|
| 19153 |
kshitij.so |
595 |
if prepaidBestOne['netPriceAfterCashBack'] < bestOne['netPriceAfterCashBack']:
|
| 16069 |
kshitij.so |
596 |
toUpdate.remove(prepaidBestOne['_id'])
|
|
|
597 |
get_mongo_connection().Catalog.Deals.update({ '_id' : prepaidBestOne['_id'] }, {'$set':{'showDeal':0,'prepaidDeal':1 }})
|
| 16072 |
kshitij.so |
598 |
else:
|
|
|
599 |
toUpdate.remove(prepaidBestOne['_id'])
|
|
|
600 |
get_mongo_connection().Catalog.Deals.update({ '_id' : prepaidBestOne['_id'] }, {'$set':{'showDeal':0,'prepaidDeal':1 }})
|
| 13918 |
kshitij.so |
601 |
if len(toUpdate) > 0:
|
| 16017 |
kshitij.so |
602 |
get_mongo_connection().Catalog.Deals.update({ '_id' : { "$in": toUpdate } }, {'$set':{'showDeal':0,'prepaidDeal':0 }},upsert=False, multi=True)
|
|
|
603 |
|
| 14342 |
kshitij.so |
604 |
print "Done with recomputing"
|
| 13829 |
kshitij.so |
605 |
|
|
|
606 |
def getLatestPrice(skuBundleId, source_id):
|
|
|
607 |
temp = []
|
|
|
608 |
itemIds = list(get_mongo_connection().Catalog.MasterData.find({'skuBundleId':skuBundleId,'source_id' : source_id}))
|
| 16026 |
kshitij.so |
609 |
item = None
|
| 13829 |
kshitij.so |
610 |
for item in itemIds:
|
| 14309 |
kshitij.so |
611 |
item['dealFlag'] = 0
|
|
|
612 |
item['dealType'] = 0
|
| 16510 |
kshitij.so |
613 |
item['dealUrl'] = ""
|
| 17674 |
kshitij.so |
614 |
if item['source_id'] ==5 and item['rank'] == 0 and item['category_id']!=6:
|
| 15912 |
kshitij.so |
615 |
continue
|
| 15187 |
kshitij.so |
616 |
if item['source_id'] ==3:
|
|
|
617 |
item['marketPlaceUrl'] = item['marketPlaceUrl']+'?supc='+item.get('identifier')
|
| 14309 |
kshitij.so |
618 |
manualDeals = list(get_mongo_connection().Catalog.ManualDeals.find({'startDate':{'$lte':to_java_date(datetime.now())},'endDate':{'$gte':to_java_date(datetime.now())},'source_id':source_id, 'sku':item['_id']}))
|
|
|
619 |
if len(manualDeals) > 0:
|
|
|
620 |
item['dealFlag'] = 1
|
| 14760 |
kshitij.so |
621 |
item['dealType'] =manualDeals[0]['dealType']
|
| 16510 |
kshitij.so |
622 |
item['dealUrl'] = manualDeals[0]['dealUrl']
|
| 14760 |
kshitij.so |
623 |
info = returnLatestPrice(item, source_id)
|
| 19153 |
kshitij.so |
624 |
if item['source_id'] != SOURCE_MAP.get('PAYTM.COM'):
|
|
|
625 |
data = calculateCashBack(item, info['available_price'])
|
|
|
626 |
else:
|
|
|
627 |
if info['codAvailable'] ==0:
|
|
|
628 |
data = calculateCashBack(item, info['gross_price'])
|
| 14760 |
kshitij.so |
629 |
else:
|
| 19153 |
kshitij.so |
630 |
data = calculateCashBack(item, info['available_price']) #No need, can be done in if with or clause.
|
|
|
631 |
|
|
|
632 |
info['cash_back'] = data['cash_back']
|
|
|
633 |
info['cash_back_type'] = data['cash_back_type']
|
|
|
634 |
info['netPriceAfterCashBack'] = data['netPriceAfterCashBack']
|
|
|
635 |
info['showNetPrice'] = data['showNetPrice']
|
|
|
636 |
get_mongo_connection().Catalog.Deals.update({'_id':item['_id']},{"$set":{'netPriceAfterCashBack':info['netPriceAfterCashBack']}})
|
| 14760 |
kshitij.so |
637 |
temp.append(info)
|
| 16026 |
kshitij.so |
638 |
if item is not None:
|
|
|
639 |
try:
|
|
|
640 |
thread = threading.Thread(target=recomputeDeal, args = (item,))
|
|
|
641 |
thread.daemon = True
|
|
|
642 |
thread.start()
|
|
|
643 |
except:
|
|
|
644 |
print traceback.print_exc()
|
|
|
645 |
print "Unable to compute deal for ",skuBundleId
|
| 13829 |
kshitij.so |
646 |
return temp
|
|
|
647 |
|
| 13864 |
kshitij.so |
648 |
def getLatestPriceById(id):
|
|
|
649 |
item = list(get_mongo_connection().Catalog.MasterData.find({'_id':id}))
|
| 14309 |
kshitij.so |
650 |
item[0]['dealFlag'] = 0
|
|
|
651 |
item[0]['dealType'] = 0
|
| 16510 |
kshitij.so |
652 |
item[0]['dealUrl'] = ""
|
|
|
653 |
|
| 14309 |
kshitij.so |
654 |
manualDeals = list(get_mongo_connection().Catalog.ManualDeals.find({'startDate':{'$lte':to_java_date(datetime.now())},'endDate':{'$gte':to_java_date(datetime.now())},'source_id':item[0]['source_id'], 'sku':item[0]['_id']}))
|
|
|
655 |
if len(manualDeals) > 0:
|
|
|
656 |
item[0]['dealFlag'] = 1
|
| 15266 |
kshitij.so |
657 |
item[0]['dealType'] =manualDeals[0]['dealType']
|
| 16510 |
kshitij.so |
658 |
item[0]['dealUrl'] = manualDeals[0]['dealUrl']
|
| 14367 |
kshitij.so |
659 |
|
| 14431 |
kshitij.so |
660 |
info = returnLatestPrice(item[0], item[0]['source_id'])
|
| 19153 |
kshitij.so |
661 |
if item[0]['source_id'] != SOURCE_MAP.get('PAYTM.COM'):
|
|
|
662 |
data = calculateCashBack(item[0], info['available_price'])
|
|
|
663 |
else:
|
|
|
664 |
if info['codAvailable'] ==0:
|
|
|
665 |
data = calculateCashBack(item[0], info['gross_price'])
|
|
|
666 |
else:
|
|
|
667 |
data = calculateCashBack(item[0], info['available_price']) #No need, can be done in if with or clause.
|
|
|
668 |
|
|
|
669 |
info['cash_back'] = data['cash_back']
|
|
|
670 |
info['cash_back_type'] = data['cash_back_type']
|
|
|
671 |
info['netPriceAfterCashBack'] = data['netPriceAfterCashBack']
|
|
|
672 |
info['showNetPrice'] = data['showNetPrice']
|
|
|
673 |
get_mongo_connection().Catalog.Deals.update({'_id':item[0]['_id']},{"$set":{'netPriceAfterCashBack':info['netPriceAfterCashBack']}})
|
| 14794 |
kshitij.so |
674 |
print info
|
| 14367 |
kshitij.so |
675 |
try:
|
| 15273 |
kshitij.so |
676 |
thread = threading.Thread(target=recomputeDeal, args = (item[0],))
|
| 14367 |
kshitij.so |
677 |
thread.daemon = True
|
|
|
678 |
thread.start()
|
|
|
679 |
except:
|
|
|
680 |
print "Unable to compute deal for ",item[0]['skuBundleId']
|
| 14431 |
kshitij.so |
681 |
return info
|
| 13829 |
kshitij.so |
682 |
|
| 14828 |
kshitij.so |
683 |
def updatePriceForNotificationBundles(skuBundleId):
|
| 15266 |
kshitij.so |
684 |
itemIds = list(get_mongo_connection().Catalog.MasterData.find({'skuBundleId':skuBundleId,'priceUpdatedOn':{'$lte':to_java_date(datetime.now() - timedelta(minutes=2))},'source_id':{"$in":SOURCE_MAP.values()}}))
|
| 14828 |
kshitij.so |
685 |
for item in itemIds:
|
| 14833 |
kshitij.so |
686 |
print item['_id']
|
| 14828 |
kshitij.so |
687 |
item['dealFlag'] = 0
|
|
|
688 |
item['dealType'] = 0
|
| 16510 |
kshitij.so |
689 |
item['dealUrl'] = ""
|
| 14828 |
kshitij.so |
690 |
manualDeals = list(get_mongo_connection().Catalog.ManualDeals.find({'startDate':{'$lte':to_java_date(datetime.now())},'endDate':{'$gte':to_java_date(datetime.now())},'source_id':item['source_id'], 'sku':item['_id']}))
|
|
|
691 |
if len(manualDeals) > 0:
|
|
|
692 |
item['dealFlag'] = 1
|
|
|
693 |
item['dealType'] =manualDeals[0]['dealType']
|
| 16510 |
kshitij.so |
694 |
item['dealUrl'] = manualDeals[0]['dealUrl']
|
| 14828 |
kshitij.so |
695 |
info = returnLatestPrice(item, item['source_id'],False)
|
|
|
696 |
print info
|
|
|
697 |
|
| 13829 |
kshitij.so |
698 |
def main():
|
| 15956 |
kshitij.so |
699 |
print datetime.now()
|
| 19192 |
kshitij.so |
700 |
print "retuned %s"%(str(getLatestPrice(5899,4)))
|
| 15956 |
kshitij.so |
701 |
print datetime.now()
|
| 13829 |
kshitij.so |
702 |
if __name__=='__main__':
|
| 13971 |
kshitij.so |
703 |
main()
|
|
|
704 |
|