Subversion Repositories SmartDukaan

Rev

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

Rev 16869 Rev 17264
Line 92... Line 92...
92
    
92
    
93
    lowestSp = 0
93
    lowestSp = 0
94
    inStock = 0
94
    inStock = 0
95
    buyBoxPrice = 0
95
    buyBoxPrice = 0
96
    isBuyBox = 0
96
    isBuyBox = 0
97
    scraperFk = FlipkartScraper.FlipkartScraper()
-
 
98
    scraperProductPage = NewFlipkartScraper.FlipkartProductPageScraper()
97
    scraperProductPage = NewFlipkartScraper.FlipkartProductPageScraper()
99
    try:
98
    try:
100
        if data['marketPlaceUrl']!="" or data['marketPlaceUrl'] !="http://www.flipkart.com/ps/%s"%(data['identifier']):
-
 
101
            result = scraperProductPage.read(data['marketPlaceUrl'])
99
        result = scraperProductPage.read(data['identifier'])
102
            if result.get('lowestSp')!=0:
100
        if result.get('lowestSp')!=0:
103
                lowestSp = result.get('lowestSp')
101
            lowestSp = result.get('lowestSp')
104
                inStock = result.get('inStock')
102
            inStock = result.get('inStock')
105
                buyBoxPrice = result.get('buyBoxPrice')
103
            buyBoxPrice = result.get('buyBoxPrice')
106
    except:
104
    except:
107
        print "Unable to scrape product page %s" %(data['identifier'])
105
        print "Unable to scrape product page %s" %(data['identifier'])
-
 
106
        return
108
    
107
    
109
    
-
 
110
    if lowestSp == 0:
-
 
111
        url = "http://www.flipkart.com/ps/%s"%(data['identifier'].strip())
-
 
112
        while(retryCount < 3):
-
 
113
            try:
-
 
114
                vendorsData, buyBoxInfo = (scraperFk.read(url))
-
 
115
                fetched = True
-
 
116
                break
-
 
117
            except Exception as e:
-
 
118
                print "***Retry count ",retryCount 
-
 
119
                retryCount+=1
-
 
120
                if retryCount == 3:
-
 
121
                    fetched = False
-
 
122
                print e
-
 
123
        if not fetched:
-
 
124
            print "Unable to fetch data after multiple tries.Continue for %s"%(data['identifier'])
-
 
125
            return
-
 
126
        
108
        
127
        sortedVendorsData = []
-
 
128
        sortedVendorsData = sorted(vendorsData, key=itemgetter('sellingPrice'))
-
 
129
        print "data",sortedVendorsData
-
 
130
        lowestSp, iterator = (0,)*2
-
 
131
        for vData in sortedVendorsData:
-
 
132
            if iterator == 0:
-
 
133
                lowestSp = vData['sellingPrice']
-
 
134
            break
-
 
135
        if lowestSp > 0:
-
 
136
            inStock = 1
-
 
137
        if len(buyBoxInfo) > 0:
-
 
138
            buyBoxPrice = buyBoxInfo[0].get('sellingPrice')
-
 
139
        else:
-
 
140
            print "No info about buy box for %d"%(data.get('_id'))
-
 
141
    print lowestSp
109
    print lowestSp
142
    print inStock
110
    print inStock
143
    if buyBoxPrice is not None and buyBoxPrice == lowestSp:
111
    if buyBoxPrice is not None and buyBoxPrice == lowestSp:
144
        isBuyBox = 1
112
        isBuyBox = 1
145
    if lowestSp > 0:
113
    if lowestSp > 0: