| Line 36... |
Line 36... |
| 36 |
This is to map order statuses of our system to order statuses of snapdeal.
|
36 |
This is to map order statuses of our system to order statuses of snapdeal.
|
| 37 |
And our statuses will change accordingly.
|
37 |
And our statuses will change accordingly.
|
| 38 |
|
38 |
|
| 39 |
'''
|
39 |
'''
|
| 40 |
OrderStatusMap = {
|
40 |
OrderStatusMap = {
|
| 41 |
MStore.ORDER_PLACED : ['in progress', 'pending for verification', 'not available', 'in process'],
|
41 |
MStore.ORDER_PLACED : ['in progress', 'pending for verification', 'not available', 'in process', 'processing', 'processed'],
|
| 42 |
MStore.ORDER_DELIVERED : ['delivered'],
|
42 |
MStore.ORDER_DELIVERED : ['delivered'],
|
| 43 |
MStore.ORDER_SHIPPED : ['in transit'],
|
43 |
MStore.ORDER_SHIPPED : ['in transit', 'dispatched'],
|
| 44 |
MStore.ORDER_CANCELLED : ['closed for vendor reallocation', 'cancelled', 'product returned by courier', 'returned', 'n/a']
|
44 |
MStore.ORDER_CANCELLED : ['closed for vendor reallocation', 'cancelled', 'product returned by courier', 'returned', 'n/a']
|
| 45 |
}
|
45 |
}
|
| 46 |
|
46 |
|
| 47 |
CONF_CB_AMOUNT = MStore.CONF_CB_DISCOUNTED_PRICE
|
47 |
CONF_CB_AMOUNT = MStore.CONF_CB_DISCOUNTED_PRICE
|
| 48 |
def __init__(self,store_id):
|
48 |
def __init__(self,store_id):
|
| Line 174... |
Line 174... |
| 174 |
unitPrice = int(re.findall(r'\d+', subTrString)[0])
|
174 |
unitPrice = int(re.findall(r'\d+', subTrString)[0])
|
| 175 |
if "Quantity" in subTrString:
|
175 |
if "Quantity" in subTrString:
|
| 176 |
qty = int(re.findall(r'\d+', subTrString)[0])
|
176 |
qty = int(re.findall(r'\d+', subTrString)[0])
|
| 177 |
elif "Offer Discount" in subTrString:
|
177 |
elif "Offer Discount" in subTrString:
|
| 178 |
offerDiscount += int(re.findall(r'\d+', subTrString)[0])
|
178 |
offerDiscount += int(re.findall(r'\d+', subTrString)[0])
|
| 179 |
elif "SD Cash:" in subTrString:
|
179 |
elif "SD Cash" in subTrString:
|
| 180 |
sdCash = int(re.findall(r'\d+', subTrString)[0])
|
180 |
sdCash = int(re.findall(r'\d+', subTrString)[0])
|
| 181 |
elif "Delivery Charges" in subTrString:
|
181 |
elif "Delivery Charges" in subTrString:
|
| 182 |
deliveryCharges = int(re.findall(r'\d+', subTrString)[0])
|
182 |
deliveryCharges = int(re.findall(r'\d+', subTrString)[0])
|
| 183 |
elif "Subtotal" in subTrString:
|
183 |
elif "Subtotal" in subTrString:
|
| 184 |
if int(qty) > 0:
|
184 |
if int(qty) > 0:
|
| Line 257... |
Line 257... |
| 257 |
strPaymentDiv = str(paymentDiv)
|
257 |
strPaymentDiv = str(paymentDiv)
|
| 258 |
if "Unit Price" in strPaymentDiv:
|
258 |
if "Unit Price" in strPaymentDiv:
|
| 259 |
unitPrice = int(re.findall(r'\d+', strPaymentDiv)[0])
|
259 |
unitPrice = int(re.findall(r'\d+', strPaymentDiv)[0])
|
| 260 |
if "Offer Discount" in strPaymentDiv:
|
260 |
if "Offer Discount" in strPaymentDiv:
|
| 261 |
offerDiscount = int(re.findall(r'\d+', strPaymentDiv)[0])
|
261 |
offerDiscount = int(re.findall(r'\d+', strPaymentDiv)[0])
|
| 262 |
elif "SD Cash:" in strPaymentDiv:
|
262 |
elif "SD Cash" in strPaymentDiv:
|
| 263 |
sdCash = int(re.findall(r'\d+', strPaymentDiv)[0])
|
263 |
sdCash = int(re.findall(r'\d+', strPaymentDiv)[0])
|
| 264 |
elif "Delivery Charges" in strPaymentDiv:
|
264 |
elif "Delivery Charges" in strPaymentDiv:
|
| 265 |
deliveryCharges = int(re.findall(r'\d+', strPaymentDiv)[0])
|
265 |
deliveryCharges = int(re.findall(r'\d+', strPaymentDiv)[0])
|
| 266 |
elif "Subtotal" in strPaymentDiv:
|
266 |
elif "Subtotal" in strPaymentDiv:
|
| 267 |
amountPaid = int(re.findall(r'\d+', paymentDiv.find('div', {'class':'itemPriceDetail'}).text)[0])
|
267 |
amountPaid = int(re.findall(r'\d+', paymentDiv.find('div', {'class':'itemPriceDetail'}).text)[0])
|
| Line 324... |
Line 324... |
| 324 |
page = br.open(url)
|
324 |
page = br.open(url)
|
| 325 |
page = ungzipResponse(page)
|
325 |
page = ungzipResponse(page)
|
| 326 |
try:
|
326 |
try:
|
| 327 |
merchantOrder = self._parseB(orderId, subTagId, userId, page, orderSuccessUrl)
|
327 |
merchantOrder = self._parseB(orderId, subTagId, userId, page, orderSuccessUrl)
|
| 328 |
except:
|
328 |
except:
|
| - |
|
329 |
traceback.print_exc()
|
| 329 |
merchantOrder = self._parse(orderId, subTagId, userId, page, orderSuccessUrl)
|
330 |
merchantOrder = self._parse(orderId, subTagId, userId, page, orderSuccessUrl)
|
| 330 |
|
331 |
|
| 331 |
merchantOrder.orderTrackingUrl = url
|
332 |
merchantOrder.orderTrackingUrl = url
|
| 332 |
|
333 |
|
| 333 |
if self._saveToOrder(todict(merchantOrder)):
|
334 |
if self._saveToOrder(todict(merchantOrder)):
|
| Line 349... |
Line 350... |
| 349 |
def _getStatusFromDetailedStatus(self, detailedStatus):
|
350 |
def _getStatusFromDetailedStatus(self, detailedStatus):
|
| 350 |
for key, value in Store.OrderStatusMap.iteritems():
|
351 |
for key, value in Store.OrderStatusMap.iteritems():
|
| 351 |
if detailedStatus.lower() in value:
|
352 |
if detailedStatus.lower() in value:
|
| 352 |
return key
|
353 |
return key
|
| 353 |
print "Detailed Status need to be mapped", detailedStatus, self.store_id
|
354 |
print "Detailed Status need to be mapped", detailedStatus, self.store_id
|
| 354 |
raise ParseException("_getStatusFromDetailedStatus", "Found new order status" + detailedStatus)
|
355 |
return None
|
| 355 |
|
356 |
|
| 356 |
|
357 |
|
| 357 |
def scrapeStoreOrders(self,):
|
358 |
def scrapeStoreOrders(self,):
|
| 358 |
#collectionMap = {'palcedOn':1}
|
359 |
#collectionMap = {'palcedOn':1}
|
| 359 |
orders = self._getActiveOrders()
|
360 |
orders = self._getActiveOrders()
|
| Line 361... |
Line 362... |
| 361 |
print "Order", self.store_name, order['orderId']
|
362 |
print "Order", self.store_name, order['orderId']
|
| 362 |
try:
|
363 |
try:
|
| 363 |
url = ORDER_TRACK_URL + re.findall('.*(\?.*?)$', order['orderSuccessUrl'],re.IGNORECASE)[0]
|
364 |
url = ORDER_TRACK_URL + re.findall('.*(\?.*?)$', order['orderSuccessUrl'],re.IGNORECASE)[0]
|
| 364 |
page = fetchResponseUsingProxy(url)
|
365 |
page = fetchResponseUsingProxy(url)
|
| 365 |
#page=page.decode("utf-8")
|
366 |
#page=page.decode("utf-8")
|
| 366 |
soup = BeautifulSoup(page,convertEntities=BeautifulSoup.HTML_ENTITIES)
|
367 |
soup = BeautifulSoup(page)
|
| - |
|
368 |
try:
|
| - |
|
369 |
self.tryBParsing(order, soup)
|
| - |
|
370 |
except:
|
| - |
|
371 |
traceback.print_exc()
|
| 367 |
sections = soup.findAll("section")
|
372 |
sections = soup.findAll("section")
|
| 368 |
orderEl = sections[1]
|
373 |
orderEl = sections[1]
|
| 369 |
orderTrs = orderEl.findAll("tr")
|
374 |
orderTrs = orderEl.findAll("tr")
|
| 370 |
|
375 |
|
| 371 |
placedOn = str(orderTrs[0].findAll("td")[1].text)
|
376 |
placedOn = str(orderTrs[0].findAll("td")[1].text)
|
| 372 |
sections.pop(0)
|
377 |
sections.pop(0)
|
| 373 |
sections.pop(0)
|
378 |
sections.pop(0)
|
| 374 |
|
379 |
|
| 375 |
subOrders = sections
|
380 |
subOrders = sections
|
| 376 |
bulk = self.db.merchantOrder.initialize_ordered_bulk_op()
|
381 |
bulk = self.db.merchantOrder.initialize_ordered_bulk_op()
|
| 377 |
closed = True
|
382 |
closed = True
|
| 378 |
for subOrderElement in subOrders:
|
383 |
for subOrderElement in subOrders:
|
| 379 |
div1 = subOrderElement.findAll("div", {"class": "blk lrPad subordrs"})
|
384 |
div1 = subOrderElement.findAll("div", {"class": "blk lrPad subordrs"})
|
| 380 |
if len(div1)<=0:
|
385 |
if len(div1)<=0:
|
| 381 |
raise ParseException("subOrder", "Could not Parse suborders for Snapdeal")
|
386 |
raise ParseException("subOrder", "Could not Parse suborders for Snapdeal")
|
| 382 |
subOrder = None
|
387 |
subOrder = None
|
| 383 |
breakFlag = False
|
388 |
breakFlag = False
|
| 384 |
for strDiv in str(div1).split("<div class=\"seperator\"></div>"):
|
389 |
for strDiv in str(div1).split("<div class=\"seperator\"></div>"):
|
| 385 |
div = BeautifulSoup(strDiv)
|
390 |
div = BeautifulSoup(strDiv)
|
| 386 |
divStr = str(div)
|
391 |
divStr = str(div)
|
| 387 |
divStr = divStr.replace("\n","").replace("\t", "")
|
392 |
divStr = divStr.replace("\n","").replace("\t", "")
|
| 388 |
updateMap = {}
|
393 |
updateMap = {}
|
| 389 |
for line in divStr.split("<br />"):
|
394 |
for line in divStr.split("<br />"):
|
| 390 |
if "Suborder ID" in line:
|
395 |
if "Suborder ID" in line:
|
| 391 |
merchantSubOrderId = re.findall(r'\d+', line)[0]
|
396 |
merchantSubOrderId = re.findall(r'\d+', line)[0]
|
| 392 |
#break if suborder is inactive
|
397 |
#break if suborder is inactive
|
| 393 |
subOrder = self._isSubOrderActive(order, merchantSubOrderId)
|
398 |
subOrder = self._isSubOrderActive(order, merchantSubOrderId)
|
| 394 |
if subOrder is None:
|
399 |
if subOrder is None:
|
| 395 |
subOrders = self.parseSubOrder(subOrderElement, placedOn)
|
400 |
subOrders = self.parseSubOrder(subOrderElement, placedOn)
|
| 396 |
self.db.merchantOrder.update({"orderId":order['orderId']},{'$push':{"subOrders":{"$each":todict(subOrders)}}})
|
401 |
self.db.merchantOrder.update({"orderId":order['orderId']},{'$push':{"subOrders":{"$each":todict(subOrders)}}})
|
| 397 |
print "Added new suborders to Order id - " + order['orderId']
|
402 |
print "Added new suborders to Order id - ", order['orderId']
|
| 398 |
closed = False
|
403 |
closed = False
|
| 399 |
breakFlag = True
|
404 |
breakFlag = True
|
| 400 |
break
|
405 |
break
|
| 401 |
elif subOrder['closed']:
|
406 |
elif subOrder['closed']:
|
| 402 |
breakFlag = True
|
407 |
breakFlag = True
|
| 403 |
break
|
408 |
break
|
| 404 |
else:
|
409 |
else:
|
| 405 |
findMap = {"orderId": order['orderId'], "subOrders.merchantSubOrderId": merchantSubOrderId}
|
410 |
findMap = {"orderId": order['orderId'], "subOrders.merchantSubOrderId": merchantSubOrderId}
|
| 406 |
elif "Status :" in line:
|
411 |
elif "Status :" in line:
|
| 407 |
detailedStatus = re.findall('>(.*?)</span>', line, re.IGNORECASE)[0]
|
412 |
detailedStatus = re.findall('>(.*?)</span>', line, re.IGNORECASE)[0]
|
| 408 |
updateMap["subOrders.$.detailedStatus"] = detailedStatus
|
413 |
updateMap["subOrders.$.detailedStatus"] = detailedStatus
|
| 409 |
status = self._getStatusFromDetailedStatus(detailedStatus)
|
414 |
status = self._getStatusFromDetailedStatus(detailedStatus)
|
| 410 |
closedStatus = status in [Store.ORDER_DELIVERED, Store.ORDER_CANCELLED]
|
415 |
closedStatus = status in [Store.ORDER_DELIVERED, Store.ORDER_CANCELLED]
|
| - |
|
416 |
if status is not None:
|
| 411 |
updateMap["subOrders.$.status"] = status
|
417 |
updateMap["subOrders.$.status"] = status
|
| 412 |
if detailedStatus == 'Closed For Vendor Reallocation':
|
418 |
if detailedStatus == 'Closed For Vendor Reallocation':
|
| 413 |
#if it is more than 6hours mark closed.
|
419 |
#if it is more than 6hours mark closed.
|
| 414 |
closeAt = subOrder.get("closeAt")
|
420 |
closeAt = subOrder.get("closeAt")
|
| 415 |
if closeAt is None:
|
421 |
if closeAt is None:
|
| 416 |
closeAt = datetime.now() + timedelta(hours=6)
|
422 |
closeAt = datetime.now() + timedelta(hours=6)
|
| 417 |
updateMap["subOrders.$.closeAt"] = datetime.strftime(closeAt,"%Y-%m-%d %H:%M:%S")
|
423 |
updateMap["subOrders.$.closeAt"] = datetime.strftime(closeAt,"%Y-%m-%d %H:%M:%S")
|
| - |
|
424 |
else:
|
| - |
|
425 |
closeAt = datetime.strptime(closeAt,"%Y-%m-%d %H:%M:%S")
|
| - |
|
426 |
if datetime.now() > closeAt:
|
| - |
|
427 |
closedStatus = True
|
| - |
|
428 |
|
| - |
|
429 |
|
| - |
|
430 |
if closedStatus:
|
| - |
|
431 |
#if status is closed then change the paybackStatus accordingly
|
| - |
|
432 |
updateMap["subOrders.$.closed"] = True
|
| - |
|
433 |
if status == Store.ORDER_DELIVERED:
|
| - |
|
434 |
if subOrder.get("cashBackStatus") == Store.CB_PENDING:
|
| - |
|
435 |
updateMap["subOrders.$.cashBackStatus"] = Store.CB_APPROVED
|
| - |
|
436 |
elif status == Store.ORDER_CANCELLED:
|
| - |
|
437 |
if subOrder.get("cashBackStatus") == Store.CB_PENDING:
|
| - |
|
438 |
updateMap["subOrders.$.cashBackStatus"] = Store.CB_CANCELLED
|
| - |
|
439 |
|
| 418 |
else:
|
440 |
else:
|
| 419 |
closeAt = datetime.strptime(closeAt,"%Y-%m-%d %H:%M:%S")
|
- |
|
| 420 |
if datetime.now() > closeAt:
|
- |
|
| 421 |
closedStatus = True
|
- |
|
| 422 |
|
- |
|
| 423 |
|
- |
|
| 424 |
if closedStatus:
|
- |
|
| 425 |
#if status is closed then change the paybackStatus accordingly
|
- |
|
| 426 |
updateMap["subOrders.$.closed"] = True
|
- |
|
| 427 |
if status == Store.ORDER_DELIVERED:
|
- |
|
| 428 |
if subOrder.get("cashBackStatus") == Store.CB_PENDING:
|
- |
|
| 429 |
updateMap["subOrders.$.cashBackStatus"] = Store.CB_APPROVED
|
- |
|
| 430 |
elif status == Store.ORDER_CANCELLED:
|
- |
|
| 431 |
if subOrder.get("cashBackStatus") == Store.CB_PENDING:
|
- |
|
| 432 |
updateMap["subOrders.$.cashBackStatus"] = Store.CB_CANCELLED
|
- |
|
| 433 |
|
- |
|
| 434 |
else:
|
- |
|
| 435 |
closed = False
|
441 |
closed = False
|
| 436 |
elif "Est. Shipping Date" in line:
|
442 |
elif "Est. Shipping Date" in line:
|
| 437 |
estimatedShippingDate = line.split(":")[1].strip()
|
443 |
estimatedShippingDate = line.split(":")[1].strip()
|
| 438 |
updateMap["subOrders.$.estimatedShippingDate"] = estimatedShippingDate
|
444 |
updateMap["subOrders.$.estimatedShippingDate"] = estimatedShippingDate
|
| 439 |
elif "Est. Delivery Date" in line:
|
445 |
elif "Est. Delivery Date" in line:
|
| 440 |
estimatedDeliveryDate = line.split(":")[1].strip()
|
446 |
estimatedDeliveryDate = line.split(":")[1].strip()
|
| 441 |
updateMap["subOrders.$.estimatedDeliveryDate"] = estimatedDeliveryDate
|
447 |
updateMap["subOrders.$.estimatedDeliveryDate"] = estimatedDeliveryDate
|
| 442 |
elif "Courier Name" in line:
|
448 |
elif "Courier Name" in line:
|
| 443 |
courierName = line.split(":")[1].strip()
|
449 |
courierName = line.split(":")[1].strip()
|
| 444 |
updateMap["subOrders.$.courierName"] = courierName
|
450 |
updateMap["subOrders.$.courierName"] = courierName
|
| 445 |
elif "Tracking No" in line:
|
451 |
elif "Tracking No" in line:
|
| 446 |
trackingNumber = line.split(":")[1].strip()
|
452 |
trackingNumber = line.split(":")[1].strip()
|
| 447 |
updateMap["subOrders.$.trackingNumber"] = trackingNumber
|
453 |
updateMap["subOrders.$.trackingNumber"] = trackingNumber
|
| 448 |
|
454 |
|
| 449 |
if breakFlag:
|
455 |
if breakFlag:
|
| 450 |
continue
|
456 |
continue
|
| 451 |
|
457 |
|
| 452 |
bulk.find(findMap).update({'$set' : updateMap})
|
458 |
bulk.find(findMap).update({'$set' : updateMap})
|
| 453 |
bulk.find({'orderId': order['orderId']}).update({'$set':{'closed': closed,"parseError":False}})
|
459 |
bulk.find({'orderId': order['orderId']}).update({'$set':{'closed': closed,"parseError":False}})
|
| 454 |
result = bulk.execute()
|
460 |
result = bulk.execute()
|
| 455 |
tprint(result)
|
461 |
tprint(result)
|
| 456 |
except:
|
462 |
except:
|
| 457 |
tprint("Could not update " + str(order['orderId']) + "For store " + self.getName())
|
463 |
tprint("Could not update " + str(order['orderId']) + "For store " + self.getName())
|
| 458 |
self.db.merchantOrder.update({"orderId":order['orderId']}, {"$set":{"parseError":True}})
|
464 |
self.db.merchantOrder.update({"orderId":order['orderId']}, {"$set":{"parseError":True}})
|
| 459 |
traceback.print_exc()
|
465 |
traceback.print_exc()
|
| 460 |
|
466 |
|
| Line 475... |
Line 481... |
| 475 |
imgDiv = prodDetailDiv[0]
|
481 |
imgDiv = prodDetailDiv[0]
|
| 476 |
otherDiv = prodDetailDiv[1]
|
482 |
otherDiv = prodDetailDiv[1]
|
| 477 |
|
483 |
|
| 478 |
subOrder = None
|
484 |
subOrder = None
|
| 479 |
breakFlag = False
|
485 |
breakFlag = False
|
| 480 |
|
- |
|
| 481 |
div = None
|
- |
|
| 482 |
divStr = str(div)
|
- |
|
| 483 |
divStr = divStr.replace("\n","").replace("\t", "")
|
- |
|
| 484 |
updateMap = {}
|
- |
|
| 485 |
for line in divStr.split("<br />"):
|
- |
|
| 486 |
if "Suborder ID" in line:
|
- |
|
| 487 |
merchantSubOrderId = re.findall(r'\d+', line)[0]
|
- |
|
| 488 |
#break if suborder is inactive
|
- |
|
| 489 |
subOrder = self._isSubOrderActive(order, merchantSubOrderId)
|
486 |
subOrder = self._isSubOrderActive(order, merchantSubOrderId)
|
| 490 |
if subOrder is None:
|
487 |
if subOrder is None:
|
| 491 |
subOrders = self.parseSubOrder(subOrderElement, placedOn)
|
488 |
subOrders = self.parseSubOrderB(subOrderElement, placedOn)
|
| 492 |
self.db.merchantOrder.update({"orderId":order['orderId']},{'$push':{"subOrders":{"$each":todict(subOrders)}}})
|
489 |
self.db.merchantOrder.update({"orderId":order['orderId']},{'$push':{"subOrders":{"$each":todict([subOrders])}}})
|
| 493 |
print "Added new suborders to Order id - " + order['orderId']
|
490 |
print "Added new suborders to Order id - ", order['orderId']
|
| 494 |
closed = False
|
491 |
closed = False
|
| 495 |
breakFlag = True
|
- |
|
| 496 |
break
|
492 |
continue
|
| 497 |
elif subOrder['closed']:
|
493 |
elif subOrder['closed']:
|
| 498 |
breakFlag = True
|
- |
|
| 499 |
break
|
494 |
continue
|
| 500 |
else:
|
495 |
else:
|
| 501 |
findMap = {"orderId": order['orderId'], "subOrders.merchantSubOrderId": merchantSubOrderId}
|
496 |
findMap = {"orderId": order['orderId'], "subOrders.merchantSubOrderId": merchantSubOrderId}
|
| 502 |
elif "Status :" in line:
|
497 |
updateMap = {}
|
| - |
|
498 |
prodDivs = subOrderElement.findAll('div', recursive=False)
|
| - |
|
499 |
prodDetailDiv = prodDivs[1].findAll('div', recursive=False)
|
| - |
|
500 |
otherDiv = prodDetailDiv[1]
|
| 503 |
detailedStatus = re.findall('>(.*?)</span>', line, re.IGNORECASE)[0]
|
501 |
detailedStatus = otherDiv.find('div',{'class':'orderStatus'}).span.text.strip()
|
| 504 |
updateMap["subOrders.$.detailedStatus"] = detailedStatus
|
502 |
updateMap["subOrders.$.detailedStatus"] = detailedStatus
|
| 505 |
status = self._getStatusFromDetailedStatus(detailedStatus)
|
503 |
status = self._getStatusFromDetailedStatus(detailedStatus)
|
| 506 |
closedStatus = status in [Store.ORDER_DELIVERED, Store.ORDER_CANCELLED]
|
504 |
closedStatus = status in [Store.ORDER_DELIVERED, Store.ORDER_CANCELLED]
|
| - |
|
505 |
if status is not None:
|
| 507 |
updateMap["subOrders.$.status"] = status
|
506 |
updateMap["subOrders.$.status"] = status
|
| 508 |
if detailedStatus == 'Closed For Vendor Reallocation':
|
507 |
if detailedStatus == 'Closed For Vendor Reallocation':
|
| 509 |
#if it is more than 6hours mark closed.
|
508 |
#if it is more than 6hours mark closed.
|
| 510 |
closeAt = subOrder.get("closeAt")
|
509 |
closeAt = subOrder.get("closeAt")
|
| 511 |
if closeAt is None:
|
510 |
if closeAt is None:
|
| 512 |
closeAt = datetime.now() + timedelta(hours=6)
|
511 |
closeAt = datetime.now() + timedelta(hours=6)
|
| 513 |
updateMap["subOrders.$.closeAt"] = datetime.strftime(closeAt,"%Y-%m-%d %H:%M:%S")
|
512 |
updateMap["subOrders.$.closeAt"] = datetime.strftime(closeAt,"%Y-%m-%d %H:%M:%S")
|
| 514 |
else:
|
- |
|
| 515 |
closeAt = datetime.strptime(closeAt,"%Y-%m-%d %H:%M:%S")
|
- |
|
| 516 |
if datetime.now() > closeAt:
|
- |
|
| 517 |
closedStatus = True
|
- |
|
| 518 |
|
- |
|
| 519 |
|
- |
|
| 520 |
if closedStatus:
|
- |
|
| 521 |
#if status is closed then change the paybackStatus accordingly
|
- |
|
| 522 |
updateMap["subOrders.$.closed"] = True
|
- |
|
| 523 |
if status == Store.ORDER_DELIVERED:
|
- |
|
| 524 |
if subOrder.get("cashBackStatus") == Store.CB_PENDING:
|
- |
|
| 525 |
updateMap["subOrders.$.cashBackStatus"] = Store.CB_APPROVED
|
- |
|
| 526 |
elif status == Store.ORDER_CANCELLED:
|
- |
|
| 527 |
if subOrder.get("cashBackStatus") == Store.CB_PENDING:
|
- |
|
| 528 |
updateMap["subOrders.$.cashBackStatus"] = Store.CB_CANCELLED
|
- |
|
| 529 |
|
- |
|
| 530 |
else:
|
513 |
else:
|
| - |
|
514 |
closeAt = datetime.strptime(closeAt,"%Y-%m-%d %H:%M:%S")
|
| 531 |
closed = False
|
515 |
if datetime.now() > closeAt:
|
| 532 |
elif "Est. Shipping Date" in line:
|
516 |
closedStatus = True
|
| 533 |
estimatedShippingDate = line.split(":")[1].strip()
|
517 |
|
| 534 |
updateMap["subOrders.$.estimatedShippingDate"] = estimatedShippingDate
|
518 |
|
| 535 |
elif "Est. Delivery Date" in line:
|
519 |
if closedStatus:
|
| 536 |
estimatedDeliveryDate = line.split(":")[1].strip()
|
520 |
#if status is closed then change the paybackStatus accordingly
|
| 537 |
updateMap["subOrders.$.estimatedDeliveryDate"] = estimatedDeliveryDate
|
521 |
updateMap["subOrders.$.closed"] = True
|
| 538 |
elif "Courier Name" in line:
|
522 |
if status == Store.ORDER_DELIVERED:
|
| 539 |
courierName = line.split(":")[1].strip()
|
523 |
if subOrder.get("cashBackStatus") == Store.CB_PENDING:
|
| 540 |
updateMap["subOrders.$.courierName"] = courierName
|
524 |
updateMap["subOrders.$.cashBackStatus"] = Store.CB_APPROVED
|
| 541 |
elif "Tracking No" in line:
|
525 |
elif status == Store.ORDER_CANCELLED:
|
| 542 |
trackingNumber = line.split(":")[1].strip()
|
526 |
if subOrder.get("cashBackStatus") == Store.CB_PENDING:
|
| 543 |
updateMap["subOrders.$.trackingNumber"] = trackingNumber
|
527 |
updateMap["subOrders.$.cashBackStatus"] = Store.CB_CANCELLED
|
| 544 |
|
- |
|
| 545 |
if breakFlag:
|
528 |
|
| 546 |
continue
|
529 |
else:
|
| - |
|
530 |
closed = False
|
| 547 |
|
531 |
|
| - |
|
532 |
deliveryStatus = otherDiv.find('div',{'class':'orderDelivery'})
|
| - |
|
533 |
if deliveryStatus is not None:
|
| - |
|
534 |
delString = deliveryStatus.text.strip()
|
| - |
|
535 |
arr = delString.split(':')
|
| - |
|
536 |
if "On" in arr[0]:
|
| - |
|
537 |
updateMap['subOrders.$.deliveredOn'] = arr[1].strip()
|
| - |
|
538 |
elif "Exp. Delivery by" in arr[0]:
|
| - |
|
539 |
updateMap['subOrders.$.estimatedDeliveryDate'] = arr[1].strip()
|
| - |
|
540 |
else:
|
| - |
|
541 |
updateMap['subOrders.$.estimatedShippingDate'] = arr[1].strip()
|
| - |
|
542 |
courierDet = subOrderElement.find('div', {'class':'courierDetail'})
|
| - |
|
543 |
if courierDet is not None:
|
| - |
|
544 |
updateMap['subOrders.$.courierName'] = courierDet.span.text.strip()
|
| - |
|
545 |
trackingDet = subOrderElement.find('div', {'class':'trackingNo'})
|
| - |
|
546 |
if trackingDet is not None:
|
| - |
|
547 |
updateMap['subOrders.$.trackingUrl'] = trackingDet.span.a['href']
|
| - |
|
548 |
updateMap['subOrders.$.trackingNumber'] = trackingDet.span.a.text.strip()
|
| 548 |
bulk.find(findMap).update({'$set' : updateMap})
|
549 |
bulk.find(findMap).update({'$set' : updateMap})
|
| 549 |
bulk.find({'orderId': order['orderId']}).update({'$set':{'closed': closed,"parseError":False}})
|
550 |
bulk.find({'orderId': order['orderId']}).update({'$set':{'closed': closed,"parseError":False}})
|
| 550 |
result = bulk.execute()
|
551 |
result = bulk.execute()
|
| 551 |
tprint(result)
|
552 |
tprint(result)
|
| 552 |
|
553 |
|
| Line 614... |
Line 615... |
| 614 |
return urllib.urlencode(parameters)
|
615 |
return urllib.urlencode(parameters)
|
| 615 |
|
616 |
|
| 616 |
def main():
|
617 |
def main():
|
| 617 |
#print todict([1,2,"3"])
|
618 |
#print todict([1,2,"3"])
|
| 618 |
store = getStore(3)
|
619 |
store = getStore(3)
|
| 619 |
store.parseOrderRawHtml(33222, "32323", 2, "323243", "https://m.snapdeal.com/purchaseMobileComplete?code=561009a4a0c043e2f537f558c8531580&order=5822820967")
|
620 |
#store.parseOrderRawHtml(33222, "32323", 2, "323243", "https://m.snapdeal.com/purchaseMobileComplete?code=1131a4add85aefb40a924d71cbf921bd&order=5822561503")
|
| 620 |
#store.scrapeStoreOrders()
|
621 |
store.scrapeStoreOrders()
|
| 621 |
#store._isSubOrderActive(8, "5970688907")
|
622 |
#store._isSubOrderActive(8, "5970688907")
|
| 622 |
#store.scrapeAffiliate()
|
623 |
#store.scrapeAffiliate()
|
| 623 |
#store.scrapeStoreOrders()
|
624 |
#store.scrapeStoreOrders()
|
| 624 |
|
625 |
|
| 625 |
|
626 |
|