| Line 4... |
Line 4... |
| 4 |
from dtr.utils.utils import to_java_date, getNlcPoints, transformUrl
|
4 |
from dtr.utils.utils import to_java_date, getNlcPoints, transformUrl
|
| 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 AmazonDealScraper
|
| 9 |
from dtr.utils import FlipkartScraper,NewFlipkartScraper, ShopCluesScraper
|
9 |
from dtr.utils import FlipkartScraper,NewFlipkartScraper, ShopCluesScraper, \
|
| - |
|
10 |
PaytmOfferScraper, PaytmScraper
|
| 10 |
from dtr.storage.MemCache import MemCache
|
11 |
from dtr.storage.MemCache import MemCache
|
| 11 |
from functools import partial
|
12 |
from functools import partial
|
| 12 |
import threading
|
13 |
import threading
|
| 13 |
from dtr.utils.utils import getCashBack
|
14 |
from dtr.utils.utils import getCashBack
|
| 14 |
import traceback
|
15 |
import traceback
|
| Line 21... |
Line 22... |
| 21 |
|
22 |
|
| 22 |
mc = MemCache(host_memCache)
|
23 |
mc = MemCache(host_memCache)
|
| 23 |
|
24 |
|
| 24 |
|
25 |
|
| 25 |
con = None
|
26 |
con = None
|
| 26 |
SOURCE_MAP = {'AMAZON':1,'FLIPKART':2,'SNAPDEAL':3,'SAHOLIC':4, 'SHOPCLUES.COM':5}
|
27 |
SOURCE_MAP = {'AMAZON':1,'FLIPKART':2,'SNAPDEAL':3,'SAHOLIC':4, 'SHOPCLUES.COM':5,'PAYTM.COM':6}
|
| 27 |
|
28 |
|
| 28 |
headers = {
|
29 |
headers = {
|
| 29 |
'User-agent':'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11',
|
30 |
'User-agent':'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11',
|
| 30 |
'Accept' : 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
|
31 |
'Accept' : 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
|
| 31 |
'Accept-Language' : 'en-US,en;q=0.8',
|
32 |
'Accept-Language' : 'en-US,en;q=0.8',
|
| Line 325... |
Line 326... |
| 325 |
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']}
|
326 |
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']}
|
| 326 |
except Exception as e:
|
327 |
except Exception as e:
|
| 327 |
print "Exception for _id %d and source %s"%(data['_id'], source_id)
|
328 |
print "Exception for _id %d and source %s"%(data['_id'], source_id)
|
| 328 |
traceback.print_exc()
|
329 |
traceback.print_exc()
|
| 329 |
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']}
|
330 |
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']}
|
| - |
|
331 |
|
| - |
|
332 |
elif source_id == 6:
|
| - |
|
333 |
try:
|
| - |
|
334 |
if data['_id'] in ignoreItems:
|
| - |
|
335 |
print "Ignored items returning for %d"%(data['_id'])
|
| - |
|
336 |
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']}
|
| - |
|
337 |
|
| - |
|
338 |
try:
|
| - |
|
339 |
if ignoreLastUpdated and data['priceUpdatedOn'] > to_java_date(now - timedelta(minutes=5)):
|
| - |
|
340 |
print "sku id is already updated",data['_id']
|
| - |
|
341 |
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']}
|
| - |
|
342 |
except:
|
| - |
|
343 |
pass
|
| - |
|
344 |
|
| - |
|
345 |
paytmScraper = PaytmScraper.PaytmScraper()
|
| - |
|
346 |
url = "https://catalog.paytm.com/v1/mobile/product/%s"%(data['identifier'].strip())
|
| - |
|
347 |
try:
|
| - |
|
348 |
result = paytmScraper.read(url)
|
| - |
|
349 |
effective_price = result.get('offerPrice')
|
| - |
|
350 |
coupon = ""
|
| - |
|
351 |
try:
|
| - |
|
352 |
offers = PaytmOfferScraper.fetchOffers(result['offerUrl'])
|
| - |
|
353 |
bestOffer = {}
|
| - |
|
354 |
for offer_data in offers.get('codes'):
|
| - |
|
355 |
if effective_price < offer_data.get('effective_price'):
|
| - |
|
356 |
effective_price = offer_data.get('effective_price')
|
| - |
|
357 |
bestOffer = offer_data
|
| - |
|
358 |
coupon = bestOffer.get('code')
|
| - |
|
359 |
except:
|
| - |
|
360 |
pass
|
| - |
|
361 |
available_price = effective_price
|
| - |
|
362 |
if result['inStock']:
|
| - |
|
363 |
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('cod'),'coupon':coupon}})
|
| - |
|
365 |
get_mongo_connection().Catalog.Deals.update({'_id':data['_id']}, {'$set' : {'available_price':available_price , 'in_stock':1,'codAvailable':result.get('cod')}})
|
| - |
|
366 |
else:
|
| - |
|
367 |
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('cod'),'coupon':coupon}})
|
| - |
|
369 |
get_mongo_connection().Catalog.Deals.update({'_id':data['_id']}, {'$set' : {'in_stock':0,'codAvailable':result.get('cod')}})
|
| - |
|
370 |
|
| - |
|
371 |
except:
|
| - |
|
372 |
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}})
|
| - |
|
374 |
get_mongo_connection().Catalog.Deals.update({'_id':data['_id']}, {'$set' : {'in_stock':0}})
|
| - |
|
375 |
|
| - |
|
376 |
|
| - |
|
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['cod'], 'tagline': data['tagline'], 'offer': data['offer']}
|
| - |
|
378 |
except Exception as e:
|
| - |
|
379 |
print "Exception for _id %d and source %s"%(data['_id'], source_id)
|
| - |
|
380 |
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']}
|
| - |
|
382 |
|
| 330 |
|
383 |
|
| 331 |
else:
|
384 |
else:
|
| 332 |
return {}
|
385 |
return {}
|
| 333 |
|
386 |
|
| 334 |
|
387 |
|