Subversion Repositories SmartDukaan

Rev

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

Rev 17434 Rev 18326
Line 20... Line 20...
20
    
20
    
21
    def read(self, identifier):
21
    def read(self, identifier):
22
        response_data = ""
22
        response_data = ""
23
        self.fsn = identifier.upper().strip()
23
        self.fsn = identifier.upper().strip()
24
        url = "http://mobileapi.flipkart.net/2/discover/productInfo/0?pids=%s"%(self.fsn)
24
        url = "http://mobileapi.flipkart.net/2/discover/productInfo/0?pids=%s"%(self.fsn)
-
 
25
        print url
25
        try:
26
        try:
26
            
27
            
27
            """quick fix,need to add it conf""" 
28
            """quick fix,need to add it conf""" 
28
            
29
            
29
            response_data = fetchResponseUsingProxy(url, headers, livePricing=None, proxy=True, flipkart=False)                
30
            response_data = fetchResponseUsingProxy(url, headers, livePricing=None, proxy=True, flipkart=False)      
30
            print "Fetched response from flipkart for %s" %(url)
31
            print "Fetched response from flipkart for %s" %(url)
31
            #redirect_url = response.url
32
            #redirect_url = response.url
32
 
33
 
33
        except Exception as e:
34
        except Exception as e:
34
            traceback.print_exc()
35
            traceback.print_exc()
Line 46... Line 47...
46
        input_json = json.loads(self.response_data)
47
        input_json = json.loads(self.response_data)
47
        inStock = not input_json['RESPONSE']['productInfo'][self.fsn]['availabilityDetails']['product.isOOS']
48
        inStock = not input_json['RESPONSE']['productInfo'][self.fsn]['availabilityDetails']['product.isOOS']
48
        preferred_seller = input_json['RESPONSE']['productInfo'][self.fsn]['preferredListingId']
49
        preferred_seller = input_json['RESPONSE']['productInfo'][self.fsn]['preferredListingId']
49
        buyBoxPrice = 0
50
        buyBoxPrice = 0
50
        lowestSp = 0
51
        lowestSp = 0
-
 
52
        try:
-
 
53
            for priceMap in  input_json['RESPONSE']['productInfo'][self.fsn]['priceWidget']['prices']:
-
 
54
                if priceMap['isFinal']:
-
 
55
                    buyBoxPrice =  float(priceMap['price'])
-
 
56
        except:
-
 
57
            traceback.print_exc()
51
        for x in (input_json['RESPONSE']['productInfo'][self.fsn]['marketplace']):
58
        for x in (input_json['RESPONSE']['productInfo'][self.fsn]['marketplace']):
52
#             print x['marketplace.listId'],
59
#             print x['marketplace.listId'],
53
#             print '\t',
60
#             print '\t',
54
#             print x['product.availabilityDetails']['product.isOOS'],
61
#             print x['product.availabilityDetails']['product.isOOS'],
55
#             print '\t',
62
#             print '\t',
Line 60... Line 67...
60
#             print x['seller.displayName']
67
#             print x['seller.displayName']
61
            
68
            
62
            if not x['product.availabilityDetails']['product.isOOS']:
69
            if not x['product.availabilityDetails']['product.isOOS']:
63
                if lowestSp == 0 or lowestSp > x['product.selling_price']:
70
                if lowestSp == 0 or lowestSp > x['product.selling_price']:
64
                    lowestSp = x['product.selling_price']
71
                    lowestSp = x['product.selling_price']
65
                
72
                if buyBoxPrice ==0:
66
                if x['marketplace.listId'] == preferred_seller:
73
                    if x['marketplace.listId'] == preferred_seller:
67
                    buyBoxPrice = x['product.selling_price']
74
                        buyBoxPrice = x['product.selling_price']
68
            
75
        
-
 
76
        if buyBoxPrice < lowestSp:
69
                    
77
            lowestSp = buyBoxPrice            
70
        return {'lowestSp':lowestSp,'inStock':int(inStock),'buyBoxPrice':buyBoxPrice} 
78
        return {'lowestSp':lowestSp,'inStock':int(inStock),'buyBoxPrice':buyBoxPrice} 
71
            
79
            
72
 
80
 
73
def main():
81
def main():
74
    print datetime.datetime.now()
82
    print datetime.datetime.now()
75
    scraper = FlipkartProductPageScraper()
83
    scraper = FlipkartProductPageScraper()
76
    print scraper.read('MOBE9QXZK8VMMNDV')
84
    print scraper.read('MOBE5PFFKF8Y3CZP')
77
    print datetime.datetime.now()
85
    print datetime.datetime.now()
78
 
86
 
79
 
87
 
80
if __name__ == '__main__':
88
if __name__ == '__main__':
81
    main()
89
    main()
82
90