Subversion Repositories SmartDukaan

Rev

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

Rev 17257 Rev 17258
Line 35... Line 35...
35
class Store(MStore):
35
class Store(MStore):
36
    
36
    
37
    orderStatusRegexMap = { MStore.ORDER_PLACED : ['ordered from', 'not yet dispatched','dispatching now', 'preparing for dispatch'],
37
    orderStatusRegexMap = { MStore.ORDER_PLACED : ['ordered from', 'not yet dispatched','dispatching now', 'preparing for dispatch'],
38
                            MStore.ORDER_SHIPPED : ['dispatched on','dispatched', 'on the way', 'out for delivery', 'Out for delivery'],
38
                            MStore.ORDER_SHIPPED : ['dispatched on','dispatched', 'on the way', 'out for delivery', 'Out for delivery'],
39
                            MStore.ORDER_CANCELLED : ['return complete', 'refunded', 'cancelled'],
39
                            MStore.ORDER_CANCELLED : ['return complete', 'refunded', 'cancelled'],
40
                            MStore.ORDER_DELIVERED : ['delivered', 'your package was delivered']
40
                            MStore.ORDER_DELIVERED : ['delivered', 'your package was delivered', 'package was handed directly to customer']
41
                           }
41
                           }
42
 
42
 
43
    def __init__(self,store_id):
43
    def __init__(self,store_id):
44
        super(Store, self).__init__(store_id)
44
        super(Store, self).__init__(store_id)
45
        
45
        
Line 451... Line 451...
451
                bulk = self.db.merchantOrder.initialize_ordered_bulk_op()
451
                bulk = self.db.merchantOrder.initialize_ordered_bulk_op()
452
                for activeOrder in activeOrders:
452
                for activeOrder in activeOrders:
453
                    for orderEle in allOrders:
453
                    for orderEle in allOrders:
454
                        deliveredOn = None
454
                        deliveredOn = None
455
                        deliveryEstimate = None
455
                        deliveryEstimate = None
-
 
456
                        shippingEstimate = None
456
                        orderdiv = orderEle.find('div', {'class':'a-box a-color-offset-background order-info'}).find('div', {'class':'a-fixed-right-grid-col actions a-col-right'})
457
                        orderdiv = orderEle.find('div', {'class':'a-box a-color-offset-background order-info'}).find('div', {'class':'a-fixed-right-grid-col actions a-col-right'})
457
                        merchantOrderId = orderdiv.find('span', {'class':'a-color-secondary value'}).text.strip()
458
                        merchantOrderId = orderdiv.find('span', {'class':'a-color-secondary value'}).text.strip()
458
                        if merchantOrderId==activeOrder['merchantOrderId']:
459
                        if merchantOrderId==activeOrder['merchantOrderId']:
459
                            closed = True
460
                            closed = True
460
                            shipments = orderEle.findAll('div',{'class':re.compile('.*?a-box.*?')}, recursive=False)
461
                            shipments = orderEle.findAll('div',{'class':re.compile('.*?a-box.*?')}, recursive=False)
Line 466... Line 467...
466
                                    orderStatus = sdivs[0].findAll('div')[1].div.text.strip()
467
                                    orderStatus = sdivs[0].findAll('div')[1].div.text.strip()
467
                                except:
468
                                except:
468
                                    orderStatus = sdivs[0].findAll('div')[1].text.strip()
469
                                    orderStatus = sdivs[0].findAll('div')[1].text.strip()
469
                                print orderStatus
470
                                print orderStatus
470
                                try:
471
                                try:
-
 
472
                                    if "Dispatch estimate" in orderStatus:
-
 
473
                                        status = MStore.ORDER_PLACED
-
 
474
                                        shippingEstimate = orderStatus.split("Dispatch estimate").split("-")[0].strip()
471
                                    status = self._getStatusFromDetailedStatus(orderStatus)
475
                                    elif "Delivery estimate" in orderStatus:
-
 
476
                                        status = MStore.ORDER_SHIPPED
-
 
477
                                        deliveryEstimate = orderStatus.split("Delivery estimate").split("-")[0].strip()
472
                                except:
478
                                except:
473
                                    closed=False
479
                                    closed=False
474
                                    status = None
480
                                    status = None
475
                                if status == MStore.ORDER_DELIVERED:
481
                                if status == MStore.ORDER_DELIVERED:
476
                                    dateString = sdivs[0].span.text.strip().split("Delivered ")[1].strip()
482
                                    dateString = sdivs[0].span.text.strip().split("Delivered ")[1].strip()
477
                                    deliveredOn = datetime.strftime(getDateStringDelivered(dateString), '%d-%b-%y')
483
                                    deliveredOn = datetime.strftime(getDateStringDelivered(dateString), '%d-%b-%y')
478
                                if status == MStore.ORDER_SHIPPED:
484
                                if status == MStore.ORDER_SHIPPED:
479
                                    dateString = sdivs[0].span.text.strip().split("Arriving ")[1].strip()
485
                                    dateString = sdivs[0].span.text.strip().split("Arriving ")[1].strip()
480
                                    deliveryEstimate = datetime.strftime(getDateStringArriving(dateString), '%d-%b-%y')
486
                                    deliveryEstimate = datetime.strftime(getDateStringArriving(dateString), '%d-%b-%y')
481
#                                deliveryestimatespan = sdivs[0].find('span', {'class':'a-color-success'})
-
 
482
#                                deliveryEstimate = None
-
 
483
#                                if deliveryestimatespan is not None:
-
 
484
#                                    deliveryEstimate = deliveryestimatespan.find('span', {'class':'a-text-bold'}).text.strip()
-
 
-
 
487
 
485
                                productDivs = shipdiv.find('div', {'class':re.compile('.*?a-spacing-top-medium.*?')}).find('div', {'class':'a-row'}).findAll('div', recursive=False)
488
                                productDivs = shipdiv.find('div', {'class':re.compile('.*?a-spacing-top-medium.*?')}).find('div', {'class':'a-row'}).findAll('div', recursive=False)
486
                                trackingUrl = None
489
                                trackingUrl = None
487
                                for buttonDiv in shipdiv.findAll('span', {'class':'a-button-inner'}):
490
                                for buttonDiv in shipdiv.findAll('span', {'class':'a-button-inner'}):
488
                                    if buttonDiv.find('a').text.strip()=='Track package':
491
                                    if buttonDiv.find('a').text.strip()=='Track package':
489
                                        trackingUrl = buttonDiv.find('a')['href'].strip()
492
                                        trackingUrl = buttonDiv.find('a')['href'].strip()
Line 499... Line 502...
499
                                            findMap = {"orderId": activeOrder['orderId'], "subOrders.merchantSubOrderId": subOrder.get("merchantSubOrderId")}
502
                                            findMap = {"orderId": activeOrder['orderId'], "subOrders.merchantSubOrderId": subOrder.get("merchantSubOrderId")}
500
                                            updateMap = {}
503
                                            updateMap = {}
501
                                            closedStatus = False
504
                                            closedStatus = False
502
                                            updateMap['subOrders.$.imgUrl'] = imgUrl
505
                                            updateMap['subOrders.$.imgUrl'] = imgUrl
503
                                            updateMap['subOrders.$.lastTracked'] = timestamp
506
                                            updateMap['subOrders.$.lastTracked'] = timestamp
-
 
507
                                            if status:
504
                                            updateMap['subOrders.$.detailedStatus'] = status
508
                                                updateMap['subOrders.$.detailedStatus'] = status
505
                                            cashbackStatus = subOrder.get("cashBackStatus")
509
                                                updateMap['subOrders.$.status'] = status 
506
                                            updateMap['subOrders.$.status'] = status 
510
                                                cashbackStatus = subOrder.get("cashBackStatus")
507
                                        
511
                                        
508
                                            if status==MStore.ORDER_DELIVERED:
512
                                            if status==MStore.ORDER_DELIVERED:
509
                                                if not deliveredOn:                               
513
                                                if not deliveredOn:                               
510
                                                    updateMap['subOrders.$.deliveredOn'] = deliveredOn
514
                                                    updateMap['subOrders.$.deliveredOn'] = deliveredOn
511
                                                closedStatus = True
515
                                                closedStatus = True
Line 520... Line 524...
520
                                            if status==MStore.ORDER_SHIPPED:
524
                                            if status==MStore.ORDER_SHIPPED:
521
                                                if deliveryEstimate:   
525
                                                if deliveryEstimate:   
522
                                                    updateMap['subOrders.$.estimatedDeliveryDate'] = deliveryEstimate
526
                                                    updateMap['subOrders.$.estimatedDeliveryDate'] = deliveryEstimate
523
                                                if trackingUrl is not None:
527
                                                if trackingUrl is not None:
524
                                                    updateMap['subOrders.$.trackingUrl'] = trackingUrl
528
                                                    updateMap['subOrders.$.trackingUrl'] = trackingUrl
-
 
529
                                            if shippingEstimate:   
-
 
530
                                                updateMap['subOrders.$.estimatedShippingDate'] = shippingEstimate
525
                                            if not closedStatus:
531
                                            if not closedStatus:
526
                                                closed = False
532
                                                closed = False
527
                                            bulk.find(findMap).update({'$set' : updateMap})
533
                                            bulk.find(findMap).update({'$set' : updateMap})
528
                                            break
534
                                            break
529
                            bulk.find({'orderId': activeOrder['orderId']}).update({'$set':{'closed': closed}})            
535
                            bulk.find({'orderId': activeOrder['orderId']}).update({'$set':{'closed': closed}})            
Line 818... Line 824...
818
        
824
        
819
    finally:
825
    finally:
820
        session.close()
826
        session.close()
821
    
827
    
822
if __name__ == '__main__':
828
if __name__ == '__main__':
-
 
829
        readSSh("/AmazonTrack/User7091/orderSummary14-10:13:29:40")
823
        main()
830
        #main()
824
        #getDateStringArriving()
831
        #getDateStringArriving()
825
832