Subversion Repositories SmartDukaan

Rev

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

Rev 20391 Rev 20392
Line 24... Line 24...
24
import pymongo
24
import pymongo
25
import re
25
import re
26
import traceback
26
import traceback
27
import urllib
27
import urllib
28
import urllib2
28
import urllib2
-
 
29
from urlparse import urlparse
29
import zipfile
30
import zipfile
30
USERNAME='saholic1@gmail.com'
31
USERNAME='saholic1@gmail.com'
31
PASSWORD='spice@2020'
32
PASSWORD='spice@2020'
32
ORDER_TRACK_URL='https://m.flipkart.com/order_details'
33
ORDER_TRACK_URL='https://m.flipkart.com/order_details?src=or&pr=1&type=physical&'
33
AFFILIATE_URL='https://affiliate.flipkart.com/'
34
AFFILIATE_URL='https://affiliate.flipkart.com/'
34
AFFILIATE_LOGIN_URL='https://affiliate.flipkart.com/a_login'
35
AFFILIATE_LOGIN_URL='https://affiliate.flipkart.com/a_login'
35
AFF_REPORT_URL = "https://affiliate.flipkart.com/downloads/a_downloadRequest?type=OrdersReport&parameters=%s"
36
AFF_REPORT_URL = "https://affiliate.flipkart.com/downloads/a_downloadRequest?type=OrdersReport&parameters=%s"
36
AFF_DOWNLOAD_URL="https://affiliate.flipkart.com/downloads/file?id=%s"
37
AFF_DOWNLOAD_URL="https://affiliate.flipkart.com/downloads/file?id=%s"
37
AFF_STATUS_CANCELLED='cancelled'
38
AFF_STATUS_CANCELLED='cancelled'
Line 99... Line 100...
99
        orders = self._getActiveOrders()
100
        orders = self._getActiveOrders()
100
        for order in orders:
101
        for order in orders:
101
            print "Order", self.store_name, order['orderId']
102
            print "Order", self.store_name, order['orderId']
102
            try:
103
            try:
103
                closed = True
104
                closed = True
104
                url = ORDER_TRACK_URL + re.findall('.*(\?.*?)$', order['orderSuccessUrl'],re.IGNORECASE)[0]
105
                url = ORDER_TRACK_URL + urlparse(order['orderSuccessUrl']).query
105
                page = fetchResponseUsingProxy(url)
106
                page = fetchResponseUsingProxy(url)
106
                soup = BeautifulSoup(page,convertEntities=BeautifulSoup.HTML_ENTITIES)
107
                soup = BeautifulSoup(page,convertEntities=BeautifulSoup.HTML_ENTITIES)
107
                
108
                
108
                sections = soup.findAll("div", {"class":"ui-app-card-body"})
109
                sections = soup.findAll("div", {"class":"ui-app-card-body"})
109
                sections.pop(1)
110
                sections.pop(1)
Line 286... Line 287...
286
            
287
            
287
    def parseOrderRawHtml(self, orderId, subTagId, userId, rawHtml, orderSuccessUrl):
288
    def parseOrderRawHtml(self, orderId, subTagId, userId, rawHtml, orderSuccessUrl):
288
        resp= {}
289
        resp= {}
289
        try:
290
        try:
290
            br = getBrowserObject()
291
            br = getBrowserObject()
291
            url = ORDER_TRACK_URL + re.findall('.*(\?.*?)$', orderSuccessUrl,re.IGNORECASE)[0]
292
            url = ORDER_TRACK_URL + urlparse(orderSuccessUrl).query 
292
           
293
           
293
            response = br.open(url)
294
            response = br.open(url)
294
            page = ungzipResponse(response)
295
            page = ungzipResponse(response)
295
            
296
            
296
            merchantOrderId = re.findall('reference_id=(.*?)&', orderSuccessUrl,re.IGNORECASE)[0]
297
            merchantOrderId = re.findall('reference_id=(.*?)&', orderSuccessUrl,re.IGNORECASE)[0]
Line 329... Line 330...
329
                y = subOrder.find("header").findAll("span")
330
                y = subOrder.find("header").findAll("span")
330
                for suborderId in y:
331
                for suborderId in y:
331
                    if "value emp" in str(suborderId):
332
                    if "value emp" in str(suborderId):
332
                        merchantSubOrderId = suborderId.text
333
                        merchantSubOrderId = suborderId.text
333
                        break
334
                        break
334
                orderItems = subOrder.findAll("div", {"class":"ui-app-card product-list-item order-product-list-item m-bottom no_assoc"}, recursive=True)
335
                orderItems = subOrder.findAll("div", "product-list-item", recursive=True)
335
                i=0
336
                i=0
336
                for orderItem in orderItems:
337
                for orderItem in orderItems:
337
                    merchantOrder.placedOn
338
                    merchantOrder.placedOn
338
                    merchantSubOrderId = merchantSubOrderId + str(i)
339
                    merchantSubOrderId = merchantSubOrderId + str(i)
339
                    divs = orderItem.findAll('div', recursive=False)
340
                    divs = orderItem.findAll('div', recursive=False)
Line 417... Line 418...
417
    def _getStatusFromDetailedStatus(self, detailedStatus):
418
    def _getStatusFromDetailedStatus(self, detailedStatus):
418
        for key, value in Store.OrderStatusMap.iteritems():
419
        for key, value in Store.OrderStatusMap.iteritems():
419
            if detailedStatus.lower() in value:
420
            if detailedStatus.lower() in value:
420
                return key
421
                return key
421
        print "Detailed Status need to be mapped", detailedStatus, "Store:", self.store_name
422
        print "Detailed Status need to be mapped", detailedStatus, "Store:", self.store_name
422
        raise ParseException("_getStatusFromDetailedStatus", "Found new order status" + detailedStatus)
423
        raise ParseException("_getStatusFromDetailedStatus", "Found new order status" + detailedStatus)           
423
    
-
 
424
    def flipkartOrderTracking(self, orderId, subTagId, userId, rawHtml, orderSuccessUrl):
-
 
425
        br = getBrowserObject()
-
 
426
        url = ORDER_TRACK_URL + re.findall('.*(\?.*?)$', orderSuccessUrl,re.IGNORECASE)[0]
-
 
427
       
-
 
428
        response = br.open(url)
-
 
429
        page = ungzipResponse(response, br)
-
 
430
       
-
 
431
        
-
 
432
        soup = BeautifulSoup(page,convertEntities=BeautifulSoup.HTML_ENTITIES)
-
 
433
        
-
 
434
        
-
 
435
        mainOrder = soup.findAll("ul",{"class":"m-bottom p-cart"})
-
 
436
        #fetching suborders details
-
 
437
        for subOrder in mainOrder:
-
 
438
            subOrd = subOrder.findAll("li")
-
 
439
           
-
 
440
            subOrd.pop(len(subOrd)-1)
-
 
441
            for productInfo in subOrd:
-
 
442
                status=-1    
-
 
443
                #To track shipping details         
-
 
444
                n = productInfo.findAll("div",{"class":"tracking-progress grid-row cf"})
-
 
445
                for trackingStatus in n:
-
 
446
                    tr = trackingStatus.findAll("div",{"class":"tap-bullet-area c-tab-trigger"})
-
 
447
                    if "approveDetails-complete" in str(tr):
-
 
448
                        print "Here"
-
 
449
                        if "processingDetails-complete" in str(tr):
-
 
450
                            print "There"
-
 
451
                            if "shippingDetails-complete" in str(tr):
-
 
452
                                print "Share"
-
 
453
                                if "delivery-complete" in str(tr):
-
 
454
                                    print "Last"
-
 
455
                                    status = 3
-
 
456
                                else:     
-
 
457
                                    status = 2
-
 
458
                            else:
-
 
459
                                status = 1 
-
 
460
                        else: 
-
 
461
                            status = 0     
-
 
462
                    if "dead" in str(tr):
-
 
463
                        status = 4    
-
 
464
                print status                      
-
 
465
               
-
 
466
                
424
                
467
def _saveToOrderFlipkart(self, order):
425
def _saveToOrderFlipkart(self, order):
468
        collection = self.db.merchantOrder
426
        collection = self.db.merchantOrder
469
        order = collection.insert(order)
427
        order = collection.insert(order)
470
 
428