| Line 40... |
Line 40... |
| 40 |
def parseOrderRawHtml(self, orderId, subTagId, userId, rawHtml, orderSuccessUrl, insert=False):
|
40 |
def parseOrderRawHtml(self, orderId, subTagId, userId, rawHtml, orderSuccessUrl, insert=False):
|
| 41 |
resp = {}
|
41 |
resp = {}
|
| 42 |
if ORDER_SUCCESS_URL in orderSuccessUrl or THANKYOU_URL in orderSuccessUrl:
|
42 |
if ORDER_SUCCESS_URL in orderSuccessUrl or THANKYOU_URL in orderSuccessUrl:
|
| 43 |
try:
|
43 |
try:
|
| 44 |
soup = BeautifulSoup(rawHtml)
|
44 |
soup = BeautifulSoup(rawHtml)
|
| - |
|
45 |
try:
|
| 45 |
orderUrl = soup.find('div', {"id":"thank-you-box-wrapper"}).div.findAll('div', recursive=False)[1].a['href']
|
46 |
orderUrl = soup.find('div', {"id":"thank-you-box-wrapper"}).div.findAll('div', recursive=False)[1].a['href']
|
| 46 |
merchantOrderId = re.findall(r'.*&oid=(.*)&?.*?', orderUrl)[0]
|
47 |
merchantOrderId = re.findall(r'.*&oid=(.*)&?.*?', orderUrl)[0]
|
| - |
|
48 |
except:
|
| - |
|
49 |
merchantOrderId = soup.find(id="orders-list").div.span.b.text
|
| 47 |
order = Order(orderId, userId, subTagId, self.store_id, orderSuccessUrl, False)
|
50 |
order = Order(orderId, userId, subTagId, self.store_id, orderSuccessUrl, False)
|
| 48 |
order.orderSuccessUrl = ORDER_REDIRECT_URL % (merchantOrderId)
|
51 |
order.orderSuccessUrl = ORDER_REDIRECT_URL % (merchantOrderId)
|
| 49 |
order.merchantOrderId = merchantOrderId
|
52 |
order.merchantOrderId = merchantOrderId
|
| 50 |
order.requireDetail = True
|
53 |
order.requireDetail = True
|
| 51 |
order.closed = None
|
54 |
order.closed = None
|
| Line 83... |
Line 86... |
| 83 |
resp['result'] = 'ORDER_NOT_CREATED'
|
86 |
resp['result'] = 'ORDER_NOT_CREATED'
|
| 84 |
return resp
|
87 |
return resp
|
| 85 |
|
88 |
|
| 86 |
#This should be exposed from api for specific sources
|
89 |
#This should be exposed from api for specific sources
|
| 87 |
def scrapeStoreOrders(self):
|
90 |
def scrapeStoreOrders(self):
|
| - |
|
91 |
# br = getBrowserObject()
|
| - |
|
92 |
# orders = self.db.merchantOrder.find({"storeId":1, "closed":False, "subOrders.closed":False, "subOrders.trackingUrl":{"$exists":True}})
|
| - |
|
93 |
# for merchantOrder in orders:
|
| - |
|
94 |
# for subOrder in merchantOrder.get("subOrders"):
|
| - |
|
95 |
# trackingUrl = subOrder.get("trackingUrl")
|
| - |
|
96 |
# if not subOrder.get("closed") and trackingUrl is not None:
|
| - |
|
97 |
#
|
| - |
|
98 |
# self.parseTrackingUrl(br, trackingUrl)
|
| 88 |
pass
|
99 |
pass
|
| - |
|
100 |
|
| - |
|
101 |
|
| - |
|
102 |
|
| 89 |
|
103 |
|
| 90 |
def parseOldStlye(self, merchantOrder, soup):
|
104 |
def parseOldStlye(self, merchantOrder, soup):
|
| 91 |
merchantOrder.orderTrackingUrl = merchantOrder.orderSuccessUrl
|
105 |
merchantOrder.orderTrackingUrl = merchantOrder.orderSuccessUrl
|
| 92 |
table = soup.body.findAll("table", recursive=False)[1]
|
106 |
table = soup.body.findAll("table", recursive=False)[1]
|
| 93 |
#print table
|
107 |
#print table
|
| Line 317... |
Line 331... |
| 317 |
trackingUrl = None
|
331 |
trackingUrl = None
|
| 318 |
for buttonDiv in shipdiv.findAll('span', {'class':'a-button-inner'}):
|
332 |
for buttonDiv in shipdiv.findAll('span', {'class':'a-button-inner'}):
|
| 319 |
if buttonDiv.find('a').text.strip()=='Track package':
|
333 |
if buttonDiv.find('a').text.strip()=='Track package':
|
| 320 |
trackingUrl = buttonDiv.find('a')['href'].strip()
|
334 |
trackingUrl = buttonDiv.find('a')['href'].strip()
|
| 321 |
if not trackingUrl.startswith("http"):
|
335 |
if not trackingUrl.startswith("http"):
|
| 322 |
trackingUrl = "https://www.amazon.in/" + trackingUrl
|
336 |
trackingUrl = "http://www.amazon.in" + trackingUrl
|
| 323 |
break
|
337 |
break
|
| 324 |
for prodDiv in productDivs:
|
338 |
for prodDiv in productDivs:
|
| 325 |
prodDiv.find('div', {'class':'a-fixed-left-grid-inner'})
|
339 |
prodDiv.find('div', {'class':'a-fixed-left-grid-inner'})
|
| 326 |
productTitle = prodDiv.find('div', {'class':'a-fixed-left-grid-inner'}).find("div", {'class':'a-row'}).find('a').text.strip()
|
340 |
productTitle = prodDiv.find('div', {'class':'a-fixed-left-grid-inner'}).find("div", {'class':'a-row'}).find('a').text.strip()
|
| 327 |
imgUrl = prodDiv.find("img")["src"]
|
341 |
imgUrl = prodDiv.find("img")["src"]
|
| Line 378... |
Line 392... |
| 378 |
return key
|
392 |
return key
|
| 379 |
|
393 |
|
| 380 |
print "Detailed Status need to be mapped"
|
394 |
print "Detailed Status need to be mapped"
|
| 381 |
print "Found new order status", detailedStatus
|
395 |
print "Found new order status", detailedStatus
|
| 382 |
raise ParseException("_getStatusFromDetailedStatus", "Found new order status" + detailedStatus)
|
396 |
raise ParseException("_getStatusFromDetailedStatus", "Found new order status" + detailedStatus)
|
| - |
|
397 |
|
| - |
|
398 |
def parseTrackingUrl(self, br, trackingUrl):
|
| - |
|
399 |
response = br.open(trackingUrl)
|
| - |
|
400 |
page = ungzipResponse(response)
|
| - |
|
401 |
soup = BeautifulSoup(page,convertEntities=BeautifulSoup.HTML_ENTITIES)
|
| - |
|
402 |
alertContainer = soup.find("a-box-inner a-alert-container")
|
| - |
|
403 |
|
| - |
|
404 |
|
| 383 |
|
405 |
|
| 384 |
|
406 |
|
| 385 |
def main():
|
407 |
def main():
|
| 386 |
store = getStore(1)
|
408 |
store = getStore(1)
|
| 387 |
#store.scrapeStoreOrders()
|
409 |
#br = getBrowserObject()
|
| 388 |
store.parseOrderRawHtml(11112, 'saad', '21232211', readSSh('/home/amit/786.html'), 'https://www.amazon.in/gp/css/summary/edit.html?orderID=12212')
|
410 |
#store.parseTrackingUrl(br, "http://www.amazon.in//gp/css/shiptrack/view.html/ref=oh_aui_direct_track_pkg_o00_s00?ie=UTF8&marketplaceOfOrigin=&orderID=171-7613541-7425906&orderingShipmentId=729710930106&packageId=1&ref=")
|
| 389 |
#store.trackOrdersForUser(8,'https://www.amazon.in/gp/css/order-history', readSSh('/tmp/User2/2015-03-03 00:29:40.165513'))
|
411 |
store.parseOrderRawHtml(2121, "13232", 14, readSSh("/home/amit/917.html"), "https://www.amazon.in/gp/buy/spc/handlers/static-submit-decoupled.html/ref=ox_spc_place_order?ie=UTF8&hasWorkingJavascript=")
|
| 390 |
#readSSh('snapdeal.csv')
|
- |
|
| 391 |
def readSSh(fileName):
|
412 |
def readSSh(fileName):
|
| 392 |
try:
|
413 |
try:
|
| 393 |
str1 = open(fileName).read()
|
414 |
str1 = open(fileName).read()
|
| 394 |
return str1
|
415 |
return str1
|
| 395 |
except:
|
416 |
except:
|