| Line 23... |
Line 23... |
| 23 |
import re
|
23 |
import re
|
| 24 |
import time
|
24 |
import time
|
| 25 |
import traceback
|
25 |
import traceback
|
| 26 |
import urllib2
|
26 |
import urllib2
|
| 27 |
from dtr.storage.Mongo import getDealRank
|
27 |
from dtr.storage.Mongo import getDealRank
|
| - |
|
28 |
from dtr.storage.DataService import OrdersRaw
|
| - |
|
29 |
from elixir import *
|
| 28 |
|
30 |
|
| 29 |
ORDER_REDIRECT_URL = 'https://www.amazon.in/gp/css/summary/edit.html?orderID=%s'
|
31 |
ORDER_REDIRECT_URL = 'https://www.amazon.in/gp/css/summary/edit.html?orderID=%s'
|
| 30 |
ORDER_SUCCESS_URL = 'https://www.amazon.in/gp/buy/spc/handlers/static-submit-decoupled.html'
|
32 |
ORDER_SUCCESS_URL = 'https://www.amazon.in/gp/buy/spc/handlers/static-submit-decoupled.html'
|
| 31 |
THANKYOU_URL = 'https://www.amazon.in/gp/buy/thankyou/handlers/display.html'
|
33 |
THANKYOU_URL = 'https://www.amazon.in/gp/buy/thankyou/handlers/display.html'
|
| 32 |
AMAZON_AFF_URL = 'https://assoc-datafeeds-eu.amazon.com/datafeed/listReports'
|
34 |
AMAZON_AFF_URL = 'https://assoc-datafeeds-eu.amazon.com/datafeed/listReports'
|
| Line 269... |
Line 271... |
| 269 |
divAfterH1 = orderDetailsContainer.h1.next_sibling.next_sibling
|
271 |
divAfterH1 = orderDetailsContainer.h1.next_sibling.next_sibling
|
| 270 |
orderLeftDiv = divAfterH1.div
|
272 |
orderLeftDiv = divAfterH1.div
|
| 271 |
placedOnSpan = orderLeftDiv.find("span", {'class':'order-date-invoice-item'})
|
273 |
placedOnSpan = orderLeftDiv.find("span", {'class':'order-date-invoice-item'})
|
| 272 |
merchantOrder.placedOn =placedOnSpan.text.split('Ordered on')[1].strip()
|
274 |
merchantOrder.placedOn =placedOnSpan.text.split('Ordered on')[1].strip()
|
| 273 |
merchantOrder.merchantOrderId = placedOnSpan.next_sibling.next_sibling.text.split('Order#')[1].strip()
|
275 |
merchantOrder.merchantOrderId = placedOnSpan.next_sibling.next_sibling.text.split('Order#')[1].strip()
|
| - |
|
276 |
try:
|
| 274 |
priceBox = divAfterH1.next_sibling.next_sibling.next_sibling.next_sibling.find("div", {"class":"a-box-inner"}).div.div.findAll('div', recursive=False)[-1]
|
277 |
priceBox = divAfterH1.next_sibling.next_sibling.next_sibling.next_sibling.find("div", {"class":"a-box-inner"}).div.div.findAll('div', recursive=False)[-1]
|
| - |
|
278 |
except:
|
| - |
|
279 |
priceBox = divAfterH1.next_sibling.next_sibling.next_sibling.next_sibling.find("div", {"class":"a-box a-last"}).div.div.findAll('div', recursive=False)[-1]
|
| 275 |
priceRows = priceBox.findAll('div', {'class':'a-row'})
|
280 |
priceRows = priceBox.findAll('div', {'class':'a-row'})
|
| 276 |
subTotal = 0
|
281 |
subTotal = 0
|
| 277 |
shippingPrice = 0
|
282 |
shippingPrice = 0
|
| 278 |
promoApplied = 0
|
283 |
promoApplied = 0
|
| 279 |
for priceRow in priceRows:
|
284 |
for priceRow in priceRows:
|
| Line 504... |
Line 509... |
| 504 |
|
509 |
|
| 505 |
filename = directory + "/" + merchantOrderId
|
510 |
filename = directory + "/" + merchantOrderId
|
| 506 |
f = open(filename,'w')
|
511 |
f = open(filename,'w')
|
| 507 |
f.write(rawHtml) # python will convert \n to os.linesep
|
512 |
f.write(rawHtml) # python will convert \n to os.linesep
|
| 508 |
f.close() # you can omit in most cases as the destructor will call if
|
513 |
f.close() # you can omit in most cases as the destructor will call if
|
| 509 |
self.parseOrderRawHtml(merchantOrder['orderId'], merchantOrder['subTagId'], merchantOrder['userId'], rawHtml, url, True)['result']
|
514 |
result = self.parseOrderRawHtml(merchantOrder['orderId'], merchantOrder['subTagId'], merchantOrder['userId'], rawHtml, url, True)['result']
|
| - |
|
515 |
try:
|
| - |
|
516 |
order = session.query(OrdersRaw).filter_by(id=merchantOrder['orderId'])
|
| - |
|
517 |
order.status = result
|
| - |
|
518 |
order.raw_html = rawHtml
|
| - |
|
519 |
session.commit()
|
| - |
|
520 |
finally:
|
| - |
|
521 |
session.close()
|
| 510 |
return 'PARSED_SUCCESS'
|
522 |
return 'PARSED_SUCCESS'
|
| 511 |
pass
|
523 |
pass
|
| 512 |
return 'PARSED_SUCCESS_NO_ORDERS'
|
524 |
return 'PARSED_SUCCESS_NO_ORDERS'
|
| 513 |
except:
|
525 |
except:
|
| 514 |
traceback.print_exc()
|
526 |
traceback.print_exc()
|
| Line 594... |
Line 606... |
| 594 |
# ('Accept', 'text/html,application/xhtml+xml,application/json,application/xml;q=0.9,*/*;q=0.8'),
|
606 |
# ('Accept', 'text/html,application/xhtml+xml,application/json,application/xml;q=0.9,*/*;q=0.8'),
|
| 595 |
# ('Accept-Encoding', 'gzip,deflate,sdch'),
|
607 |
# ('Accept-Encoding', 'gzip,deflate,sdch'),
|
| 596 |
# ('Accept-Language', 'en-US,en;q=0.8'),
|
608 |
# ('Accept-Language', 'en-US,en;q=0.8'),
|
| 597 |
# ('Accept-Charset', 'ISO-8859-1,utf-8;q=0.7,*;q=0.3')]
|
609 |
# ('Accept-Charset', 'ISO-8859-1,utf-8;q=0.7,*;q=0.3')]
|
| 598 |
# store.scrapeStoreOrders()
|
610 |
# store.scrapeStoreOrders()
|
| 599 |
#store.parseOrderRawHtml(4333, "13232", 14, readSSh("/tmp/4333"), "https://www.amazon.in/gp/buy/thankyou/handlers/display.html?ie=UTF8&from=Visa&fromAnywhere=1&isFromThirdParty=1&purchaseId=404-9350243-7228362&processorId=eJxzSSxJdE4szgAADOkC%2Bg%3D%3D")
|
611 |
#store.parseOrderRawHtml(3418, "13232", 14, readSSh("/home/amit/3418"), "https://www.amazon.in/gp/css/summary/edit.html?orderID=402-1853822-0778736")
|
| 600 |
store.trackOrdersForUser(1306, "https://www.amazon.in/gp/css/summary/edit.html?orderID=171-0886591-1480333", readSSh("/AmazonTrack/User91/171-0886591-1480333"))
|
612 |
#store.trackOrdersForUser(4355, "https://www.amazon.in/gp/css/summary/edit.html?orderID=171-4824011-7090713", readSSh("~/4355"))
|
| 601 |
#readSSh("/tmp/User211/2015-04-12 10:32:41.905765")
|
613 |
#readSSh("/tmp/User211/2015-04-12 10:32:41.905765")
|
| 602 |
#store.scrapeAffiliate()
|
614 |
#store.scrapeAffiliate()
|
| - |
|
615 |
parseDetailNotCreated()
|
| - |
|
616 |
|
| - |
|
617 |
def parseDetailNotCreated():
|
| - |
|
618 |
try:
|
| - |
|
619 |
store=getStore(1)
|
| - |
|
620 |
orders = session.query(OrdersRaw).filter_by(status='DETAIL_NOT_CREATED_UNKNOWN').all()
|
| - |
|
621 |
for order in orders:
|
| - |
|
622 |
store.trackOrdersForUser(order.id, order.order_url, order.rawhtml)
|
| - |
|
623 |
|
| - |
|
624 |
finally:
|
| - |
|
625 |
session.close()
|
| - |
|
626 |
|
| 603 |
def readSSh(fileName):
|
627 |
def readSSh(fileName):
|
| 604 |
try:
|
628 |
try:
|
| 605 |
str1 = open(fileName).read()
|
629 |
str1 = open(fileName).read()
|
| 606 |
return str1
|
630 |
return str1
|
| 607 |
except:
|
631 |
except:
|