| Line 50... |
Line 50... |
| 50 |
|
50 |
|
| 51 |
def scrapeStoreOrders(self,):
|
51 |
def scrapeStoreOrders(self,):
|
| 52 |
orders = self._getActiveOrders()
|
52 |
orders = self._getActiveOrders()
|
| 53 |
br = getBrowserObject()
|
53 |
br = getBrowserObject()
|
| 54 |
for order in orders:
|
54 |
for order in orders:
|
| 55 |
print order
|
55 |
print "Order", self.store_name, order['orderId']
|
| 56 |
try:
|
56 |
try:
|
| 57 |
closed = True
|
57 |
closed = True
|
| 58 |
url = ORDER_TRACK_URL + re.findall('.*(\?.*?)$', order['orderSuccessUrl'],re.IGNORECASE)[0]
|
58 |
url = ORDER_TRACK_URL + re.findall('.*(\?.*?)$', order['orderSuccessUrl'],re.IGNORECASE)[0]
|
| 59 |
response = br.open(url)
|
59 |
response = br.open(url)
|
| 60 |
page = ungzipResponse(response)
|
60 |
page = ungzipResponse(response)
|
| Line 78... |
Line 78... |
| 78 |
y = subOrder.find("header").findAll("span")
|
78 |
y = subOrder.find("header").findAll("span")
|
| 79 |
for suborderId in y:
|
79 |
for suborderId in y:
|
| 80 |
if "value emp" in str(suborderId):
|
80 |
if "value emp" in str(suborderId):
|
| 81 |
merchantSubOrderId = suborderId.text
|
81 |
merchantSubOrderId = suborderId.text
|
| 82 |
break
|
82 |
break
|
| - |
|
83 |
ul = subOrder.find("ul")
|
| - |
|
84 |
if ul is None:
|
| - |
|
85 |
ul = subOrder.findAll("div", recursive=False)[0].div.div
|
| 83 |
orderItems = subOrder.find("ul").findAll("div", recursive=False)
|
86 |
orderItems = ul.findAll("div", recursive=False)
|
| 84 |
i=0
|
87 |
i=0
|
| 85 |
for orderItem in orderItems:
|
88 |
for orderItem in orderItems:
|
| 86 |
closedStatus = False
|
89 |
closedStatus = False
|
| 87 |
merchantSubOrderId = merchantSubOrderId + str(i)
|
90 |
merchantSubOrderId = merchantSubOrderId + str(i)
|
| 88 |
subOrder = self._isSubOrderActive(order, merchantSubOrderId)
|
91 |
subOrder = self._isSubOrderActive(order, merchantSubOrderId)
|
| Line 116... |
Line 119... |
| 116 |
courierArr = trackingText.split(' : ')
|
119 |
courierArr = trackingText.split(' : ')
|
| 117 |
updateMap["subOrders.$.trackingUrl"] = trackingUrl
|
120 |
updateMap["subOrders.$.trackingUrl"] = trackingUrl
|
| 118 |
updateMap["subOrders.$.trackingNumber"] = courierArr[1]
|
121 |
updateMap["subOrders.$.trackingNumber"] = courierArr[1]
|
| 119 |
updateMap["subOrders.$.courierName"] = courierArr[0]
|
122 |
updateMap["subOrders.$.courierName"] = courierArr[0]
|
| 120 |
else:
|
123 |
else:
|
| 121 |
status = MStore.ORDER_PLACED
|
124 |
status = MStore.ORDER_CANCELLED
|
| - |
|
125 |
closedStatus = True
|
| - |
|
126 |
if cashbackStatus == Store.CB_PENDING:
|
| - |
|
127 |
cashbackStatus = Store.CB_CANCELLED
|
| 122 |
else:
|
128 |
else:
|
| 123 |
status = MStore.ORDER_PLACED
|
129 |
status = MStore.ORDER_PLACED
|
| 124 |
elif str(tr) in ["approveDetails-ongoing"]:
|
130 |
elif str(tr) in ["approveDetails-ongoing"]:
|
| 125 |
status=MStore.ORDER_PLACED
|
131 |
status=MStore.ORDER_PLACED
|
| 126 |
if "dead" in str(tr) or status==MStore.ORDER_CANCELLED:
|
132 |
if "dead" in str(tr) or status==MStore.ORDER_CANCELLED:
|
| Line 133... |
Line 139... |
| 133 |
updateMap["subOrders.$.status"] = status
|
139 |
updateMap["subOrders.$.status"] = status
|
| 134 |
updateMap["subOrders.$.closed"] = closedStatus
|
140 |
updateMap["subOrders.$.closed"] = closedStatus
|
| 135 |
if closed:
|
141 |
if closed:
|
| 136 |
closed = closedStatus
|
142 |
closed = closedStatus
|
| 137 |
bulk.find(findMap).update({'$set' : updateMap})
|
143 |
bulk.find(findMap).update({'$set' : updateMap})
|
| 138 |
bulk.find({'orderId': order['orderId']}).update({'$set':{'closed': closed}})
|
144 |
bulk.find({'orderId': order['orderId']}).update({'$set':{'closed': closed, 'parseError':False}})
|
| 139 |
bulk.execute()
|
145 |
bulk.execute()
|
| 140 |
except:
|
146 |
except:
|
| - |
|
147 |
self.db.merchantOrder.update({"orderId":order['orderId']}, {"$set":{"parseError":True}})
|
| 141 |
tprint("Could not update " + str(order['orderId']))
|
148 |
tprint("Could not update " + str(order['orderId']))
|
| 142 |
traceback.print_exc()
|
149 |
traceback.print_exc()
|
| 143 |
def scrapeAffiliate(self, startDate=None, endDate=None):
|
150 |
def scrapeAffiliate(self, startDate=None, endDate=None):
|
| 144 |
#get all yesterday's affiliate in pending or cancelled state and update to system
|
151 |
#get all yesterday's affiliate in pending or cancelled state and update to system
|
| 145 |
offers = []
|
152 |
offers = []
|
| Line 308... |
Line 315... |
| 308 |
status = MStore.ORDER_PLACED
|
315 |
status = MStore.ORDER_PLACED
|
| 309 |
else:
|
316 |
else:
|
| 310 |
status = MStore.ORDER_PLACED
|
317 |
status = MStore.ORDER_PLACED
|
| 311 |
elif str(tr) in ["approveDetails-ongoing"]:
|
318 |
elif str(tr) in ["approveDetails-ongoing"]:
|
| 312 |
status=MStore.ORDER_PLACED
|
319 |
status=MStore.ORDER_PLACED
|
| 313 |
if "dead" in str(tr) or "shippingDetails-returnOngoing" in str(tr):
|
320 |
if "dead" in str(tr) or "shippingDetails-returnOngoing" in str(tr) or "shippingDetails-return" in str(tr):
|
| 314 |
status = MStore.ORDER_CANCELLED
|
321 |
status = MStore.ORDER_CANCELLED
|
| 315 |
print "Sub Order Status " + str(status)
|
322 |
print "Sub Order Status " + str(status)
|
| 316 |
|
323 |
|
| 317 |
trackingDetailsActive = orderTrackingDet.find("div",{"class":"c-tabs-content m-top active"})
|
324 |
trackingDetailsActive = orderTrackingDet.find("div",{"class":"c-tabs-content m-top active"})
|
| 318 |
print "Sub order tracking description " + trackingDetailsActive.text
|
325 |
print "Sub order tracking description " + trackingDetailsActive.text
|
| Line 388... |
Line 395... |
| 388 |
print(m.digest())
|
395 |
print(m.digest())
|
| 389 |
|
396 |
|
| 390 |
def main():
|
397 |
def main():
|
| 391 |
|
398 |
|
| 392 |
store = getStore(2)
|
399 |
store = getStore(2)
|
| 393 |
store.scrapeAffiliate()
|
400 |
#store.scrapeAffiliate()
|
| 394 |
#store.scrapeStoreOrders(123469, "SHA21423034609", 122324, "html", 'https://m.flipkart.com/orderresponse?reference_id=OD0022423903274462&token=8c09a43ad48d1cd4f73be1f0c3c00d39&src=or&pr=1')
|
401 |
store.scrapeStoreOrders()
|
| 395 |
#store.parseOrderRawHtml(12346, "subtagId", 122324, "html", 'https://m.flipkart.com/orderresponse?reference_id=OD3016502908102575&token=0db4c692bacbfbfc158b52358ac9e91e&src=or&pr=1')
|
402 |
#store.parseOrderRawHtml(12346, "subtagId", 122324, "html", 'https://m.flipkart.com/orderresponse?reference_id=OD3016502908102575&token=0db4c692bacbfbfc158b52358ac9e91e&src=or&pr=1')
|
| 396 |
#store.parseOrderRawHtml(12346, "subtagId", 122324, "html", 'https://m.flipkart.com/orderresponse?reference_id=OD3018701137253850&token=f7402ddcf2b63b37cc6bc528cc115d2f&src=or&pr=1')
|
403 |
#store.parseOrderRawHtml(12346, "subtagId", 122324, "html", 'https://m.flipkart.com/orderresponse?reference_id=OD3018701137253850&token=f7402ddcf2b63b37cc6bc528cc115d2f&src=or&pr=1')
|
| 397 |
#store.parseOrderRawHtml(12346, "subtagId", 122324, "html", 'https://m.flipkart.com/orderresponse?reference_id=OD0019279584515727&token=7d85d8c24d36b5a1efc8008634390c7e&src=or&pr=1')
|
404 |
#store.parseOrderRawHtml(12346, "subtagId", 122324, "html", 'https://m.flipkart.com/orderresponse?reference_id=OD0019279584515727&token=7d85d8c24d36b5a1efc8008634390c7e&src=or&pr=1')
|
| 398 |
#store.flipkartOrderTracking(12346, "subtagId", 122324, "html", 'https://m.flipkart.com/orderresponse?reference_id=OD0019279584515727&token=7d85d8c24d36b5a1efc8008634390c7e&src=or&pr=1')
|
405 |
#store.flipkartOrderTracking(12346, "subtagId", 122324, "html", 'https://m.flipkart.com/orderresponse?reference_id=OD0019279584515727&token=7d85d8c24d36b5a1efc8008634390c7e&src=or&pr=1')
|
| 399 |
#store.parseOrderRawHtml(12346, "subtagId", 122324, "html", 'https://m.flipkart.com/orderresponse?reference_id=OD0019365336126533&token=dbce2bd4dc4023295b436a7d3c7986c9&src=or&pr=1')
|
406 |
#store.parseOrderRawHtml(12346, "subtagId", 122324, "html", 'https://m.flipkart.com/orderresponse?reference_id=OD0019365336126533&token=dbce2bd4dc4023295b436a7d3c7986c9&src=or&pr=1')
|