Subversion Repositories SmartDukaan

Rev

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

Rev 13658 Rev 13679
Line 15... Line 15...
15
 
15
 
16
from pprint import pprint
16
from pprint import pprint
17
USERNAME='saholic1@gmail.com'
17
USERNAME='saholic1@gmail.com'
18
PASSWORD='spice@2020'
18
PASSWORD='spice@2020'
19
ORDER_TRACK_URL='https://m.flipkart.com/order_details'
19
ORDER_TRACK_URL='https://m.flipkart.com/order_details'
-
 
20
AFFILIATE_URL='https://www.flipkart.com/affiliate/login'
-
 
21
 
20
 
22
 
21
class Store(main.Store):
23
class Store(main.Store):
22
    OrderStatusMap = {
24
    OrderStatusMap = {
23
                      main.Store.ORDER_PLACED : ['In Progress','N/A'],
25
                      main.Store.ORDER_PLACED : ['In Progress','N/A'],
24
                      main.Store.ORDER_DELIVERED : ['Delivered'],
26
                      main.Store.ORDER_DELIVERED : ['Delivered'],
Line 32... Line 34...
32
        super(Store, self).__init__(store_id)
34
        super(Store, self).__init__(store_id)
33
 
35
 
34
    def getName(self):
36
    def getName(self):
35
        return "flipkart"
37
        return "flipkart"
36
    
38
    
-
 
39
    def scrapeAffiliate(self, startDate=None, endDate=None):
-
 
40
        br = getBrowserObject()
-
 
41
        br.open(AFFILIATE_URL)
-
 
42
        print br.select_form(name="fk-signin")
37
    
43
        
38
    
44
    
39
    
45
    
40
    def parseOrderRawHtml(self, orderId, subTagId, userId, rawHtml, orderSuccessUrl):
46
    def parseOrderRawHtml(self, orderId, subTagId, userId, rawHtml, orderSuccessUrl):
41
        br = getBrowserObject()
47
        br = getBrowserObject()
42
        url = ORDER_TRACK_URL + re.findall('.*(\?.*?)$', orderSuccessUrl,re.IGNORECASE)[0]
48
        url = ORDER_TRACK_URL + re.findall('.*(\?.*?)$', orderSuccessUrl,re.IGNORECASE)[0]
Line 84... Line 90...
84
                y = productInfo.findAll("span")
90
                y = productInfo.findAll("span")
85
                for suborderId in y:
91
                for suborderId in y:
86
                    if "value emp" in str(suborderId):
92
                    if "value emp" in str(suborderId):
87
                        #Sub Order ID
93
                        #Sub Order ID
88
                        print "Sub Order ID"  + suborderId.text
94
                        print "Sub Order ID"  + suborderId.text
-
 
95
                g = productInfo.findAll("div",{"class":"product-image-block"})
-
 
96
                for imageUrl in g:
-
 
97
                    print str(imageUrl.find("img")['src'])         
89
                x = productInfo.findAll("div",{"class":"product-info"})
98
                x = productInfo.findAll("div",{"class":"product-info"})
90
                for maik in x:
99
                for maik in x:
91
                    #Product title
100
                    #Product title
92
                    print maik.find("a",{"class":"product-title"}).text
101
                    print maik.find("a",{"class":"product-title"}).text
-
 
102
                    print str(maik.find("a")['href'])
-
 
103
                    start='pid='
-
 
104
                    s=str(maik.find("a")['href'])
-
 
105
                    print re.findall(re.escape(start)+"(.*)",s)[0]
93
                    mname = maik.findAll("span")
106
                    mname = maik.findAll("span")
94
                    k=0
107
                    k=0
95
                    while k<len(mname):
108
                    while k<len(mname):
96
                        if "note" in str(mname[k]):
109
                        if "note" in str(mname[k]):
97
                            if "Color:" in str(mname[k]):
110
                            if "Color:" in str(mname[k]):
Line 103... Line 116...
103
                            elif "Subtotal:" in str(mname[k]):
116
                            elif "Subtotal:" in str(mname[k]):
104
                                #SubTotal for the item
117
                                #SubTotal for the item
105
                                print "Sub Total"+mname[k+1].text
118
                                print "Sub Total"+mname[k+1].text
106
                            elif "Delivery:" in str(mname[k]):
119
                            elif "Delivery:" in str(mname[k]):
107
                                #Delivery Date for sub order
120
                                #Delivery Date for sub order
108
                                print "Delivery Date " +mname[k+1].text            
121
                                print "Delivery Date " +mname[k+1].text
-
 
122
                        if "key text-dim" in str(mname[k]):
-
 
123
                            if "Seller" in str(mname[k]):
-
 
124
                                print "Seller  URL : http://m.flipkart.com"+maik.findAll("a")[1]['href']
-
 
125
                                print "Seller "+maik.findAll("a")[1].text                
109
                        k=k+1           
126
                        k=k+1           
110
                status=-1    
127
                status=-1    
111
                #To track shipping details         
128
                #To track shipping details         
112
                n = productInfo.findAll("div",{"class":"tracking-progress grid-row cf"})
129
                n = productInfo.findAll("div",{"class":"tracking-progress grid-row cf"})
113
                for trackingStatus in n:
130
                for trackingStatus in n:
Line 120... Line 137...
120
                                else:     
137
                                else:     
121
                                    status = 2
138
                                    status = 2
122
                            else:
139
                            else:
123
                                status = 1 
140
                                status = 1 
124
                        else: 
141
                        else: 
125
                            status = 0     
142
                            status = 0
-
 
143
                    elif "approveDetails-ongoing" in str(tr):
-
 
144
                        status=0             
126
                    if "dead" in str(tr):
145
                    if "dead" in str(tr):
127
                        status = 4    
146
                        status = 4    
128
                print "Sub Order Status " + str(status)                      
147
                print "Sub Order Status " + str(status)                      
129
                f = productInfo.findAll("div",{"class":"c-tabs-content m-top active"})
148
                f = productInfo.findAll("div",{"class":"c-tabs-content m-top active"})
130
                for trackingDetailsActive in f:
149
                for trackingDetailsActive in f:
Line 153... Line 172...
153
                #To track shipping details         
172
                #To track shipping details         
154
                n = productInfo.findAll("div",{"class":"tracking-progress grid-row cf"})
173
                n = productInfo.findAll("div",{"class":"tracking-progress grid-row cf"})
155
                for trackingStatus in n:
174
                for trackingStatus in n:
156
                    tr = trackingStatus.findAll("div",{"class":"tap-bullet-area c-tab-trigger"})
175
                    tr = trackingStatus.findAll("div",{"class":"tap-bullet-area c-tab-trigger"})
157
                    if "approveDetails-complete" in str(tr):
176
                    if "approveDetails-complete" in str(tr):
-
 
177
                        print "Here"
158
                        if "processingDetails-complete" in str(tr):
178
                        if "processingDetails-complete" in str(tr):
-
 
179
                            print "There"
159
                            if "shippingDetails-complete" in str(tr):
180
                            if "shippingDetails-complete" in str(tr):
-
 
181
                                print "Share"
160
                                if "delivery-complete" in str(tr):
182
                                if "delivery-complete" in str(tr):
-
 
183
                                    print "Last"
161
                                    status = 3
184
                                    status = 3
162
                                else:     
185
                                else:     
163
                                    status = 2
186
                                    status = 2
164
                            else:
187
                            else:
165
                                status = 1 
188
                                status = 1 
Line 176... Line 199...
176
        order = collection.insert(order)
199
        order = collection.insert(order)
177
 
200
 
178
def main():
201
def main():
179
  
202
  
180
    store = getStore(2)
203
    store = getStore(2)
-
 
204
    store.scrapeAffiliate()
181
    #store.parseOrderRawHtml(12346, "subtagId", 122324,  "html", 'https://m.flipkart.com/orderresponse?reference_id=OD3016502908102575&token=0db4c692bacbfbfc158b52358ac9e91e&src=or&pr=1')
205
    #store.parseOrderRawHtml(12346, "subtagId", 122324,  "html", 'https://m.flipkart.com/orderresponse?reference_id=OD3016502908102575&token=0db4c692bacbfbfc158b52358ac9e91e&src=or&pr=1')
182
    #store.parseOrderRawHtml(12346, "subtagId", 122324,  "html", 'https://m.flipkart.com/orderresponse?reference_id=OD3018701137253850&token=f7402ddcf2b63b37cc6bc528cc115d2f&src=or&pr=1')
206
    #store.parseOrderRawHtml(12346, "subtagId", 122324,  "html", 'https://m.flipkart.com/orderresponse?reference_id=OD3018701137253850&token=f7402ddcf2b63b37cc6bc528cc115d2f&src=or&pr=1')
183
    store.parseOrderRawHtml(12346, "subtagId", 122324,  "html", 'https://m.flipkart.com/orderresponse?reference_id=OD0019279584515727&token=7d85d8c24d36b5a1efc8008634390c7e&src=or&pr=1')
207
    #store.parseOrderRawHtml(12346, "subtagId", 122324,  "html", 'https://m.flipkart.com/orderresponse?reference_id=OD0019279584515727&token=7d85d8c24d36b5a1efc8008634390c7e&src=or&pr=1')
184
    #store.flipkartOrderTracking(12346, "subtagId", 122324,  "html", 'https://m.flipkart.com/orderresponse?reference_id=OD0019279584515727&token=7d85d8c24d36b5a1efc8008634390c7e&src=or&pr=1')
208
    #store.flipkartOrderTracking(12346, "subtagId", 122324,  "html", 'https://m.flipkart.com/orderresponse?reference_id=OD0019279584515727&token=7d85d8c24d36b5a1efc8008634390c7e&src=or&pr=1')
-
 
209
    #store.parseOrderRawHtml(12346, "subtagId", 122324,  "html", 'https://m.flipkart.com/orderresponse?reference_id=OD0019365336126533&token=dbce2bd4dc4023295b436a7d3c7986c9&src=or&pr=1')
-
 
210
    #store.parseOrderRawHtml(12346, "subtagId", 122324,  "html", 'https://dl.flipkart.com/orderresponse?reference_id=OD1019453634552336&token=e8e04871ad65b532aa53fa82bb34b901&src=or&pr=1')
-
 
211
 
185
def ungzipResponse(r,b):
212
def ungzipResponse(r,b):
186
        headers = r.info()
213
        headers = r.info()
187
        if headers['Content-Encoding']=='gzip':
214
        if headers['Content-Encoding']=='gzip':
188
            import gzip
215
            import gzip
189
        print "********************"
216
        print "********************"