Subversion Repositories SmartDukaan

Rev

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

Rev 14810 Rev 14813
Line 44... Line 44...
44
    def getName(self):
44
    def getName(self):
45
        return "amazon"
45
        return "amazon"
46
    
46
    
47
    def parseOrderRawHtml(self, orderId, subTagId, userId, rawHtml, orderSuccessUrl, insert=False):
47
    def parseOrderRawHtml(self, orderId, subTagId, userId, rawHtml, orderSuccessUrl, insert=False):
48
        resp = {}
48
        resp = {}
-
 
49
        resp['result'] = 'ORDER_NOT_CREATED'
49
        if ORDER_SUCCESS_URL in orderSuccessUrl or THANKYOU_URL in orderSuccessUrl:
50
        if ORDER_SUCCESS_URL in orderSuccessUrl or THANKYOU_URL in orderSuccessUrl:
50
            try:
51
            try:
51
                soup = BeautifulSoup(rawHtml)
52
                soup = BeautifulSoup(rawHtml)
52
                try:
53
                try:
53
                    orderUrl = soup.find('div', {"id":"thank-you-box-wrapper"}).div.findAll('div', recursive=False)[1].a['href']
54
                    orderUrl = soup.find('div', {"id":"thank-you-box-wrapper"}).div.findAll('div', recursive=False)[1].a['href']
Line 66... Line 67...
66
                    resp["htmlRequired"] = True
67
                    resp["htmlRequired"] = True
67
                    resp['orderId'] = orderId
68
                    resp['orderId'] = orderId
68
                else:
69
                else:
69
                    resp['result'] = 'ORDER_ALREADY_CREATED_IGNORED'
70
                    resp['result'] = 'ORDER_ALREADY_CREATED_IGNORED'
70
                    
71
                    
71
                return resp
-
 
72
            except:
72
            except:
-
 
73
                #Write all cases here for Order Not created Known
73
                try:
74
                try:
74
                    if 'Securely redirecting you' in soup.h3.text:
75
                    if 'Securely redirecting you' in soup.h3.text:
75
                        resp['result'] = 'PAYMNET_REDIRECT'
76
                        resp['result'] = 'ORDER_NOT_CREATED_KNOWN'
76
                    else:
77
                    else:
77
                        resp['result'] = 'ORDER_NOT_CREATED'
78
                        raise
78
                except:
79
                except:
-
 
80
                    if soup.h1.text in ['This is a duplicate order', 'There was a problem with your payment.']:
79
                    resp["result"] = 'ORDER_NOT_CREATED'
81
                        resp['result'] = 'ORDER_NOT_CREATED_KNOWN'
80
                return resp
82
            return resp
81
        
83
            
82
        else:
84
        else:
83
            try:
85
            try:
84
                mo = self.db.merchantOrder.find_one({"orderId":orderId})
86
                mo = self.db.merchantOrder.find_one({"orderId":orderId})
85
                if mo is not None:
87
                if mo is not None:
86
                    merchantOrder = Order(orderId, userId, subTagId, self.store_id, orderSuccessUrl, False)
88
                    merchantOrder = Order(orderId, userId, subTagId, self.store_id, orderSuccessUrl, False)
Line 96... Line 98...
96
                        traceback.print_exc()
98
                        traceback.print_exc()
97
                        self.parseNewStlye(merchantOrder, soup)
99
                        self.parseNewStlye(merchantOrder, soup)
98
                    except:
100
                    except:
99
                        traceback.print_exc()
101
                        traceback.print_exc()
100
                        self.parseCancelled(merchantOrder, soup)
102
                        self.parseCancelled(merchantOrder, soup)
101
                resp['result'] = 'ORDER_CREATED'
103
                resp['result'] = 'DETAIL_CREATED'
102
                return resp    
104
                return resp    
103
            except:
105
            except:
104
                try:
-
 
105
                    self.parserest(soup)
-
 
106
                    resp['result'] = 'PARSED_ORDER_NOT_CREATED'
-
 
107
                    return resp    
-
 
108
                except:
-
 
109
                    order = self.db.merchantOrder.find_one({"orderId":orderId})
106
                order = self.db.merchantOrder.find_one({"orderId":orderId})
110
                    if order is not None:
107
                if order is not None:
111
                        self.db.merchantOrder.update({"orderId":orderId}, {"$set":{"status":"parse_failed"}})
108
                    self.db.merchantOrder.update({"orderId":orderId}, {"$set":{"status":"parse_failed"}})
112
                    print "Error occurred"
109
                print "Error occurred"
113
                    resp['result'] = 'ORDER_NOT_CREATED'
110
                resp['result'] = 'DETAIL_NOT_CREATED'
114
                    traceback.print_exc()
111
                traceback.print_exc()
115
                    return resp    
112
            return resp    
116
                    
113
                    
117
    #This should be exposed from api for specific sources
114
    #This should be exposed from api for specific sources
118
    def scrapeStoreOrders(self):
115
    def scrapeStoreOrders(self):
119
        orders = self.db.merchantOrder.find({"storeId":1, "closed":False, "subOrders.closed":False, "subOrders.trackingUrl":{"$exists":True}})
116
        orders = self.db.merchantOrder.find({"storeId":1, "closed":False, "subOrders.closed":False, "subOrders.trackingUrl":{"$exists":True}})
120
        for merchantOrder in orders:
117
        for merchantOrder in orders:
Line 530... Line 527...
530
#                     ('Accept', 'text/html,application/xhtml+xml,application/json,application/xml;q=0.9,*/*;q=0.8'),
527
#                     ('Accept', 'text/html,application/xhtml+xml,application/json,application/xml;q=0.9,*/*;q=0.8'),
531
#                     ('Accept-Encoding', 'gzip,deflate,sdch'),                  
528
#                     ('Accept-Encoding', 'gzip,deflate,sdch'),                  
532
#                     ('Accept-Language', 'en-US,en;q=0.8'),                     
529
#                     ('Accept-Language', 'en-US,en;q=0.8'),                     
533
#                     ('Accept-Charset', 'ISO-8859-1,utf-8;q=0.7,*;q=0.3')]
530
#                     ('Accept-Charset', 'ISO-8859-1,utf-8;q=0.7,*;q=0.3')]
534
#    store.scrapeStoreOrders()
531
#    store.scrapeStoreOrders()
535
    store.parseOrderRawHtml(1306, "13232", 14, readSSh("/home/amit/322.html"), "https://www.amazon.in/gp/buy/thankyou/handlers/display.html?ie=UTF8&from=Visa&fromAnywhere=1&isFromThirdParty=1&purchaseId=404-602")
532
    store.parseOrderRawHtml(1306, "13232", 14, readSSh("/home/amit/322.html"), "https://www.amazon.in/gp/css/summary/edit.html?orderID=171-5570474-5548341")
536
    #store.parseOrderRawHtml(2121, "13232", 14, readSSh("/home/amit/f1.html"), "https://www.amazon.in/gp/css/summary/edit.html?orderID=171-5196461-3230730")
533
    #store.parseOrderRawHtml(2121, "13232", 14, readSSh("/home/amit/f1.html"), "https://www.amazon.in/gp/css/summary/edit.html?orderID=171-5196461-3230730")
537
    #readSSh("/tmp/User211/2015-04-01 15:31:42.250309")
534
    #readSSh("/tmp/User211/2015-04-12 10:32:41.905765")
538
    #store.scrapeAffiliate()
535
    #store.scrapeAffiliate()
539
def readSSh(fileName):
536
def readSSh(fileName):
540
    try:
537
    try:
541
            str1 = open(fileName).read()
538
            str1 = open(fileName).read()
542
            return str1
539
            return str1