Subversion Repositories SmartDukaan

Rev

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

Rev 15539 Rev 15630
Line 27... Line 27...
27
USERNAME='saholic1@gmail.com'
27
USERNAME='saholic1@gmail.com'
28
PASSWORD='spice@2020'
28
PASSWORD='spice@2020'
29
ORDER_TRACK_URL='https://m.flipkart.com/order_details'
29
ORDER_TRACK_URL='https://m.flipkart.com/order_details'
30
AFFILIATE_URL='https://www.flipkart.com/affiliate/login'
30
AFFILIATE_URL='https://www.flipkart.com/affiliate/login'
31
AFFILIATE_LOGIN_URL='https://www.flipkart.com/affiliate/a_login'
31
AFFILIATE_LOGIN_URL='https://www.flipkart.com/affiliate/a_login'
32
AFF_REPORT_URL='http://www.flipkart.com/affiliate/reports/ordersReport?order_status_filter=%s&startdate=%s&enddate=%s'
32
AFF_REPORT_URL='http://www.flipkart.com/affiliate/reports/ordersReport?order_status_filter=%s&startdate=%s&enddate=%s&page=%s'
33
AFF_STATUS_CANCELLED='cancelled'
33
AFF_STATUS_CANCELLED='cancelled'
34
AFF_STATUS_APPROVED='approved'
34
AFF_STATUS_APPROVED='approved'
35
AFF_STATUS_DISAPPROVED='disapproved'
35
AFF_STATUS_DISAPPROVED='disapproved'
36
AFF_STATUS_PENDING='pending'
36
AFF_STATUS_PENDING='pending'
37
categoryMap = {3:"Mobiles", 5:"Tablets"}
37
categoryMap = {3:"Mobiles", 5:"Tablets"}
Line 163... Line 163...
163
        br.open(AFFILIATE_LOGIN_URL, urllib.urlencode(data))
163
        br.open(AFFILIATE_LOGIN_URL, urllib.urlencode(data))
164
        for delta in range(1,2):
164
        for delta in range(1,2):
165
            yester5date = date.today() - timedelta(delta)
165
            yester5date = date.today() - timedelta(delta)
166
            syester5date = yester5date.strftime('%Y-%m-%d')
166
            syester5date = yester5date.strftime('%Y-%m-%d')
167
            for status in [AFF_STATUS_PENDING, AFF_STATUS_CANCELLED, AFF_STATUS_DISAPPROVED]:
167
            for status in [AFF_STATUS_PENDING, AFF_STATUS_CANCELLED, AFF_STATUS_DISAPPROVED]:
-
 
168
                hasPagination=True
-
 
169
                page = 0
-
 
170
                while hasPagination:
-
 
171
                    page +=1
168
                try:
172
                    try:
169
                    br.open(AFF_REPORT_URL % (status, syester5date, syester5date))
173
                        br.open(AFF_REPORT_URL % (status, syester5date, syester5date, page))
170
                except:
174
                    except:
171
                    tprint("Could not fetch data for Status %s and date %s"%(status, syester5date))
175
                        tprint("Could not fetch data for Status %s and date %s"%(status, syester5date))
172
                page = ungzipResponse(br.response())
176
                    page = ungzipResponse(br.response())
173
                soup = BeautifulSoup(page,convertEntities=BeautifulSoup.HTML_ENTITIES)
177
                    soup = BeautifulSoup(page,convertEntities=BeautifulSoup.HTML_ENTITIES)
174
                soup.table
178
                    soup.table
175
                try:
179
                    try:
176
                    tableElement = soup.findAll('table', {'class':'report-table fixtable'})[1]
180
                        tableElement = soup.findAll('table', {'class':'report-table fixtable'})[1]
177
                except:
181
                    except:
178
                    continue
182
                        continue
179
                trElements = tableElement.findAll('tr')
183
                    trElements = tableElement.findAll('tr')
180
                trElements.pop(0)
184
                    trElements.pop(0)
-
 
185
                    hasPagination = len(trElements) > 0
-
 
186
                        
181
                for trElement in trElements:
187
                    for trElement in trElements:
182
                    tdElements = trElement.findAll('td')
188
                        tdElements = trElement.findAll('td')
183
                    productCode = re.findall(r'pid=(.*)$', tdElements[0].find('a')['href'])[0]
189
                        productCode = re.findall(r'pid=(.*)$', tdElements[0].find('a')['href'])[0]
184
                    quantity =int(tdElements[3].text)
190
                        quantity =int(tdElements[3].text)
185
                    price = int(float(tdElements[2].text.strip().replace(",","")))
191
                        price = int(float(tdElements[2].text.strip().replace(",","")))
186
                    payOut = int(float(tdElements[6].text.strip().replace(",","")))
192
                        payOut = int(float(tdElements[6].text.strip().replace(",","")))
187
                    saleAmount = int(float(tdElements[4].text.strip().replace(",","")))
193
                        saleAmount = int(float(tdElements[4].text.strip().replace(",","")))
188
                    subTagId = tdElements[7].text.strip()
194
                        subTagId = tdElements[7].text.strip()
189
                    category = tdElements[1].text.strip()
195
                        category = tdElements[1].text.strip()
190
                    affiliateInfo = FlipkartAffiliateInfo(subTagId, syester5date, productCode, price, quantity, saleAmount, payOut, status, category)
196
                        affiliateInfo = FlipkartAffiliateInfo(subTagId, syester5date, productCode, price, quantity, saleAmount, payOut, status, category)
191
                    affiliateInfo.productTitle =  tdElements[0].find('a').text
197
                        affiliateInfo.productTitle =  tdElements[0].find('a').text
192
                    #updateMap['subOrders.$.unitPrice'] = price
198
                        #updateMap['subOrders.$.unitPrice'] = price
193
                    #updateMap['subOrders.$.cashBackAmount'], updateMap['subOrders.$.cashBacPercentage'] = self.getCashbackAmount(productCode, price)
199
                        #updateMap['subOrders.$.cashBackAmount'], updateMap['subOrders.$.cashBacPercentage'] = self.getCashbackAmount(productCode, price)
194
                    offers.append(affiliateInfo)
200
                        offers.append(affiliateInfo)
195
        self._saveToAffiliate(offers)
201
        self._saveToAffiliate(offers)
196
        
202
        
197
        yester5date = date.today() - timedelta(1)
203
        yester5date = date.today() - timedelta(1)
198
        syester5date = yester5date.strftime('%Y-%m-%d')
204
        syester5date = yester5date.strftime('%Y-%m-%d')
199
        self.db.flipkartOrderAffiliateInfo.find({"saleDate":syester5date})
205
        self.db.flipkartOrderAffiliateInfo.find({"saleDate":syester5date})
Line 434... Line 440...
434
    print(m.digest())
440
    print(m.digest())
435
 
441
 
436
def main():
442
def main():
437
  
443
  
438
    store = getStore(2)
444
    store = getStore(2)
439
    #store.scrapeAffiliate()
445
    store.scrapeAffiliate()
440
    store.scrapeStoreOrders()
446
    #store.scrapeStoreOrders()
441
    #store.parseOrderRawHtml(12346, "subtagId", 122324,  "html", 'https://m.flipkart.com/orderresponse?reference_id=OD3016502908102575&token=0db4c692bacbfbfc158b52358ac9e91e&src=or&pr=1')
447
    #store.parseOrderRawHtml(12346, "subtagId", 122324,  "html", 'https://m.flipkart.com/orderresponse?reference_id=OD3016502908102575&token=0db4c692bacbfbfc158b52358ac9e91e&src=or&pr=1')
442
    #store.parseOrderRawHtml(12346, "subtagId", 122324,  "html", 'https://m.flipkart.com/orderresponse?reference_id=OD3018701137253850&token=f7402ddcf2b63b37cc6bc528cc115d2f&src=or&pr=1')
448
    #store.parseOrderRawHtml(12346, "subtagId", 122324,  "html", 'https://m.flipkart.com/orderresponse?reference_id=OD3018701137253850&token=f7402ddcf2b63b37cc6bc528cc115d2f&src=or&pr=1')
443
    #store.parseOrderRawHtml(12346, "subtagId", 122324,  "html", 'https://m.flipkart.com/orderresponse?reference_id=OD0019279584515727&token=7d85d8c24d36b5a1efc8008634390c7e&src=or&pr=1')
449
    #store.parseOrderRawHtml(12346, "subtagId", 122324,  "html", 'https://m.flipkart.com/orderresponse?reference_id=OD0019279584515727&token=7d85d8c24d36b5a1efc8008634390c7e&src=or&pr=1')
444
    #store.flipkartOrderTracking(12346, "subtagId", 122324,  "html", 'https://m.flipkart.com/orderresponse?reference_id=OD0019279584515727&token=7d85d8c24d36b5a1efc8008634390c7e&src=or&pr=1')
450
    #store.flipkartOrderTracking(12346, "subtagId", 122324,  "html", 'https://m.flipkart.com/orderresponse?reference_id=OD0019279584515727&token=7d85d8c24d36b5a1efc8008634390c7e&src=or&pr=1')
445
    #store.parseOrderRawHtml(12346, "subtagId", 122324,  "html", 'https://m.flipkart.com/orderresponse?reference_id=OD0019365336126533&token=dbce2bd4dc4023295b436a7d3c7986c9&src=or&pr=1')
451
    #store.parseOrderRawHtml(12346, "subtagId", 122324,  "html", 'https://m.flipkart.com/orderresponse?reference_id=OD0019365336126533&token=dbce2bd4dc4023295b436a7d3c7986c9&src=or&pr=1')