| Line 49... |
Line 49... |
| 49 |
This is to map order statuses of our system to order statuses of snapdeal.
|
49 |
This is to map order statuses of our system to order statuses of snapdeal.
|
| 50 |
And our statuses will change accordingly.
|
50 |
And our statuses will change accordingly.
|
| 51 |
|
51 |
|
| 52 |
'''
|
52 |
'''
|
| 53 |
OrderStatusMap = {
|
53 |
OrderStatusMap = {
|
| 54 |
MStore.ORDER_PLACED : ['in progress', 'pending for verification', 'not available', 'in process', 'processing', 'processed', 'under verification'],
|
54 |
MStore.ORDER_PLACED : ['in progress', 'pending for verification', 'not available', 'in process',
|
| - |
|
55 |
'processing', 'processed', 'under verification', 'readying for dispatch',
|
| - |
|
56 |
'waiting for courier to pick up', ''],
|
| 55 |
MStore.ORDER_DELIVERED : ['delivered'],
|
57 |
MStore.ORDER_DELIVERED : ['delivered','delivered successfully!'],
|
| 56 |
MStore.ORDER_SHIPPED : ['in transit', 'dispatched'],
|
58 |
MStore.ORDER_SHIPPED : ['in transit', 'dispatched', 'handed over to courier', 'undelivered. update delivery details!'],
|
| 57 |
MStore.ORDER_CANCELLED : ['closed for vendor reallocation', 'cancelled', 'product returned by courier', 'returned', 'n/a', 'courier returned', 'a new order placed with a different seller', 'closed', 'cancellation in progress']
|
59 |
MStore.ORDER_CANCELLED : ['closed for vendor reallocation', 'cancelled', 'product returned by courier', 'returned', 'n/a', 'courier returned',
|
| - |
|
60 |
'a new order placed with a different seller', 'closed', 'cancellation in progress', 'verification failed. order cancelled',
|
| - |
|
61 |
'cancelled. payment refunded','closed. new order placed']
|
| 58 |
}
|
62 |
}
|
| 59 |
|
63 |
|
| 60 |
CONF_CB_AMOUNT = MStore.CONF_CB_DISCOUNTED_PRICE
|
64 |
CONF_CB_AMOUNT = MStore.CONF_CB_DISCOUNTED_PRICE
|
| 61 |
def __init__(self,store_id):
|
65 |
def __init__(self,store_id):
|
| 62 |
super(Store, self).__init__(store_id)
|
66 |
super(Store, self).__init__(store_id)
|
| Line 478... |
Line 482... |
| 478 |
productTitle = map1['title']
|
482 |
productTitle = map1['title']
|
| 479 |
productUrl = map1['productUrl']
|
483 |
productUrl = map1['productUrl']
|
| 480 |
subOrder = SubOrder(productTitle, productUrl, placedOn, amountPaid)
|
484 |
subOrder = SubOrder(productTitle, productUrl, placedOn, amountPaid)
|
| 481 |
if(s.get('deliveryDate') is not None):
|
485 |
if(s.get('deliveryDate') is not None):
|
| 482 |
print "Delivered On",
|
486 |
print "Delivered On",
|
| 483 |
subOrder.deliveredOn = datetime.strftime(utils.fromTimeStamp(s.get('deliveryDate')/1000),'%Y-%m-%d')
|
487 |
subOrder.deliveredOn = datetime.strftime(utils.fromTimeStamp(s.get('deliveryDate')/1000),'%d %b, %Y')
|
| 484 |
subOrder.status = MStore.ORDER_DELIVERED
|
488 |
subOrder.status = MStore.ORDER_DELIVERED
|
| 485 |
subOrder.detailedStatus = MStore.ORDER_DELIVERED
|
489 |
subOrder.detailedStatus = MStore.ORDER_DELIVERED
|
| 486 |
elif s['suborderStatus'].get('macroDescription')== 'Closed':
|
490 |
elif s['suborderStatus'].get('macroDescription')== 'Closed':
|
| 487 |
if s['suborderStatus'].get('value')== 'Close for vendor reallocation':
|
491 |
if s['suborderStatus'].get('value')== 'Close for vendor reallocation':
|
| 488 |
subOrder.detailedStatus = 'Close for vendor reallocation'
|
492 |
subOrder.detailedStatus = 'Close for vendor reallocation'
|
| Line 501... |
Line 505... |
| 501 |
subOrder.unitPrice = s['offerPrice'] -s['internalCashbackValue'] - s['externalCashbackValue']
|
505 |
subOrder.unitPrice = s['offerPrice'] -s['internalCashbackValue'] - s['externalCashbackValue']
|
| 502 |
subOrder.amount = subOrder.unitPrice - s['offerDiscount'] - s['sdCash']
|
506 |
subOrder.amount = subOrder.unitPrice - s['offerDiscount'] - s['sdCash']
|
| 503 |
try:
|
507 |
try:
|
| 504 |
try:
|
508 |
try:
|
| 505 |
if s['shipDateRange']['start']==s['shipDateRange']['end']:
|
509 |
if s['shipDateRange']['start']==s['shipDateRange']['end']:
|
| 506 |
subOrder.estimatedShippingDate = datetime.strftime(utils.fromTimeStamp(s['shipDateRange']['start']/1000),'%Y-%m-%d')
|
510 |
subOrder.estimatedShippingDate = datetime.strftime(utils.fromTimeStamp(s['shipDateRange']['start']/1000),'%d %b, %Y')
|
| 507 |
else:
|
511 |
else:
|
| 508 |
subOrder.estimatedShippingDate = datetime.strftime(utils.fromTimeStamp(s['shipDateRange']['start']/1000),'%Y-%m-%d') + " - " + datetime.strftime(utils.fromTimeStamp(s['shipDateRange']['end']/1000),'%Y-%m-%d')
|
512 |
subOrder.estimatedShippingDate = datetime.strftime(utils.fromTimeStamp(s['shipDateRange']['start']/1000),'%d %b, %Y') + " - " + datetime.strftime(utils.fromTimeStamp(s['shipDateRange']['end']/1000),'%d %b, %Y')
|
| 509 |
except:
|
513 |
except:
|
| 510 |
if s['deliveryDateRange']['start']==s['deliveryDateRange']['end']:
|
514 |
if s['deliveryDateRange']['start']==s['deliveryDateRange']['end']:
|
| 511 |
subOrder.estimatedDeliveryDate = datetime.strftime(utils.fromTimeStamp(s['deliveryDateRange']['start']/1000),'%Y-%m-%d')
|
515 |
subOrder.estimatedDeliveryDate = datetime.strftime(utils.fromTimeStamp(s['deliveryDateRange']['start']/1000),'%d %b, %Y')
|
| 512 |
else:
|
516 |
else:
|
| 513 |
subOrder.estimatedDeliveryDate = datetime.strftime(utils.fromTimeStamp(s['deliveryDateRange']['start']/1000),'%Y-%m-%d') + " - " + datetime.strftime('%Y-%m-%d',utils.fromTimeStamp(s['deliveryDateRange']['end']/1000),'%Y-%m-%d')
|
517 |
subOrder.estimatedDeliveryDate = datetime.strftime(utils.fromTimeStamp(s['deliveryDateRange']['start']/1000),'%d %b, %Y') + " - " + datetime.strftime(utils.fromTimeStamp(s['deliveryDateRange']['end']/1000),'%d %b, %Y')
|
| 514 |
except:
|
518 |
except:
|
| 515 |
pass
|
519 |
pass
|
| 516 |
subOrder.offerDiscount = s['offerDiscount']
|
520 |
subOrder.offerDiscount = s['offerDiscount']
|
| 517 |
subOrder.unitPrice = s['offerPrice']
|
521 |
subOrder.unitPrice = s['offerPrice']
|
| 518 |
merchantSubOrders.append(subOrder)
|
522 |
merchantSubOrders.append(subOrder)
|
| Line 531... |
Line 535... |
| 531 |
|
535 |
|
| 532 |
def scrapeStoreOrders(self,):
|
536 |
def scrapeStoreOrders(self,):
|
| 533 |
#collectionMap = {'palcedOn':1}
|
537 |
#collectionMap = {'palcedOn':1}
|
| 534 |
orders = self._getActiveOrders()
|
538 |
orders = self._getActiveOrders()
|
| 535 |
for order in orders:
|
539 |
for order in orders:
|
| - |
|
540 |
order = obj(order)
|
| 536 |
print "Order", self.store_name, order['orderId']
|
541 |
print "Order", self.store_name, order.orderId
|
| 537 |
try:
|
542 |
try:
|
| 538 |
url = ORDER_TRACK_URL + re.findall('.*(\?.*?)$', order['orderSuccessUrl'],re.IGNORECASE)[0]
|
543 |
url = order.orderTrackingUrl
|
| 539 |
page = fetchResponseUsingProxy(url)
|
544 |
page = fetchResponseUsingProxy(url)
|
| 540 |
#page=page.decode("utf-8")
|
545 |
#page=page.decode("utf-8")
|
| 541 |
soup = BeautifulSoup(page)
|
- |
|
| 542 |
try:
|
546 |
try:
|
| - |
|
547 |
pq = PyQuery(page)
|
| - |
|
548 |
subOrderStatusMap={}
|
| - |
|
549 |
for el in pq('div.cardLayout.pad-10.mb-10'):
|
| - |
|
550 |
elpq = PyQuery(el)
|
| - |
|
551 |
try:
|
| - |
|
552 |
subOrderId = elpq("div.subOrderId").text().split(":")[1].strip()
|
| - |
|
553 |
subOrderStatusMap[subOrderId] = elpq
|
| - |
|
554 |
except:
|
| - |
|
555 |
pass
|
| - |
|
556 |
closedForReco = {}
|
| - |
|
557 |
for suborder in order.subOrders:
|
| - |
|
558 |
if suborder.closed:
|
| - |
|
559 |
if suborder.merchantSubOrderId in subOrderStatusMap:
|
| - |
|
560 |
del subOrderStatusMap[suborder.merchantSubOrderId]
|
| - |
|
561 |
continue
|
| - |
|
562 |
if subOrderStatusMap.has_key(suborder.merchantSubOrderId):
|
| - |
|
563 |
elpq = subOrderStatusMap.get(suborder.merchantSubOrderId)
|
| - |
|
564 |
del subOrderStatusMap[suborder.merchantSubOrderId]
|
| - |
|
565 |
if elpq("#trackLink").attr("href"):
|
| - |
|
566 |
suborder.trackingUrl = elpq("#trackLink").attr("href")
|
| - |
|
567 |
if elpq('span.subOrdStatusText').text():
|
| - |
|
568 |
suborder.estimatedDeliveryDate=elpq('span.subOrdStatusText').text().strip()
|
| - |
|
569 |
suborder.detailedStatus = elpq("div.orderStatus span").text().strip()
|
| - |
|
570 |
if suborder.detailedStatus == 'Closed. New Order Placed':
|
| - |
|
571 |
closedForReco[suborder.merchantSubOrderId] = suborder
|
| - |
|
572 |
suborder.status = self._getStatusFromDetailedStatus(suborder.detailedStatus)
|
| - |
|
573 |
|
| - |
|
574 |
if len(closedForReco) == len(subOrderStatusMap) and len(closedForReco)>0:
|
| - |
|
575 |
productCode = ''
|
| - |
|
576 |
allProductsSame = True
|
| - |
|
577 |
for subOrderId, subo in closedForReco.iteritems():
|
| - |
|
578 |
if productCode == '':
|
| - |
|
579 |
productCode = subo.productCode
|
| - |
|
580 |
continue
|
| - |
|
581 |
if subo.productCode != productCode:
|
| - |
|
582 |
allProductsSame = False
|
| - |
|
583 |
break
|
| - |
|
584 |
subOrderStatusMap
|
| - |
|
585 |
if allProductsSame:
|
| - |
|
586 |
print "singlereco", order.orderId
|
| - |
|
587 |
suborderNew = obj(todict(suborder))
|
| - |
|
588 |
for key, elpq in subOrderStatusMap.iteritems():
|
| - |
|
589 |
suborderNew.merchantSubOrderId = key
|
| - |
|
590 |
if elpq("#trackLink").attr("href"):
|
| - |
|
591 |
suborderNew.trackingUrl = elpq("#trackLink").attr("href")
|
| - |
|
592 |
if elpq('span.subOrdStatusText').text():
|
| - |
|
593 |
suborderNew.estimatedDeliveryDate=elpq('span.subOrdStatusText').text().strip()
|
| - |
|
594 |
suborderNew.detailedStatus = elpq("div.orderStatus span").text().strip()
|
| - |
|
595 |
suborderNew.status = self._getStatusFromDetailedStatus(suborder.detailedStatus)
|
| - |
|
596 |
order.subOrders.append(suborderNew)
|
| - |
|
597 |
else:
|
| - |
|
598 |
print "All products not same", order.orderId
|
| - |
|
599 |
else:
|
| - |
|
600 |
pass
|
| - |
|
601 |
#Lookout for ordersummary page for exact mapping
|
| 543 |
self.tryBParsing(order, soup)
|
602 |
self.populateDerivedFields(order)
|
| - |
|
603 |
self._updateToOrder(todict(order))
|
| 544 |
except:
|
604 |
except:
|
| 545 |
traceback.print_exc()
|
605 |
traceback.print_exc()
|
| - |
|
606 |
soup = BeautifulSoup(page)
|
| - |
|
607 |
try:
|
| - |
|
608 |
self.tryBParsing(order, soup)
|
| - |
|
609 |
except:
|
| - |
|
610 |
traceback.print_exc()
|
| 546 |
sections = soup.findAll("section")
|
611 |
sections = soup.findAll("section")
|
| 547 |
orderEl = sections[1]
|
612 |
orderEl = sections[1]
|
| 548 |
orderTrs = orderEl.findAll("tr")
|
613 |
orderTrs = orderEl.findAll("tr")
|
| 549 |
|
614 |
|
| 550 |
placedOn = str(orderTrs[0].findAll("td")[1].text)
|
615 |
placedOn = str(orderTrs[0].findAll("td")[1].text)
|
| 551 |
sections.pop(0)
|
616 |
sections.pop(0)
|
| 552 |
sections.pop(0)
|
617 |
sections.pop(0)
|
| 553 |
|
618 |
|
| 554 |
subOrders = sections
|
619 |
subOrders = sections
|
| 555 |
bulk = self.db.merchantOrder.initialize_ordered_bulk_op()
|
620 |
bulk = self.db.merchantOrder.initialize_ordered_bulk_op()
|
| 556 |
closed = True
|
621 |
closed = True
|
| 557 |
for subOrderElement in subOrders:
|
622 |
for subOrderElement in subOrders:
|
| 558 |
div1 = subOrderElement.findAll("div", {"class": "blk lrPad subordrs"})
|
623 |
div1 = subOrderElement.findAll("div", {"class": "blk lrPad subordrs"})
|
| 559 |
if len(div1)<=0:
|
624 |
if len(div1)<=0:
|
| 560 |
raise ParseException("subOrder", "Could not Parse suborders for Snapdeal")
|
625 |
raise ParseException("subOrder", "Could not Parse suborders for Snapdeal")
|
| 561 |
subOrder = None
|
626 |
subOrder = None
|
| 562 |
breakFlag = False
|
627 |
breakFlag = False
|
| 563 |
for strDiv in str(div1).split("<div class=\"seperator\"></div>"):
|
628 |
for strDiv in str(div1).split("<div class=\"seperator\"></div>"):
|
| 564 |
div = BeautifulSoup(strDiv)
|
629 |
div = BeautifulSoup(strDiv)
|
| 565 |
divStr = str(div)
|
630 |
divStr = str(div)
|
| 566 |
divStr = divStr.replace("\n","").replace("\t", "")
|
631 |
divStr = divStr.replace("\n","").replace("\t", "")
|
| 567 |
updateMap = {}
|
632 |
updateMap = {}
|
| 568 |
for line in divStr.split("<br />"):
|
633 |
for line in divStr.split("<br />"):
|
| 569 |
if "Suborder ID" in line:
|
634 |
if "Suborder ID" in line:
|
| 570 |
merchantSubOrderId = re.findall(r'\d+', line)[0]
|
635 |
merchantSubOrderId = re.findall(r'\d+', line)[0]
|
| 571 |
#break if suborder is inactive
|
636 |
#break if suborder is inactive
|
| 572 |
subOrder = self._isSubOrderActive(order, merchantSubOrderId)
|
637 |
subOrder = self._isSubOrderActive(order, merchantSubOrderId)
|
| 573 |
if subOrder is None:
|
638 |
if subOrder is None:
|
| 574 |
subOrders = self.parseSubOrder(subOrderElement, placedOn)
|
639 |
subOrders = self.parseSubOrder(subOrderElement, placedOn)
|
| 575 |
self.db.merchantOrder.update({"orderId":order['orderId']},{'$push':{"subOrders":{"$each":todict(subOrders)}}})
|
640 |
self.db.merchantOrder.update({"orderId":order['orderId']},{'$push':{"subOrders":{"$each":todict(subOrders)}}})
|
| 576 |
print "Added new suborders to Order id - ", order['orderId']
|
641 |
print "Added new suborders to Order id - ", order['orderId']
|
| 577 |
closed = False
|
642 |
closed = False
|
| 578 |
breakFlag = True
|
643 |
breakFlag = True
|
| 579 |
break
|
644 |
break
|
| 580 |
elif subOrder['closed']:
|
645 |
elif subOrder['closed']:
|
| 581 |
breakFlag = True
|
646 |
breakFlag = True
|
| 582 |
break
|
647 |
break
|
| 583 |
else:
|
648 |
else:
|
| 584 |
findMap = {"orderId": order['orderId'], "subOrders.merchantSubOrderId": merchantSubOrderId}
|
649 |
findMap = {"orderId": order['orderId'], "subOrders.merchantSubOrderId": merchantSubOrderId}
|
| 585 |
elif "Status :" in line:
|
650 |
elif "Status :" in line:
|
| 586 |
detailedStatus = re.findall('>(.*?)</span>', line, re.IGNORECASE)[0]
|
651 |
detailedStatus = re.findall('>(.*?)</span>', line, re.IGNORECASE)[0]
|
| 587 |
updateMap["subOrders.$.detailedStatus"] = detailedStatus
|
652 |
updateMap["subOrders.$.detailedStatus"] = detailedStatus
|
| 588 |
status = self._getStatusFromDetailedStatus(detailedStatus)
|
653 |
status = self._getStatusFromDetailedStatus(detailedStatus)
|
| 589 |
closedStatus = status in [Store.ORDER_DELIVERED, Store.ORDER_CANCELLED]
|
654 |
closedStatus = status in [Store.ORDER_DELIVERED, Store.ORDER_CANCELLED]
|
| 590 |
if status is not None:
|
655 |
if status is not None:
|
| 591 |
updateMap["subOrders.$.status"] = status
|
656 |
updateMap["subOrders.$.status"] = status
|
| 592 |
if detailedStatus == 'Closed For Vendor Reallocation':
|
657 |
if detailedStatus == 'Closed For Vendor Reallocation':
|
| 593 |
#if it is more than 6hours mark closed.
|
658 |
#if it is more than 6hours mark closed.
|
| 594 |
closeAt = subOrder.get("closeAt")
|
659 |
closeAt = subOrder.get("closeAt")
|
| 595 |
if closeAt is None:
|
660 |
if closeAt is None:
|
| 596 |
closeAt = datetime.now() + timedelta(hours=6)
|
661 |
closeAt = datetime.now() + timedelta(hours=6)
|
| 597 |
updateMap["subOrders.$.closeAt"] = datetime.strftime(closeAt,"%Y-%m-%d %H:%M:%S")
|
662 |
updateMap["subOrders.$.closeAt"] = datetime.strftime(closeAt,"%Y-%m-%d %H:%M:%S")
|
| - |
|
663 |
else:
|
| - |
|
664 |
closeAt = datetime.strptime(closeAt,"%Y-%m-%d %H:%M:%S")
|
| - |
|
665 |
if datetime.now() > closeAt:
|
| - |
|
666 |
closedStatus = True
|
| - |
|
667 |
#Close if not applicable suborders are not closed
|
| - |
|
668 |
if utils.fromTimeStamp(order['createdOnInt'] + 35*86400*1000) < datetime.now() and subOrder['cashBackStatus']==utils.CB_NA:
|
| - |
|
669 |
closedStatus=True
|
| - |
|
670 |
|
| - |
|
671 |
|
| - |
|
672 |
if closedStatus:
|
| - |
|
673 |
#if status is closed then change the paybackStatus accordingly
|
| - |
|
674 |
updateMap["subOrders.$.closed"] = True
|
| - |
|
675 |
if status == Store.ORDER_DELIVERED:
|
| - |
|
676 |
if subOrder.get("cashBackStatus") == Store.CB_PENDING:
|
| - |
|
677 |
updateMap["subOrders.$.cashBackStatus"] = Store.CB_APPROVED
|
| - |
|
678 |
elif status == Store.ORDER_CANCELLED:
|
| - |
|
679 |
if subOrder.get("cashBackStatus") == Store.CB_PENDING:
|
| - |
|
680 |
updateMap["subOrders.$.cashBackStatus"] = Store.CB_CANCELLED
|
| - |
|
681 |
|
| 598 |
else:
|
682 |
else:
|
| 599 |
closeAt = datetime.strptime(closeAt,"%Y-%m-%d %H:%M:%S")
|
- |
|
| 600 |
if datetime.now() > closeAt:
|
- |
|
| 601 |
closedStatus = True
|
- |
|
| 602 |
#Close if not applicable suborders are not closed
|
- |
|
| 603 |
if utils.fromTimeStamp(order['createdOnInt'] + 35*86400*1000) < datetime.now() and subOrder['cashBackStatus']==utils.CB_NA:
|
- |
|
| 604 |
closedStatus=True
|
- |
|
| 605 |
|
- |
|
| 606 |
|
- |
|
| 607 |
if closedStatus:
|
- |
|
| 608 |
#if status is closed then change the paybackStatus accordingly
|
- |
|
| 609 |
updateMap["subOrders.$.closed"] = True
|
- |
|
| 610 |
if status == Store.ORDER_DELIVERED:
|
- |
|
| 611 |
if subOrder.get("cashBackStatus") == Store.CB_PENDING:
|
- |
|
| 612 |
updateMap["subOrders.$.cashBackStatus"] = Store.CB_APPROVED
|
- |
|
| 613 |
elif status == Store.ORDER_CANCELLED:
|
- |
|
| 614 |
if subOrder.get("cashBackStatus") == Store.CB_PENDING:
|
- |
|
| 615 |
updateMap["subOrders.$.cashBackStatus"] = Store.CB_CANCELLED
|
- |
|
| 616 |
|
- |
|
| 617 |
else:
|
- |
|
| 618 |
closed = False
|
683 |
closed = False
|
| 619 |
elif "Est. Shipping Date" in line:
|
684 |
elif "Est. Shipping Date" in line:
|
| 620 |
estimatedShippingDate = line.split(":")[1].strip()
|
685 |
estimatedShippingDate = line.split(":")[1].strip()
|
| 621 |
updateMap["subOrders.$.estimatedShippingDate"] = estimatedShippingDate
|
686 |
updateMap["subOrders.$.estimatedShippingDate"] = estimatedShippingDate
|
| 622 |
elif "Est. Delivery Date" in line:
|
687 |
elif "Est. Delivery Date" in line:
|
| 623 |
estimatedDeliveryDate = line.split(":")[1].strip()
|
688 |
estimatedDeliveryDate = line.split(":")[1].strip()
|
| 624 |
updateMap["subOrders.$.estimatedDeliveryDate"] = estimatedDeliveryDate
|
689 |
updateMap["subOrders.$.estimatedDeliveryDate"] = estimatedDeliveryDate
|
| 625 |
elif "Courier Name" in line:
|
690 |
elif "Courier Name" in line:
|
| 626 |
courierName = line.split(":")[1].strip()
|
691 |
courierName = line.split(":")[1].strip()
|
| 627 |
updateMap["subOrders.$.courierName"] = courierName
|
692 |
updateMap["subOrders.$.courierName"] = courierName
|
| 628 |
elif "Tracking No" in line:
|
693 |
elif "Tracking No" in line:
|
| 629 |
trackingNumber = line.split(":")[1].strip()
|
694 |
trackingNumber = line.split(":")[1].strip()
|
| 630 |
updateMap["subOrders.$.trackingNumber"] = trackingNumber
|
695 |
updateMap["subOrders.$.trackingNumber"] = trackingNumber
|
| 631 |
|
696 |
|
| 632 |
if breakFlag:
|
697 |
if breakFlag:
|
| 633 |
continue
|
698 |
continue
|
| 634 |
|
699 |
|
| 635 |
bulk.find(findMap).update({'$set' : updateMap})
|
700 |
bulk.find(findMap).update({'$set' : updateMap})
|
| 636 |
bulk.find({'orderId': order['orderId']}).update({'$set':{'closed': closed,"parseError":False}})
|
701 |
bulk.find({'orderId': order['orderId']}).update({'$set':{'closed': closed,"parseError":False}})
|
| 637 |
result = bulk.execute()
|
702 |
result = bulk.execute()
|
| 638 |
tprint(result)
|
703 |
tprint(result)
|
| 639 |
except:
|
704 |
except:
|
| 640 |
tprint("Could not update " + str(order['orderId']) + "For store " + self.getName())
|
- |
|
| 641 |
self.db.merchantOrder.update({"orderId":order['orderId']}, {"$set":{"parseError":True}})
|
- |
|
| 642 |
traceback.print_exc()
|
705 |
traceback.print_exc()
|
| - |
|
706 |
tprint("Could not update " + str(order.orderId) + "For store " + self.getName())
|
| - |
|
707 |
self.db.merchantOrder.update({"orderId":order.orderId}, {"$set":{"parseError":True}})
|
| 643 |
|
708 |
|
| 644 |
def tryBParsing(self, order, soup):
|
709 |
def tryBParsing(self, order, soup):
|
| 645 |
orderDetailContainerDivs = soup.body.find("div", {'class':'cardLayoutWrap'}).findAll('div', recursive=False)
|
710 |
orderDetailContainerDivs = soup.body.find("div", {'class':'cardLayoutWrap'}).findAll('div', recursive=False)
|
| 646 |
orderDetailDiv = orderDetailContainerDivs.pop(0)
|
711 |
orderDetailDiv = orderDetailContainerDivs.pop(0)
|
| 647 |
placedOn = orderDetailDiv.span.text.split(':')[1].strip()
|
712 |
placedOn = orderDetailDiv.span.text.split(':')[1].strip()
|
| Line 855... |
Line 920... |
| 855 |
|
920 |
|
| 856 |
|
921 |
|
| 857 |
def main():
|
922 |
def main():
|
| 858 |
#print todict([1,2,"3"])
|
923 |
#print todict([1,2,"3"])
|
| 859 |
store = getStore(3)
|
924 |
store = getStore(3)
|
| - |
|
925 |
#store.parseOrderRawHtml(332221, "3232311", 2, readSSh("/home/amit/snapdeal.html"), "https://m.snapdeal.com/purchaseMobileComplete?code=b92753bd7236bb3efbd6e8a0df46b962&order=9627657388")
|
| 860 |
#store.scrapeStoreOrders()
|
926 |
store.scrapeStoreOrders()
|
| 861 |
#https://m.snapdeal.com/purchaseMobileComplete?code=3fbc8a02a1c4d3c4e906f46886de0464&order=5808451506
|
927 |
#https://m.snapdeal.com/purchaseMobileComplete?code=3fbc8a02a1c4d3c4e906f46886de0464&order=5808451506
|
| 862 |
#https://m.snapdeal.com/purchaseMobileComplete?code=9f4dfa49ff08a16d04c5e4bf519506fc&order=9611672826
|
928 |
#https://m.snapdeal.com/purchaseMobileComplete?code=9f4dfa49ff08a16d04c5e4bf519506fc&order=9611672826
|
| 863 |
|
929 |
|
| 864 |
orders = session.query(OrdersRaw).filter_by(store_id=3).filter_by(status='ORDER_NOT_CREATED').all()
|
930 |
# orders = list(session.query(OrdersRaw).filter_by(store_id=3).filter_by(status='ORDER_NOT_CREATED').all())
|
| 865 |
for o in orders:
|
931 |
# for o in orders:
|
| 866 |
result = store.parseOrderRawHtml(o.id, o.sub_tag, o.user_id, o.rawhtml, o.order_url)['result']
|
932 |
# result = store.parseOrderRawHtml(o.id, o.sub_tag, o.user_id, o.rawhtml, o.order_url)['result']
|
| 867 |
o.status = result
|
933 |
# o.status = result
|
| 868 |
session.commit()
|
934 |
# session.commit()
|
| 869 |
#store.parseOrderRawHtml(332221, "3232311", 2, readSSh("/home/amit/snapdeal.html"), "https://m.snapdeal.com/purchaseMobileComplete?code=3fbc8a02a1c4d3c4e906f46886de0464&order=5808451506")
|
- |
|
| - |
|
935 |
# session.close()
|
| 870 |
#store.scrapeStoreOrders()
|
936 |
#store.scrapeStoreOrders()
|
| 871 |
#store._isSubOrderActive(8, "5970688907")
|
937 |
#store._isSubOrderActive(8, "5970688907")
|
| 872 |
#store.scrapeAffiliate(datetime(2015,4,1))
|
938 |
#store.scrapeAffiliate(datetime(2015,4,1))
|
| 873 |
#store.scrapeStoreOrders()
|
939 |
#store.scrapeStoreOrders()
|
| 874 |
#store.parseInfo()
|
940 |
#store.parseInfo()
|
| 875 |
|
941 |
|
| - |
|
942 |
class obj(object):
|
| - |
|
943 |
def __init__(self, d):
|
| - |
|
944 |
for a, b in d.items():
|
| - |
|
945 |
if isinstance(b, (list, tuple)):
|
| - |
|
946 |
setattr(self, a, [obj(x) if isinstance(x, dict) else x for x in b])
|
| - |
|
947 |
else:
|
| - |
|
948 |
setattr(self, a, obj(b) if isinstance(b, dict) else b)
|
| 876 |
|
949 |
|
| 877 |
|
950 |
|
| 878 |
def todict(obj, classkey=None):
|
951 |
def todict(obj, classkey=None):
|
| 879 |
if isinstance(obj, dict):
|
952 |
if isinstance(obj, dict):
|
| 880 |
data = {}
|
953 |
data = {}
|
| 881 |
for (k, v) in obj.items():
|
954 |
for (k, v) in obj.items():
|