Subversion Repositories SmartDukaan

Rev

Rev 14127 | Rev 14147 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 14127 Rev 14133
Line 17... Line 17...
17
            print e
17
            print e
18
            return None
18
            return None
19
    return con
19
    return con
20
 
20
 
21
def scrapeAmazon():
21
def scrapeAmazon():
22
    amazonBestSellers = list(get_mongo_connection().Catalog.MasterData.find({'rank':{'$gt':0}}))
22
    bestSellers = list(get_mongo_connection().Catalog.MasterData.find({'rank':{'$gt':0}}))
23
    for data in amazonBestSellers:
23
    for bestSeller in bestSellers: 
24
        if data['source_id'] !=1:
24
        amazonBestSellers = list(get_mongo_connection().Catalog.MasterData.find({'skuBundleId':bestSeller['skuBundleId'],'source_id':1}))
25
            continue
25
        for data in amazonBestSellers:
26
        inStock = 0
26
            inStock = 0
27
        print str(data['identifier'])
27
            print str(data['identifier'])
28
        if data['identifier'] is None or len(data['identifier'].strip())==0:
28
            if data['identifier'] is None or len(data['identifier'].strip())==0:
29
            print "continue"
29
                print "continue"
30
            continue
-
 
31
        
-
 
32
        try:
-
 
33
            if data['priceUpdatedOn'] > to_java_date(datetime.now() - timedelta(minutes=5)):
-
 
34
                print "sku id is already updated",data['_id'] 
-
 
35
                continue
30
                continue
36
        except:
-
 
37
            pass
-
 
38
        
-
 
39
        url = "http://www.amazon.in/gp/offer-listing/%s/ref=olp_sort_ps"%(data['identifier'].strip())
-
 
40
        print url
-
 
41
        lowestPrice = 0.0
-
 
42
        lowestPrice = scraperAmazon.read(url)
-
 
43
        print lowestPrice
-
 
44
        if lowestPrice > 0:
-
 
45
            inStock = 1
-
 
46
        print lowestPrice
-
 
47
        print inStock
-
 
48
        if lowestPrice > 0:
-
 
49
            get_mongo_connection().Catalog.MasterData.update({'_id':data['_id']}, {'$set' : {'available_price':lowestPrice,'updatedOn':to_java_date(datetime.now()),'priceUpdatedOn':to_java_date(datetime.now()),'in_stock':inStock}}, multi=True)
-
 
50
            get_mongo_connection().Catalog.Deals.update({'_id':data['_id']}, {'$set' : {'available_price':lowestPrice , 'in_stock':inStock}}, multi=True)
-
 
51
        else:
-
 
52
            get_mongo_connection().Catalog.MasterData.update({'_id':data['_id']}, {'$set' : {'updatedOn':to_java_date(datetime.now()),'in_stock':inStock,'priceUpdatedOn':to_java_date(datetime.now())}}, multi=True)
-
 
53
            get_mongo_connection().Catalog.Deals.update({'_id':data['_id']}, {'$set' : {'in_stock':inStock}}, multi=True)
-
 
54
            
31
            
55
        try:
32
            try:
-
 
33
                if data['priceUpdatedOn'] > to_java_date(datetime.now() - timedelta(minutes=5)):
-
 
34
                    print "sku id is already updated",data['_id'] 
-
 
35
                    continue
-
 
36
            except:
-
 
37
                pass
-
 
38
            
-
 
39
            url = "http://www.amazon.in/gp/offer-listing/%s/ref=olp_sort_ps"%(data['identifier'].strip())
-
 
40
            print url
-
 
41
            lowestPrice = 0.0
-
 
42
            lowestPrice = scraperAmazon.read(url)
-
 
43
            print lowestPrice
-
 
44
            if lowestPrice > 0:
-
 
45
                inStock = 1
-
 
46
            print lowestPrice
-
 
47
            print inStock
-
 
48
            if lowestPrice > 0:
-
 
49
                get_mongo_connection().Catalog.MasterData.update({'_id':data['_id']}, {'$set' : {'available_price':lowestPrice,'updatedOn':to_java_date(datetime.now()),'priceUpdatedOn':to_java_date(datetime.now()),'in_stock':inStock}}, multi=True)
-
 
50
                get_mongo_connection().Catalog.Deals.update({'_id':data['_id']}, {'$set' : {'available_price':lowestPrice , 'in_stock':inStock}}, multi=True)
-
 
51
            else:
-
 
52
                get_mongo_connection().Catalog.MasterData.update({'_id':data['_id']}, {'$set' : {'updatedOn':to_java_date(datetime.now()),'in_stock':inStock,'priceUpdatedOn':to_java_date(datetime.now())}}, multi=True)
-
 
53
                get_mongo_connection().Catalog.Deals.update({'_id':data['_id']}, {'$set' : {'in_stock':inStock}}, multi=True)
-
 
54
                
-
 
55
            try:
56
            recomputeDeal(data['skuBundleId'])
56
                recomputeDeal(data['skuBundleId'])
57
        except:
57
            except:
58
            print "Unable to compute deal for ",data['skuBundleId']
58
                print "Unable to compute deal for ",data['skuBundleId']
59
        
59
        
60
 
60
 
61
def recomputeDeal(skuBundleId):
61
def recomputeDeal(skuBundleId):
62
    """Lets recompute deal for this bundle"""
62
    """Lets recompute deal for this bundle"""
63
    print "Recomputing for bundleId",skuBundleId
63
    print "Recomputing for bundleId",skuBundleId