Subversion Repositories SmartDukaan

Rev

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

Rev 14703 Rev 14722
Line 72... Line 72...
72
                resp["result"] = 'ORDER_NOT_CREATED'
72
                resp["result"] = 'ORDER_NOT_CREATED'
73
                return resp
73
                return resp
74
        
74
        
75
        else:
75
        else:
76
            try:
76
            try:
-
 
77
                mo = self.db.merchantOrder.find_one({"orderId":orderId})
-
 
78
                if mo is not None:
-
 
79
                    merchantOrder = Order(orderId, userId, subTagId, self.store_id, orderSuccessUrl)
-
 
80
                    merchantOrder.createdOn = mo.get("createdOn")
-
 
81
                    merchantOrder.createdOnInt =  mo.get("createdOnInt")
-
 
82
                else:
77
                merchantOrder = Order(orderId, userId, subTagId, self.store_id, orderSuccessUrl, False)
83
                    merchantOrder = Order(orderId, userId, subTagId, self.store_id, orderSuccessUrl, False)
78
                soup = BeautifulSoup(rawHtml)
84
                soup = BeautifulSoup(rawHtml)
79
                try:
85
                try:
80
                    self.parseOldStlye(merchantOrder, soup)
86
                    self.parseOldStlye(merchantOrder, soup)
81
                except:
87
                except:
82
                    try:
88
                    try:
Line 181... Line 187...
181
                
187
                
182
            
188
            
183
                subOrder = SubOrder(productTitle, productUrl, merchantOrder.placedOn, unitPrice*quantity, status, quantity)
189
                subOrder = SubOrder(productTitle, productUrl, merchantOrder.placedOn, unitPrice*quantity, status, quantity)
184
                subOrder.merchantSubOrderId = str(counter) + " of " + merchantOrder.merchantOrderId
190
                subOrder.merchantSubOrderId = str(counter) + " of " + merchantOrder.merchantOrderId
185
                subOrder.estimatedDeliveryDate = estimatedDelivery
191
                subOrder.estimatedDeliveryDate = estimatedDelivery
-
 
192
                estDlvyTime = datetime.strptime(estimatedDelivery.split('-')[0].strip(), "%A %d %B %Y")
-
 
193
                createdOn = datetime.fromtimestamp(merchantOrder.createdOnInt)
-
 
194
                subOrder.trackAfter = int(time.mktime(max(estDlvyTime-timedelta(days=4),createdOn + timedelta(days=3)).timetuple()))
186
                subOrder.productCode = productUrl.split('/')[5]
195
                subOrder.productCode = productUrl.split('/')[5]
187
                subOrder.detailedStatus = detailedStatus
196
                subOrder.detailedStatus = detailedStatus
188
                (cashbackAmount, percentage) = self.getCashbackAmount(subOrder.productCode, unitPrice*quantity)
197
                (cashbackAmount, percentage) = self.getCashbackAmount(subOrder.productCode, unitPrice*quantity)
189
                cashbackStatus = Store.CB_PENDING
198
                cashbackStatus = Store.CB_PENDING
190
                if cashbackAmount <= 0:
199
                if cashbackAmount <= 0:
Line 265... Line 274...
265
                productUrl = "http://www.amazon.in" + detailDivs[0].a.get('href')
274
                productUrl = "http://www.amazon.in" + detailDivs[0].a.get('href')
266
                subOrder = SubOrder(productTitle, productUrl, merchantOrder.placedOn, amountPaid, MStore.ORDER_PLACED, quantity)
275
                subOrder = SubOrder(productTitle, productUrl, merchantOrder.placedOn, amountPaid, MStore.ORDER_PLACED, quantity)
267
                subOrder.productCode = productUrl.split('/')[5]
276
                subOrder.productCode = productUrl.split('/')[5]
268
                subOrder.unitPrice = unitPrice
277
                subOrder.unitPrice = unitPrice
269
                subOrder.merchantSubOrderId = str(i) + " of " + merchantOrder.merchantOrderId
278
                subOrder.merchantSubOrderId = str(i) + " of " + merchantOrder.merchantOrderId
-
 
279
                estDlvyTime = datetime.now()
270
                if deliverySpan is not None:
280
                if deliverySpan is not None:
271
                    subOrder.estimatedDeliveryDate = deliverySpan.span.text.strip() 
281
                    subOrder.estimatedDeliveryDate = deliverySpan.span.text.strip()
-
 
282
                    estDate = subOrder.estimatedDeliveryDate.split("-")[0].strip()
-
 
283
                    subOrder.estimatedDeliveryInt = int(time.mktime((datetime.strptime(estDate, "%A %d %B %Y")).timetuple()))
-
 
284
                    estDlvyTime = datetime.strptime(estDate, "%A %d %B %Y")
-
 
285
                
-
 
286
                createdOn = datetime.fromtimestamp(merchantOrder.createdOnInt)
-
 
287
                subOrder.trackAfter = int(time.mktime(max(estDlvyTime-timedelta(days=4),createdOn + timedelta(days=3)).timetuple()))/1000
272
                subOrder.detailedStatus = subOrderStatus
288
                subOrder.detailedStatus = subOrderStatus
273
                subOrder.deliveryCharges = shippingPrice
289
                subOrder.deliveryCharges = shippingPrice
274
                subOrder.imgUrl = imgDiv.img["src"]
290
                subOrder.imgUrl = imgDiv.img["src"]
275
                (cashbackAmount, percentage) = self.getCashbackAmount(subOrder.productCode, amountPaid)
291
                (cashbackAmount, percentage) = self.getCashbackAmount(subOrder.productCode, amountPaid)
276
                cashbackStatus = Store.CB_PENDING
292
                cashbackStatus = Store.CB_PENDING
Line 283... Line 299...
283
                subOrders.append(subOrder)
299
                subOrders.append(subOrder)
284
        merchantOrder.status='success'
300
        merchantOrder.status='success'
285
        self._updateToOrder(todict(merchantOrder))
301
        self._updateToOrder(todict(merchantOrder))
286
        
302
        
287
    def parseCancelled(self, merchantOrder,soup):
303
    def parseCancelled(self, merchantOrder,soup):
-
 
304
        try:
288
        fonts = soup.body.findAll("table", recursive=False)[1].findAll("font")
305
            fonts = soup.body.findAll("table", recursive=False)[1].findAll("font")
289
        if fonts[0].text == "Important Message":
306
            if fonts[0].text == "Important Message":
290
            if fonts[1].text=="This order has been cancelled.":
307
                if fonts[1].text=="This order has been cancelled.":
291
                merchantOrder.closed = True
308
                    merchantOrder.closed = True
292
                merchantOrder.status = "cancelled"
309
                    merchantOrder.status = "cancelled"
293
                merchantOrder.requireDetail = False
310
                    merchantOrder.requireDetail = False
294
                self._updateToOrder(todict(merchantOrder))
311
                    self._updateToOrder(todict(merchantOrder))
-
 
312
                    return
-
 
313
                else:
-
 
314
                    raise ParseException("parseCancelled", "Found detailed status" + fonts[1].text)
295
            else:
315
            else:
296
                raise ParseException("parseCancelled", "Found detailed status" + fonts[1].text)
316
                raise ParseException("parseCancelled", "Found detailed status" + fonts[1].text)
297
        else:
317
        except:
298
            orderDetails = soup.body.find(id="orderDetails")
318
            orderDetails = soup.body.find(id="orderDetails")
299
            if orderDetails is not None and orderDetails.h4.text == "This order has been cancelled.":
319
            if orderDetails is not None and orderDetails.h4.text == "This order has been cancelled.":
300
                merchantOrder.closed = True
320
                merchantOrder.closed = True
301
                merchantOrder.status = "cancelled"
321
                merchantOrder.status = "cancelled"
302
                merchantOrder.requireDetail = False
322
                merchantOrder.requireDetail = False
Line 493... Line 513...
493
#                     ('Accept', 'text/html,application/xhtml+xml,application/json,application/xml;q=0.9,*/*;q=0.8'),
513
#                     ('Accept', 'text/html,application/xhtml+xml,application/json,application/xml;q=0.9,*/*;q=0.8'),
494
#                     ('Accept-Encoding', 'gzip,deflate,sdch'),                  
514
#                     ('Accept-Encoding', 'gzip,deflate,sdch'),                  
495
#                     ('Accept-Language', 'en-US,en;q=0.8'),                     
515
#                     ('Accept-Language', 'en-US,en;q=0.8'),                     
496
#                     ('Accept-Charset', 'ISO-8859-1,utf-8;q=0.7,*;q=0.3')]
516
#                     ('Accept-Charset', 'ISO-8859-1,utf-8;q=0.7,*;q=0.3')]
497
#    store.scrapeStoreOrders()
517
#    store.scrapeStoreOrders()
498
    store.parseOrderRawHtml(2121, "13232", 14, readSSh("/home/amit/917.html"), "https://www.amazon.in/gp/bOy/spc/handlers/static-submit-decoupled.html/ref=ox_spc_place_order?ie=UTF8&hasWorkingJavascript=")
518
    store.parseOrderRawHtml(2121, "13232", 14, readSSh("/home/amit/1313.html"), "https://www.amazon.in/gp/css/summary/edit.html?orderID=171-5857029-0804336")
-
 
519
    #store.parseOrderRawHtml(2121, "13232", 14, readSSh("/home/amit/f1.html"), "https://www.amazon.in/gp/css/summary/edit.html?orderID=171-5196461-3230730")
499
    #readSSh("/tmp/User211/2015-04-01 15:31:42.250309")
520
    #readSSh("/tmp/User211/2015-04-01 15:31:42.250309")
500
    #store.scrapeAffiliate()
521
    #store.scrapeAffiliate()
501
def readSSh(fileName):
522
def readSSh(fileName):
502
    try:
523
    try:
503
            str1 = open(fileName).read()
524
            str1 = open(fileName).read()