| Line 42... |
Line 42... |
| 42 |
super(Store, self).__init__(store_id)
|
42 |
super(Store, self).__init__(store_id)
|
| 43 |
|
43 |
|
| 44 |
def getName(self):
|
44 |
def getName(self):
|
| 45 |
return "amazon"
|
45 |
return "amazon"
|
| 46 |
|
46 |
|
| 47 |
def parseOrderRawHtml(self, orderId, subTagId, userId, rawHtml, orderSuccessUrl, insert=False):
|
47 |
def parseOrderRawHtml(self, orderId, subTagId, userId, rawHtml, orderSuccessUrl, track=False):
|
| 48 |
resp = {}
|
48 |
resp = {}
|
| 49 |
resp['result'] = 'ORDER_NOT_CREATED'
|
49 |
resp['result'] = 'ORDER_NOT_CREATED'
|
| 50 |
if ORDER_SUCCESS_URL in orderSuccessUrl or THANKYOU_URL in orderSuccessUrl:
|
50 |
if ORDER_SUCCESS_URL in orderSuccessUrl or THANKYOU_URL in orderSuccessUrl:
|
| 51 |
try:
|
51 |
try:
|
| 52 |
soup = BeautifulSoup(rawHtml)
|
52 |
soup = BeautifulSoup(rawHtml)
|
| Line 93... |
Line 93... |
| 93 |
if mo is not None:
|
93 |
if mo is not None:
|
| 94 |
merchantOrder = Order(orderId, userId, subTagId, self.store_id, orderSuccessUrl, False)
|
94 |
merchantOrder = Order(orderId, userId, subTagId, self.store_id, orderSuccessUrl, False)
|
| 95 |
merchantOrder.createdOn = mo.get("createdOn")
|
95 |
merchantOrder.createdOn = mo.get("createdOn")
|
| 96 |
merchantOrder.createdOnInt = mo.get("createdOnInt")
|
96 |
merchantOrder.createdOnInt = mo.get("createdOnInt")
|
| 97 |
else:
|
97 |
else:
|
| - |
|
98 |
print "Could not find amazon order with order Id", orderId
|
| 98 |
merchantOrder = Order(orderId, userId, subTagId, self.store_id, orderSuccessUrl)
|
99 |
merchantOrder = Order(orderId, userId, subTagId, self.store_id, orderSuccessUrl)
|
| 99 |
soup = BeautifulSoup(rawHtml)
|
100 |
soup = BeautifulSoup(rawHtml)
|
| 100 |
try:
|
101 |
try:
|
| 101 |
self.parseOldStlye(merchantOrder, soup)
|
102 |
self.parseOldStlye(merchantOrder, soup)
|
| 102 |
except:
|
103 |
except:
|
| Line 363... |
Line 364... |
| 363 |
|
364 |
|
| 364 |
def trackOrdersForUser(self, userId, url, rawHtml):
|
365 |
def trackOrdersForUser(self, userId, url, rawHtml):
|
| 365 |
directory = "/tmp/User" + str(userId)
|
366 |
directory = "/tmp/User" + str(userId)
|
| 366 |
if not os.path.exists(directory):
|
367 |
if not os.path.exists(directory):
|
| 367 |
os.makedirs(directory)
|
368 |
os.makedirs(directory)
|
| 368 |
filename = directory + "/" + str(datetime.now())
|
- |
|
| 369 |
print "filename---", filename
|
- |
|
| 370 |
f = open(filename,'w')
|
369 |
|
| 371 |
f.write(rawHtml) # python will convert \n to os.linesep
|
- |
|
| 372 |
f.close() # you can omit in most cases as the destructor will call if
|
- |
|
| 373 |
|
370 |
|
| 374 |
try:
|
371 |
try:
|
| 375 |
searchMap = {'userId':userId}
|
372 |
searchMap = {'userId':userId}
|
| 376 |
collectionMap = {'merchantOrderId':1}
|
373 |
collectionMap = {'merchantOrderId':1}
|
| 377 |
activeOrders = self._getActiveOrders(searchMap, collectionMap)
|
374 |
activeOrders = self._getActiveOrders(searchMap, collectionMap)
|
| 378 |
datetimeNow = datetime.now()
|
375 |
datetimeNow = datetime.now()
|
| 379 |
timestamp = int(time.mktime(datetimeNow.timetuple()))
|
376 |
timestamp = int(time.mktime(datetimeNow.timetuple()))
|
| 380 |
print "url----------------", url
|
377 |
print "url----------------", url
|
| 381 |
|
378 |
|
| 382 |
if url == 'https://www.amazon.in/gp/css/order-history' or 'https://www.amazon.in/gp/css/order-history/?orderFilter=cancelled' in url:
|
379 |
if url == 'https://www.amazon.in/gp/css/order-history' or 'https://www.amazon.in/gp/css/order-history/?orderFilter=cancelled' in url:
|
| - |
|
380 |
if url == 'https://www.amazon.in/gp/css/order-history':
|
| - |
|
381 |
filename = directory + "/orderSummary" + datetime.strftime(datetime.now(), '%d-%m:%H:%M:%S')
|
| - |
|
382 |
else:
|
| - |
|
383 |
filename = directory + "/cancelledSummary" + datetime.strftime(datetime.now(), '%d-%m:%H:%M:%S')
|
| - |
|
384 |
f = open(filename,'w')
|
| - |
|
385 |
f.write(rawHtml) # python will convert \n to os.linesep
|
| - |
|
386 |
f.close() # you can omit in most cases as the destructor will call if
|
| 383 |
soup = BeautifulSoup(rawHtml)
|
387 |
soup = BeautifulSoup(rawHtml)
|
| 384 |
allOrders = soup.find(id="ordersContainer").findAll('div', {'class':'a-box-group a-spacing-base order'})
|
388 |
allOrders = soup.find(id="ordersContainer").findAll('div', {'class':'a-box-group a-spacing-base order'})
|
| 385 |
bulk = self.db.merchantOrder.initialize_ordered_bulk_op()
|
389 |
bulk = self.db.merchantOrder.initialize_ordered_bulk_op()
|
| 386 |
for activeOrder in activeOrders:
|
390 |
for activeOrder in activeOrders:
|
| 387 |
for orderEle in allOrders:
|
391 |
for orderEle in allOrders:
|
| Line 449... |
Line 453... |
| 449 |
bulk.execute()
|
453 |
bulk.execute()
|
| 450 |
return 'PARSED_SUCCESS'
|
454 |
return 'PARSED_SUCCESS'
|
| 451 |
else:
|
455 |
else:
|
| 452 |
merchantOrderId = re.findall(r'https://www.amazon.in/gp/css/summary/edit.html\?orderID=(.*)?', url, re.IGNORECASE)[0]
|
456 |
merchantOrderId = re.findall(r'https://www.amazon.in/gp/css/summary/edit.html\?orderID=(.*)?', url, re.IGNORECASE)[0]
|
| 453 |
merchantOrder = self.db.merchantOrder.find_one({"merchantOrderId":merchantOrderId})
|
457 |
merchantOrder = self.db.merchantOrder.find_one({"merchantOrderId":merchantOrderId})
|
| - |
|
458 |
|
| - |
|
459 |
filename = directory + "/" + merchantOrderId
|
| - |
|
460 |
f = open(filename,'w')
|
| - |
|
461 |
f.write(rawHtml) # python will convert \n to os.linesep
|
| - |
|
462 |
f.close() # you can omit in most cases as the destructor will call if
|
| 454 |
self.parseOrderRawHtml(merchantOrder['orderId'], merchantOrder['subTagId'], merchantOrder['userId'], rawHtml, url, False)['result']
|
463 |
self.parseOrderRawHtml(merchantOrder['orderId'], merchantOrder['subTagId'], merchantOrder['userId'], rawHtml, url, True)['result']
|
| 455 |
return 'PARSED_SUCCESS'
|
464 |
return 'PARSED_SUCCESS'
|
| 456 |
pass
|
465 |
pass
|
| 457 |
return 'PARSED_SUCCESS_NO_ORDERS'
|
466 |
return 'PARSED_SUCCESS_NO_ORDERS'
|
| 458 |
except:
|
467 |
except:
|
| 459 |
traceback.print_exc()
|
468 |
traceback.print_exc()
|
| Line 527... |
Line 536... |
| 527 |
|
536 |
|
| 528 |
|
537 |
|
| 529 |
|
538 |
|
| 530 |
|
539 |
|
| 531 |
def main():
|
540 |
def main():
|
| - |
|
541 |
readSSh("/tmp/order2015-04-23 12:39:09.743683")
|
| 532 |
store = getStore(1)
|
542 |
#store = getStore(1)
|
| 533 |
#store.scrapeStoreOrders()
|
543 |
#store.scrapeStoreOrders()
|
| 534 |
# br = mechanize.Browser()
|
544 |
# br = mechanize.Browser()
|
| 535 |
# br.addheaders = [('User-agent','Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11'),
|
545 |
# br.addheaders = [('User-agent','Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11'),
|
| 536 |
# ('Accept', 'text/html,application/xhtml+xml,application/json,application/xml;q=0.9,*/*;q=0.8'),
|
546 |
# ('Accept', 'text/html,application/xhtml+xml,application/json,application/xml;q=0.9,*/*;q=0.8'),
|
| 537 |
# ('Accept-Encoding', 'gzip,deflate,sdch'),
|
547 |
# ('Accept-Encoding', 'gzip,deflate,sdch'),
|
| 538 |
# ('Accept-Language', 'en-US,en;q=0.8'),
|
548 |
# ('Accept-Language', 'en-US,en;q=0.8'),
|
| 539 |
# ('Accept-Charset', 'ISO-8859-1,utf-8;q=0.7,*;q=0.3')]
|
549 |
# ('Accept-Charset', 'ISO-8859-1,utf-8;q=0.7,*;q=0.3')]
|
| 540 |
# store.scrapeStoreOrders()
|
550 |
# store.scrapeStoreOrders()
|
| 541 |
store.parseOrderRawHtml(1306, "13232", 14, readSSh("/home/amit/322.html"), "https://www.amazon.in/gp/css/summary/edit.html?orderID=171-5570474-5548341")
|
551 |
#store.parseOrderRawHtml(1306, "13232", 14, readSSh("/home/amit/322.html"), "https://www.amazon.in/gp/css/summary/edit.html?orderID=171-5570474-5548341")
|
| 542 |
#store.parseOrderRawHtml(2121, "13232", 14, readSSh("/home/amit/f1.html"), "https://www.amazon.in/gp/css/summary/edit.html?orderID=171-5196461-3230730")
|
552 |
#store.parseOrderRawHtml(2121, "13232", 14, readSSh("/home/amit/f1.html"), "https://www.amazon.in/gp/css/summary/edit.html?orderID=171-5196461-3230730")
|
| 543 |
#readSSh("/tmp/User211/2015-04-12 10:32:41.905765")
|
553 |
#readSSh("/tmp/User211/2015-04-12 10:32:41.905765")
|
| 544 |
#store.scrapeAffiliate()
|
554 |
#store.scrapeAffiliate()
|
| 545 |
def readSSh(fileName):
|
555 |
def readSSh(fileName):
|
| 546 |
try:
|
556 |
try:
|