| Line 3... |
Line 3... |
| 3 |
import pymongo
|
3 |
import pymongo
|
| 4 |
from dtr.utils.utils import to_java_date
|
4 |
from dtr.utils.utils import to_java_date
|
| 5 |
from datetime import datetime, timedelta
|
5 |
from datetime import datetime, timedelta
|
| 6 |
from operator import itemgetter
|
6 |
from operator import itemgetter
|
| 7 |
from dtr.utils.AmazonPriceOnlyScraper import AmazonScraper
|
7 |
from dtr.utils.AmazonPriceOnlyScraper import AmazonScraper
|
| - |
|
8 |
from dtr.utils import AmazonDealScraper
|
| 8 |
from dtr.utils import FlipkartScraper,NewFlipkartScraper
|
9 |
from dtr.utils import FlipkartScraper,NewFlipkartScraper
|
| 9 |
|
10 |
|
| 10 |
con = None
|
11 |
con = None
|
| 11 |
SOURCE_MAP = {'AMAZON':1,'FLIPKART':2,'SNAPDEAL':3,'SAHOLIC':4}
|
12 |
SOURCE_MAP = {'AMAZON':1,'FLIPKART':2,'SNAPDEAL':3,'SAHOLIC':4}
|
| 12 |
|
13 |
|
| Line 34... |
Line 35... |
| 34 |
try:
|
35 |
try:
|
| 35 |
if data['identifier'] is None or len(data['identifier'].strip())==0:
|
36 |
if data['identifier'] is None or len(data['identifier'].strip())==0:
|
| 36 |
return {}
|
37 |
return {}
|
| 37 |
|
38 |
|
| 38 |
try:
|
39 |
try:
|
| 39 |
if data['priceUpdatedOn'] > to_java_date(now - timedelta(minutes=5)):
|
40 |
if data['priceUpdatedOn'] > to_java_date(now - timedelta(minutes=0)):
|
| 40 |
print "sku id is already updated",data['_id']
|
41 |
print "sku id is already updated",data['_id']
|
| 41 |
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']}
|
42 |
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']}
|
| 42 |
except:
|
43 |
except:
|
| 43 |
pass
|
44 |
pass
|
| 44 |
|
45 |
|
| 45 |
|
46 |
|
| 46 |
url = "http://www.amazon.in/gp/offer-listing/%s/ref=olp_sort_ps"%(data['identifier'])
|
47 |
url = "http://www.amazon.in/gp/offer-listing/%s/ref=olp_sort_ps"%(data['identifier'])
|
| 47 |
lowestPrice = 0.0
|
48 |
lowestPrice = 0.0
|
| - |
|
49 |
print data['dealFlag']
|
| - |
|
50 |
print data['dealType']
|
| - |
|
51 |
try:
|
| - |
|
52 |
if data['dealFlag'] ==1 and data['dealType'] ==1:
|
| - |
|
53 |
print "Inside deal"
|
| - |
|
54 |
deal_url = "http://www.amazon.in/dp/%s"%(data['identifier'].strip())
|
| - |
|
55 |
print deal_url
|
| - |
|
56 |
dealScraperAmazon = AmazonDealScraper.AmazonScraper()
|
| - |
|
57 |
lowestPrice = dealScraperAmazon.read(deal_url)
|
| - |
|
58 |
print lowestPrice
|
| - |
|
59 |
if lowestPrice == 0:
|
| - |
|
60 |
raise
|
| - |
|
61 |
else:
|
| - |
|
62 |
scraperAmazon = AmazonScraper()
|
| - |
|
63 |
lowestPrice = scraperAmazon.read(url)
|
| - |
|
64 |
except Exception as e:
|
| - |
|
65 |
print e
|
| 48 |
scraperAmazon = AmazonScraper()
|
66 |
scraperAmazon = AmazonScraper()
|
| 49 |
lowestPrice = scraperAmazon.read(url)
|
67 |
lowestPrice = scraperAmazon.read(url)
|
| 50 |
print "LowestPrice ",lowestPrice
|
68 |
print "LowestPrice ",lowestPrice
|
| 51 |
inStock = 0
|
69 |
inStock = 0
|
| 52 |
if lowestPrice > 0:
|
70 |
if lowestPrice > 0:
|
| 53 |
inStock = 1
|
71 |
inStock = 1
|
| 54 |
if lowestPrice > 0:
|
72 |
if lowestPrice > 0:
|
| 55 |
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)
|
73 |
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)
|
| 56 |
get_mongo_connection().Catalog.Deals.update({'_id':data['_id']}, {'$set' : {'available_price':lowestPrice , 'in_stock':inStock}}, multi=True)
|
74 |
get_mongo_connection().Catalog.Deals.update({'_id':data['_id']}, {'$set' : {'available_price':lowestPrice , 'in_stock':inStock,'dealType':data['dealType']}}, multi=True)
|
| 57 |
else:
|
75 |
else:
|
| 58 |
lowestPrice = data['available_price']
|
76 |
lowestPrice = data['available_price']
|
| 59 |
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)
|
77 |
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)
|
| 60 |
get_mongo_connection().Catalog.Deals.update({'_id':data['_id']}, {'$set' : {'in_stock':0}}, multi=True)
|
78 |
get_mongo_connection().Catalog.Deals.update({'_id':data['_id']}, {'$set' : {'in_stock':0,'dealType':data['dealType']}}, multi=True)
|
| 61 |
|
79 |
|
| 62 |
try:
|
80 |
try:
|
| 63 |
recomputeDeal(data['skuBundleId'])
|
81 |
recomputeDeal(data['skuBundleId'])
|
| 64 |
except:
|
82 |
except:
|
| 65 |
print "Unable to compute deal for ",data['skuBundleId']
|
83 |
print "Unable to compute deal for ",data['skuBundleId']
|
| Line 254... |
Line 272... |
| 254 |
|
272 |
|
| 255 |
def getLatestPrice(skuBundleId, source_id):
|
273 |
def getLatestPrice(skuBundleId, source_id):
|
| 256 |
temp = []
|
274 |
temp = []
|
| 257 |
itemIds = list(get_mongo_connection().Catalog.MasterData.find({'skuBundleId':skuBundleId,'source_id' : source_id}))
|
275 |
itemIds = list(get_mongo_connection().Catalog.MasterData.find({'skuBundleId':skuBundleId,'source_id' : source_id}))
|
| 258 |
for item in itemIds:
|
276 |
for item in itemIds:
|
| - |
|
277 |
item['dealFlag'] = 0
|
| - |
|
278 |
item['dealType'] = 0
|
| - |
|
279 |
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']}))
|
| - |
|
280 |
if len(manualDeals) > 0:
|
| - |
|
281 |
item['dealFlag'] = 1
|
| - |
|
282 |
item['dealType'] =manualDeals[0]['dealType']
|
| 259 |
temp.append(returnLatestPrice(item, source_id))
|
283 |
temp.append(returnLatestPrice(item, source_id))
|
| 260 |
return temp
|
284 |
return temp
|
| 261 |
|
285 |
|
| 262 |
def getLatestPriceById(id):
|
286 |
def getLatestPriceById(id):
|
| 263 |
item = list(get_mongo_connection().Catalog.MasterData.find({'_id':id}))
|
287 |
item = list(get_mongo_connection().Catalog.MasterData.find({'_id':id}))
|
| - |
|
288 |
item[0]['dealFlag'] = 0
|
| - |
|
289 |
item[0]['dealType'] = 0
|
| - |
|
290 |
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']}))
|
| - |
|
291 |
if len(manualDeals) > 0:
|
| - |
|
292 |
item[0]['dealFlag'] = 1
|
| - |
|
293 |
item[0]['dealType'] =manualDeals[0]['dealType']
|
| 264 |
return returnLatestPrice(item[0], item[0]['source_id'])
|
294 |
return returnLatestPrice(item[0], item[0]['source_id'])
|
| 265 |
|
295 |
|
| 266 |
|
296 |
|
| 267 |
def main():
|
297 |
def main():
|
| 268 |
print getLatestPriceById(8850)
|
298 |
print getLatestPriceById(22746)
|
| 269 |
|
299 |
|
| 270 |
if __name__=='__main__':
|
300 |
if __name__=='__main__':
|
| 271 |
main()
|
301 |
main()
|
| 272 |
|
302 |
|
| 273 |
"""21.06$"""
|
303 |
"""21.06$"""
|
| 274 |
|
304 |
|