Subversion Repositories SmartDukaan

Rev

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

Rev 16421 Rev 16427
Line 81... Line 81...
81
        #for missingOrder in missingOrders:
81
        #for missingOrder in missingOrders:
82
        #    missingOrderUrls.append(ORDER_REDIRECT_URL%(missingOrder['merchantOrderId']))
82
        #    missingOrderUrls.append(ORDER_REDIRECT_URL%(missingOrder['merchantOrderId']))
83
        orders = self._getActiveOrders({'userId':userId, "subOrders.trackingUrl":{"$exists":False} }, {"merchantOrderId":1})
83
        orders = self._getActiveOrders({'userId':userId, "subOrders.trackingUrl":{"$exists":False} }, {"merchantOrderId":1})
84
        for order in orders:
84
        for order in orders:
85
            print order
85
            print order
86
            missingOrderUrls.append("https://paytm.com/shop/orderdetail/%s?actions=1&channel=web&version=2"%(order.get("merchantOrderId")))
86
            missingOrderUrls.append({"url":"https://paytm.com/shop/orderdetail/%s?actions=1&channel=web&version=2"%(order.get("merchantOrderId")), "referer":order.get("orderSuccessUrl")})
87
        return missingOrderUrls
87
        return missingOrderUrls
88
 
88
 
89
    def trackOrdersForUser(self, userId, url, rawHtml):
89
    def trackOrdersForUser(self, userId, url, rawHtml):
90
        merchantOrderId = find_between(rawHtml, "https://paytm.com/shop/orderdetail/","?actions=1&channel=web&version=2")
90
        merchantOrderId = find_between(rawHtml, "https://paytm.com/shop/orderdetail/","?actions=1&channel=web&version=2")
91
        directory = "/PaytmTrack/User" + str(userId)
91
        directory = "/PaytmTrack/User" + str(userId)
Line 96... Line 96...
96
        filename = directory + "/" + merchantOrderId + "-" +  datetime.strftime(datetime.now(), '%d-%m:%H:%M:%S')   
96
        filename = directory + "/" + merchantOrderId + "-" +  datetime.strftime(datetime.now(), '%d-%m:%H:%M:%S')   
97
        f = open(filename,'w')
97
        f = open(filename,'w')
98
        f.write(rawHtml) # python will convert \n to os.linesep
98
        f.write(rawHtml) # python will convert \n to os.linesep
99
        f.close() # you can omit in most cases as the destructor will call if
99
        f.close() # you can omit in most cases as the destructor will call if
100
        rawHtml = find_between(rawHtml,"<pre>", "</pre>")
100
        rawHtml = find_between(rawHtml,"<pre>", "</pre>")
-
 
101
        merchantOrder = self.db.merchantOrder.find_one({"merchantOrderId":merchantOrderId})
101
        if rawHtml == "":
102
        if rawHtml == "":
-
 
103
            tprint("Could not update " + str(merchantOrder['orderId']) + " For store " + self.getName())
-
 
104
            self.db.merchantOrder.update({"orderId":merchantOrder['orderId']}, {"$set":{"parseError":True}})
102
            raise    
105
            raise    
103
        ordermap = json.loads(rawHtml).get("order")
106
        ordermap = json.loads(rawHtml).get("order")
104
        merchantOrder = self.db.merchantOrder.find_one({"merchantOrderId":merchantOrderId})
-
 
105
        try:
107
        try:
106
            bulk = self.db.merchantOrder.initialize_ordered_bulk_op()
108
            bulk = self.db.merchantOrder.initialize_ordered_bulk_op()
107
            closed=True
109
            closed=True
108
            for item in ordermap.get("items"):
110
            for item in ordermap.get("items"):
109
                merchantSubOrderId = str(item.get("id"))
111
                merchantSubOrderId = str(item.get("id"))
Line 125... Line 127...
125
                            continue
127
                            continue
126
            if executeBulk:
128
            if executeBulk:
127
                bulk.find({"orderId":merchantOrder.get("orderId")}).update({"$set":{"closed":closed, "parseError":False}})
129
                bulk.find({"orderId":merchantOrder.get("orderId")}).update({"$set":{"closed":closed, "parseError":False}})
128
                bulk.execute()
130
                bulk.execute()
129
        except:
131
        except:
130
                tprint("Could not update " + str(merchantOrder['orderId']) + " For store " + self.getName())
132
            tprint("Could not update " + str(merchantOrder['orderId']) + " For store " + self.getName())
131
                self.db.merchantOrder.update({"orderId":merchantOrder['orderId']}, {"$set":{"parseError":True}})
133
            self.db.merchantOrder.update({"orderId":merchantOrder['orderId']}, {"$set":{"parseError":True}})
132
                traceback.print_exc()
134
            traceback.print_exc()
-
 
135
            raise
133
        
136
        
134
    def parseOrderRawHtml(self, orderId, subTagId, userId, rawHtml, orderSuccessUrl):
137
    def parseOrderRawHtml(self, orderId, subTagId, userId, rawHtml, orderSuccessUrl):
135
        
138
        
136
        #Expected is json
139
        #Expected is json
137
        orderSuccessUrl = find_between(orderSuccessUrl, "<pre>", "</pre>")
140
        orderSuccessUrl = find_between(orderSuccessUrl, "<pre>", "</pre>")