Subversion Repositories SmartDukaan

Rev

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

Rev 14168 Rev 14175
Line 60... Line 60...
60
        print "Inside json creator for %s" %(url)
60
        print "Inside json creator for %s" %(url)
61
        info = []
61
        info = []
62
        oddSeller = soup.findAll("div" , {"class" : "line seller-item odd "})
62
        oddSeller = soup.findAll("div" , {"class" : "line seller-item odd "})
63
        for data in oddSeller:
63
        for data in oddSeller:
64
            temp={}
64
            temp={}
65
            try:
-
 
66
                businessDays = data.find('span', attrs={'class' : re.compile('fk-deliverable.*')})
-
 
67
                shippingTime = businessDays.find('span', attrs={'class' : re.compile('fk-bold')}).string.replace('to','').replace('business days.','').strip().replace('  ','-')
-
 
68
                temp['shippingTime']=shippingTime
-
 
69
            except:
-
 
70
                pass
-
 
71
            price = data.find('span', attrs={'class' : re.compile('pxs-final-price.*')}).string.strip('Rs.').strip()
65
            price = data.find('span', attrs={'class' : re.compile('pxs-final-price.*')}).string.strip('Rs.').strip()
72
            temp['sellingPrice']=float(price)
66
            temp['sellingPrice']=float(price)
73
            for sellerInfo in data.findAll("div",{"class":re.compile(".*seller-info*")}):
-
 
74
                sellerName = sellerInfo.find('a').string
-
 
75
                temp['sellerName'] = sellerName
-
 
76
            for metrics in data.find("div",{"class":"fk-text-right"}):
67
            for metrics in data.find("div",{"class":"fk-text-right"}):
77
                try:
68
                try:
78
                    metric = metrics.findAll('input', {'type': 'submit'})
69
                    metric = metrics.findAll('input', {'type': 'submit'})
79
                except AttributeError:
70
                except AttributeError:
80
                    continue
71
                    continue
81
                try:
-
 
82
                    inputTags = metric[0]['data-lst-buytrend']
-
 
83
                except TypeError:
-
 
84
                    continue
-
 
85
                dataMetrics = metric[0]['data-listing-metrics']
72
                dataMetrics = metric[0]['data-listing-metrics']
86
                try:
-
 
87
                    buyTrend = inputTags[0:str(inputTags).index('NWSR')].replace('_','')
-
 
88
                except ValueError:
-
 
89
                    buyTrend = inputTags[0:str(inputTags).index('WSR')].replace('_','')
-
 
90
                temp['buyTrend']=buyTrend
-
 
91
                dataMetric = dataMetrics.split(';')
73
                dataMetric = dataMetrics.split(';')
92
                sellerCode = dataMetric[0]
-
 
93
                temp['sellerCode']=sellerCode
-
 
94
                temp['sellingPriceMetric'] = float(dataMetric[1])
74
                temp['sellingPriceMetric'] = float(dataMetric[1])
95
                if not temp.has_key('shippingTime'):
-
 
96
                    print "Populating shipping time from metrics"
-
 
97
                    temp['shippingTime'] = dataMetric[3]
-
 
98
                temp['sellerScore'] = int(dataMetric[4])
-
 
99
                try:
75
                try:
100
                    temp['shippingFee'] = float(dataMetric[2])
76
                    temp['shippingFee'] = float(dataMetric[2])
101
                except:
77
                except:
102
                    temp['shippingFee'] = 0.0
78
                    temp['shippingFee'] = 0.0
103
                temp['sellingPrice'] = temp['sellingPrice'] + temp['shippingFee']  
79
                temp['sellingPrice'] = temp['sellingPrice'] + temp['shippingFee']  
104
                info.append(temp)
80
                info.append(temp)
105
        evenSeller = soup.findAll("div" , {"class" : "line seller-item even "})
81
        evenSeller = soup.findAll("div" , {"class" : "line seller-item even "})
106
        for data in evenSeller:
82
        for data in evenSeller:
107
            temp={}
83
            temp={}
108
            price = data.find('span', attrs={'class' : re.compile('pxs-final-price.*')}).string.strip('Rs.')
84
            price = data.find('span', attrs={'class' : re.compile('pxs-final-price.*')}).string.strip('Rs.')
109
            try:
-
 
110
                businessDays = data.find('span', attrs={'class' : re.compile('fk-deliverable.*')})
-
 
111
                shippingTime = businessDays.find('span', attrs={'class' : re.compile('fk-bold')}).string.replace('to','').replace('business days.','').strip().replace('  ','-')
-
 
112
                temp['shippingTime']=shippingTime
-
 
113
            except:
-
 
114
                pass
-
 
115
            temp['sellingPrice']=float(price)
85
            temp['sellingPrice']=float(price)
116
            for sellerInfo in data.findAll("div",{"class":re.compile(".*seller-info*")}):
-
 
117
                sellerName = sellerInfo.find('a').string
-
 
118
                temp['sellerName'] = sellerName
-
 
119
            for metrics in data.find("div",{"class":"fk-text-right"}):
86
            for metrics in data.find("div",{"class":"fk-text-right"}):
120
                try:
87
                try:
121
                    metric = metrics.findAll('input', {'type': 'submit'})
88
                    metric = metrics.findAll('input', {'type': 'submit'})
122
                except AttributeError:
89
                except AttributeError:
123
                    continue
90
                    continue
124
                try:
-
 
125
                    inputTags = metric[0]['data-lst-buytrend']
-
 
126
                except TypeError:
-
 
127
                    continue
-
 
128
                dataMetrics = metric[0]['data-listing-metrics']
91
                dataMetrics = metric[0]['data-listing-metrics']
129
                try:
-
 
130
                    buyTrend = inputTags[0:str(inputTags).index('NWSR')].replace('_','')
-
 
131
                except ValueError:
-
 
132
                    buyTrend = inputTags[0:str(inputTags).index('WSR')].replace('_','')
-
 
133
                temp['buyTrend']=buyTrend
-
 
134
                dataMetric = dataMetrics.split(';')
92
                dataMetric = dataMetrics.split(';')
135
                temp['sellerCode'] = dataMetric[0] 
-
 
136
                temp['sellingPriceMetric'] = float(dataMetric[1])
93
                temp['sellingPriceMetric'] = float(dataMetric[1])
137
                if not temp.has_key('shippingTime'):
-
 
138
                    print "Populating shipping time from metrics"
-
 
139
                    temp['shippingTime'] = dataMetric[3]
-
 
140
                temp['sellerScore'] = int(dataMetric[4])
-
 
141
                try:
94
                try:
142
                    temp['shippingFee'] = float(dataMetric[2])
95
                    temp['shippingFee'] = float(dataMetric[2])
143
                except:
96
                except:
144
                    temp['shippingFee'] = 0.0
97
                    temp['shippingFee'] = 0.0
145
                temp['sellingPrice'] = temp['sellingPrice'] + temp['shippingFee']  
98
                temp['sellingPrice'] = temp['sellingPrice'] + temp['shippingFee']