| Line 333... |
Line 333... |
| 333 |
|
333 |
|
| 334 |
paytmScraper = PaytmScraper.PaytmScraper()
|
334 |
paytmScraper = PaytmScraper.PaytmScraper()
|
| 335 |
url = "https://catalog.paytm.com/v1/mobile/product/%s"%(data['identifier'].strip())
|
335 |
url = "https://catalog.paytm.com/v1/mobile/product/%s"%(data['identifier'].strip())
|
| 336 |
try:
|
336 |
try:
|
| 337 |
result = paytmScraper.read(url)
|
337 |
result = paytmScraper.read(url)
|
| - |
|
338 |
print result
|
| 338 |
effective_price = result.get('offerPrice')
|
339 |
effective_price = result.get('offerPrice')
|
| 339 |
gross_price = effective_price
|
340 |
gross_price = effective_price
|
| - |
|
341 |
shareUrl = result.get('shareUrl')
|
| - |
|
342 |
if shareUrl is None:
|
| - |
|
343 |
shareUrl = data['marketPlaceUrl']
|
| 340 |
coupon = ""
|
344 |
coupon = ""
|
| 341 |
try:
|
345 |
try:
|
| 342 |
offers = PaytmOfferScraper.fetchOffers(result['offerUrl'])
|
346 |
offers = PaytmOfferScraper.fetchOffers(result['offerUrl'])
|
| 343 |
try:
|
347 |
try:
|
| 344 |
addToPaytmMaster(offers.get('codes'))
|
348 |
addToPaytmMaster(offers.get('codes'))
|
| Line 359... |
Line 363... |
| 359 |
result['codAvailable'] = 0
|
363 |
result['codAvailable'] = 0
|
| 360 |
|
364 |
|
| 361 |
available_price = effective_price
|
365 |
available_price = effective_price
|
| 362 |
if result['inStock']:
|
366 |
if result['inStock']:
|
| 363 |
inStock = 1
|
367 |
inStock = 1
|
| 364 |
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}})
|
368 |
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}})
|
| 365 |
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}})
|
369 |
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}})
|
| 366 |
else:
|
370 |
else:
|
| 367 |
inStock = 0
|
371 |
inStock = 0
|
| 368 |
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}})
|
372 |
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}})
|
| 369 |
get_mongo_connection().Catalog.Deals.update({'_id':data['_id']}, {'$set' : {'in_stock':0,'codAvailable':result.get('codAvailable')}})
|
373 |
get_mongo_connection().Catalog.Deals.update({'_id':data['_id']}, {'$set' : {'in_stock':0,'codAvailable':result.get('codAvailable')}})
|
| 370 |
|
374 |
|
| 371 |
except:
|
375 |
except:
|
| 372 |
inStock = 0
|
376 |
inStock = 0
|
| 373 |
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}})
|
377 |
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}})
|
| 374 |
get_mongo_connection().Catalog.Deals.update({'_id':data['_id']}, {'$set' : {'in_stock':0}})
|
378 |
get_mongo_connection().Catalog.Deals.update({'_id':data['_id']}, {'$set' : {'in_stock':0}})
|
| 375 |
|
379 |
|
| 376 |
|
380 |
|
| 377 |
return {'_id':data['_id'],'available_price':available_price,'in_stock':inStock,'source_id':6,'source_product_name':data['source_product_name'],'marketPlaceUrl':data['marketPlaceUrl'],'thumbnail':data['thumbnail'], 'coupon':coupon,'codAvailable':result['codAvailable'], 'tagline': data['tagline'], 'offer': data['offer'],'gross_price':gross_price}
|
381 |
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}
|
| 378 |
except Exception as e:
|
382 |
except Exception as e:
|
| 379 |
print "Exception for _id %d and source %s"%(data['_id'], source_id)
|
383 |
print "Exception for _id %d and source %s"%(data['_id'], source_id)
|
| 380 |
traceback.print_exc()
|
384 |
traceback.print_exc()
|
| 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')}
|
385 |
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')}
|
| 382 |
|
386 |
|
| Line 668... |
Line 672... |
| 668 |
info = returnLatestPrice(item, item['source_id'],False)
|
672 |
info = returnLatestPrice(item, item['source_id'],False)
|
| 669 |
print info
|
673 |
print info
|
| 670 |
|
674 |
|
| 671 |
def main():
|
675 |
def main():
|
| 672 |
print datetime.now()
|
676 |
print datetime.now()
|
| 673 |
print "retuned %s"%(str(getLatestPriceById(7)))
|
677 |
print "retuned %s"%(str(getLatestPriceById(277)))
|
| 674 |
print datetime.now()
|
678 |
print datetime.now()
|
| 675 |
if __name__=='__main__':
|
679 |
if __name__=='__main__':
|
| 676 |
main()
|
680 |
main()
|
| 677 |
|
681 |
|