Subversion Repositories SmartDukaan

Rev

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

Rev 14127 Rev 14132
Line 24... Line 24...
24
            print e
24
            print e
25
            return None
25
            return None
26
    return con
26
    return con
27
 
27
 
28
def updatePrices():
28
def updatePrices():
29
    snapdealBestSellers = list(get_mongo_connection().Catalog.MasterData.find({'rank':{'$gt':0}}))
29
    bestSellers = list(get_mongo_connection().Catalog.MasterData.find({'rank':{'$gt':0}}))
30
    for data in snapdealBestSellers:
30
    for bestSeller in bestSellers: 
31
        if data['source_id']!=3:
-
 
32
            continue
-
 
33
        print data['identifier']
-
 
34
        if data['identifier'] is None or len(data['identifier'].strip())==0:
31
        snapdealBestSellers = list(get_mongo_connection().Catalog.MasterData.find({'skuBundleId':bestSeller['skuBundleId'],'source_id':3}))
35
            print "continue"
32
        for data in snapdealBestSellers:
36
            continue
33
            if data['source_id']!=3:
37
        
-
 
38
        try:
-
 
39
            if data['priceUpdatedOn'] > to_java_date(datetime.now() - timedelta(minutes=5)):
-
 
40
                print "sku id is already updated",data['_id'] 
-
 
41
                continue
34
                continue
-
 
35
            print data['identifier']
-
 
36
            if data['identifier'] is None or len(data['identifier'].strip())==0:
-
 
37
                print "continue"
-
 
38
                continue
-
 
39
            
-
 
40
            try:
-
 
41
                if data['priceUpdatedOn'] > to_java_date(datetime.now() - timedelta(minutes=5)):
-
 
42
                    print "sku id is already updated",data['_id'] 
-
 
43
                    continue
42
        except:
44
            except:
43
            pass
45
                pass
44
        
46
            
45
        url="http://www.snapdeal.com/acors/json/gvbps?supc=%s&catId=175&sort=sellingPrice"%(data['identifier'].strip())
47
            url="http://www.snapdeal.com/acors/json/gvbps?supc=%s&catId=175&sort=sellingPrice"%(data['identifier'].strip())
46
        print url
48
            print url
47
        time.sleep(1)
49
            time.sleep(1)
48
        lowestOfferPrice = 0
50
            lowestOfferPrice = 0
49
        instock = 0
51
            instock = 0
50
        req = urllib2.Request(url,headers=headers)
52
            req = urllib2.Request(url,headers=headers)
51
        response = urllib2.urlopen(req)
53
            response = urllib2.urlopen(req)
52
        json_input = response.read()
54
            json_input = response.read()
53
        if len(json_input) > 0:
55
            if len(json_input) > 0:
54
            vendorInfo = json.loads(json_input)
56
                vendorInfo = json.loads(json_input)
55
            for vendor in vendorInfo:
57
                for vendor in vendorInfo:
56
                lowestOfferPrice = float(vendor['sellingPrice'])
58
                    lowestOfferPrice = float(vendor['sellingPrice'])
57
                stock = vendor['buyableInventory']
59
                    stock = vendor['buyableInventory']
58
                if stock > 0 and lowestOfferPrice > 0:
60
                    if stock > 0 and lowestOfferPrice > 0:
59
                    instock = 1
61
                        instock = 1
60
                    break
62
                        break
61
                    
63
                        
62
        print lowestOfferPrice
64
            print lowestOfferPrice
63
        print instock
65
            print instock
64
        print stock
66
            print stock
65
        print "*************"
67
            print "*************"
66
        if instock  == 1:
68
            if instock  == 1:
67
            get_mongo_connection().Catalog.MasterData.update({'_id':data['_id']}, {'$set' : {'available_price':lowestOfferPrice,'updatedOn':to_java_date(datetime.now()),'priceUpdatedOn':to_java_date(datetime.now()),'in_stock':instock}}, multi=True)
69
                get_mongo_connection().Catalog.MasterData.update({'_id':data['_id']}, {'$set' : {'available_price':lowestOfferPrice,'updatedOn':to_java_date(datetime.now()),'priceUpdatedOn':to_java_date(datetime.now()),'in_stock':instock}}, multi=True)
68
            get_mongo_connection().Catalog.Deals.update({'_id':data['_id']}, {'$set' : {'available_price':lowestOfferPrice , 'in_stock':instock}}, multi=True)
70
                get_mongo_connection().Catalog.Deals.update({'_id':data['_id']}, {'$set' : {'available_price':lowestOfferPrice , 'in_stock':instock}}, multi=True)
69
        else:
71
            else:
70
            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)
72
                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)
71
            get_mongo_connection().Catalog.Deals.update({'_id':data['_id']}, {'$set' : {'in_stock':instock}}, multi=True)
73
                get_mongo_connection().Catalog.Deals.update({'_id':data['_id']}, {'$set' : {'in_stock':instock}}, multi=True)
72
        
74
            
73
        try:
75
            try:
74
            recomputeDeal(data['skuBundleId'])
76
                recomputeDeal(data['skuBundleId'])
75
        except:
77
            except:
76
            print "Unable to compute deal for ",data['skuBundleId']
78
                print "Unable to compute deal for ",data['skuBundleId']
77
            
79
            
78
        
80
        
79
def recomputeDeal(skuBundleId):
81
def recomputeDeal(skuBundleId):
80
    """Lets recompute deal for this bundle"""
82
    """Lets recompute deal for this bundle"""
81
    print "Recomputing for bundleId",skuBundleId
83
    print "Recomputing for bundleId",skuBundleId