| Line 68... |
Line 68... |
| 68 |
soup = BeautifulSoup(rawHtml)
|
68 |
soup = BeautifulSoup(rawHtml)
|
| 69 |
try:
|
69 |
try:
|
| 70 |
self.parseOldStlye(merchantOrder, soup)
|
70 |
self.parseOldStlye(merchantOrder, soup)
|
| 71 |
except:
|
71 |
except:
|
| 72 |
try:
|
72 |
try:
|
| - |
|
73 |
traceback.print_exc()
|
| 73 |
self.parseNewStlye(merchantOrder, soup)
|
74 |
self.parseNewStlye(merchantOrder, soup)
|
| 74 |
except:
|
75 |
except:
|
| - |
|
76 |
traceback.print_exc()
|
| 75 |
self.parseCancelled(merchantOrder, soup)
|
77 |
self.parseCancelled(merchantOrder, soup)
|
| 76 |
resp['result'] = 'ORDER_CREATED'
|
78 |
resp['result'] = 'ORDER_CREATED'
|
| 77 |
return resp
|
79 |
return resp
|
| 78 |
except:
|
80 |
except:
|
| 79 |
print "Error occurred"
|
81 |
print "Error occurred"
|
| Line 163... |
Line 165... |
| 163 |
self._updateToOrder(todict(merchantOrder))
|
165 |
self._updateToOrder(todict(merchantOrder))
|
| 164 |
|
166 |
|
| 165 |
def parseNewStlye(self, merchantOrder, soup):
|
167 |
def parseNewStlye(self, merchantOrder, soup):
|
| 166 |
merchantOrder.orderTrackingUrl = merchantOrder.orderSuccessUrl
|
168 |
merchantOrder.orderTrackingUrl = merchantOrder.orderSuccessUrl
|
| 167 |
orderDetailsContainer = soup.body.find(id="orderDetails")
|
169 |
orderDetailsContainer = soup.body.find(id="orderDetails")
|
| 168 |
orderLeftDiv = orderDetailsContainer.h1.next_sibling.next_sibling.div
|
170 |
divAfterH1 = orderDetailsContainer.h1.next_sibling.next_sibling
|
| - |
|
171 |
orderLeftDiv = divAfterH1.div
|
| 169 |
placedOnSpan = orderLeftDiv.find("span", {'class':'order-date-invoice-item'})
|
172 |
placedOnSpan = orderLeftDiv.find("span", {'class':'order-date-invoice-item'})
|
| 170 |
merchantOrder.placedOn =placedOnSpan.text.split('Ordered on')[1].strip()
|
173 |
merchantOrder.placedOn =placedOnSpan.text.split('Ordered on')[1].strip()
|
| 171 |
merchantOrder.merchantOrderId = placedOnSpan.next_sibling.next_sibling.text.split('Order#')[1].strip()
|
174 |
merchantOrder.merchantOrderId = placedOnSpan.next_sibling.next_sibling.text.split('Order#')[1].strip()
|
| 172 |
priceBox = orderDetailsContainer.find('div', {'class':re.compile(r'\ba-box-inner\b')}).div.div.findAll('div', recursive=False)[-1]
|
175 |
priceBox = divAfterH1.next_sibling.next_sibling.next_sibling.next_sibling.find("div", {"class":"a-box-inner"}).div.div.findAll('div', recursive=False)[-1]
|
| 173 |
priceRows = priceBox.findAll('div', {'class':'a-row'})
|
176 |
priceRows = priceBox.findAll('div', {'class':'a-row'})
|
| 174 |
subTotal = 0
|
177 |
subTotal = 0
|
| 175 |
shippingPrice = 0
|
178 |
shippingPrice = 0
|
| 176 |
promoApplied = 0
|
179 |
promoApplied = 0
|
| 177 |
for priceRow in priceRows:
|
180 |
for priceRow in priceRows:
|
| 178 |
if "Item(s) Subtotal:" in str(priceRow):
|
181 |
if "Item(s) Subtotal:" in str(priceRow):
|
| 179 |
subTotal = int(float(priceRow.div.next_sibling.next_sibling.span.span.text.replace('Rs.','').replace(',', '')))
|
182 |
subTotal = int(float(priceRow.div.next_sibling.next_sibling.span.span.text.replace('Rs.','').replace(',', '')))
|
| 180 |
elif "Shipping:" in str(priceRow):
|
183 |
elif "Shipping:" in str(priceRow):
|
| Line 198... |
Line 201... |
| 198 |
i=1
|
201 |
i=1
|
| 199 |
for shipmentDiv in shipmentDivs:
|
202 |
for shipmentDiv in shipmentDivs:
|
| 200 |
innerBoxes = shipmentDiv.findAll('div', recursive = False)
|
203 |
innerBoxes = shipmentDiv.findAll('div', recursive = False)
|
| 201 |
statusDiv = innerBoxes[0]
|
204 |
statusDiv = innerBoxes[0]
|
| 202 |
subOrderStatus = statusDiv.div.span.text.strip()
|
205 |
subOrderStatus = statusDiv.div.span.text.strip()
|
| 203 |
estimatedDeliveryDate = statusDiv.div.div.find_next_sibling('div').span.span.text.strip()
|
206 |
deliverySpan = statusDiv.div.div.find_next_sibling('div').span
|
| 204 |
productDivs = innerBoxes[-1].div.div.div.findAll('div', recursive=False)
|
207 |
productDivs = innerBoxes[-1].div.div.div.findAll('div', recursive=False)
|
| 205 |
subOrders = []
|
208 |
subOrders = []
|
| 206 |
merchantOrder.subOrders = subOrders
|
209 |
merchantOrder.subOrders = subOrders
|
| 207 |
for i, productDiv in enumerate(productDivs):
|
210 |
for i, productDiv in enumerate(productDivs):
|
| 208 |
i +=1
|
211 |
i +=1
|
| Line 215... |
Line 218... |
| 215 |
amountPaid = int((unitPrice*quantity*totalPaid)/subTotal)
|
218 |
amountPaid = int((unitPrice*quantity*totalPaid)/subTotal)
|
| 216 |
productUrl = "http://www.amazon.in" + detailDivs[0].a.get('href')
|
219 |
productUrl = "http://www.amazon.in" + detailDivs[0].a.get('href')
|
| 217 |
subOrder = SubOrder(productTitle, productUrl, merchantOrder.placedOn, amountPaid, MStore.ORDER_PLACED, quantity)
|
220 |
subOrder = SubOrder(productTitle, productUrl, merchantOrder.placedOn, amountPaid, MStore.ORDER_PLACED, quantity)
|
| 218 |
subOrder.productCode = productUrl.split('/')[5]
|
221 |
subOrder.productCode = productUrl.split('/')[5]
|
| 219 |
subOrder.unitPrice = unitPrice
|
222 |
subOrder.unitPrice = unitPrice
|
| 220 |
subOrder.merchantSubOrderId = str(i) + " of " + merchantOrder.merchantOrderId
|
223 |
subOrder.merchantSubOrderId = str(i) + " of " + merchantOrder.merchantOrderId
|
| - |
|
224 |
if deliverySpan is not None:
|
| 221 |
subOrder.estimatedDeliveryDate = estimatedDeliveryDate
|
225 |
subOrder.estimatedDeliveryDate = deliverySpan.span.text.strip()
|
| 222 |
subOrder.detailedStatus = subOrderStatus
|
226 |
subOrder.detailedStatus = subOrderStatus
|
| 223 |
subOrder.deliveryCharges = shippingPrice
|
227 |
subOrder.deliveryCharges = shippingPrice
|
| 224 |
subOrder.imgUrl = imgDiv.img["src"]
|
228 |
subOrder.imgUrl = imgDiv.img["src"]
|
| 225 |
(cashbackAmount, percentage) = self.getCashbackAmount(subOrder.productCode, amountPaid)
|
229 |
(cashbackAmount, percentage) = self.getCashbackAmount(subOrder.productCode, amountPaid)
|
| 226 |
cashbackStatus = Store.CB_PENDING
|
230 |
cashbackStatus = Store.CB_PENDING
|
| Line 379... |
Line 383... |
| 379 |
|
383 |
|
| 380 |
|
384 |
|
| 381 |
def main():
|
385 |
def main():
|
| 382 |
store = getStore(1)
|
386 |
store = getStore(1)
|
| 383 |
#store.scrapeStoreOrders()
|
387 |
#store.scrapeStoreOrders()
|
| 384 |
store.parseOrderRawHtml(1, 'saad', '21232211', readSSh('/home/amit/Downloads/710.html'), 'https://www.amazon.in/gp/css/summary/edit.html?orderID=12212')
|
388 |
store.parseOrderRawHtml(11112, 'saad', '21232211', readSSh('/home/amit/786.html'), 'https://www.amazon.in/gp/css/summary/edit.html?orderID=12212')
|
| 385 |
#store.trackOrdersForUser(8,'https://www.amazon.in/gp/css/order-history', readSSh('/tmp/User2/2015-03-03 00:29:40.165513'))
|
389 |
#store.trackOrdersForUser(8,'https://www.amazon.in/gp/css/order-history', readSSh('/tmp/User2/2015-03-03 00:29:40.165513'))
|
| 386 |
#readSSh('snapdeal.csv')
|
390 |
#readSSh('snapdeal.csv')
|
| 387 |
def readSSh(fileName):
|
391 |
def readSSh(fileName):
|
| 388 |
try:
|
392 |
try:
|
| 389 |
str1 = open(fileName).read()
|
393 |
str1 = open(fileName).read()
|