| Line 25... |
Line 25... |
| 25 |
import os.path
|
25 |
import os.path
|
| 26 |
import re
|
26 |
import re
|
| 27 |
import time
|
27 |
import time
|
| 28 |
import traceback
|
28 |
import traceback
|
| 29 |
import urllib2
|
29 |
import urllib2
|
| - |
|
30 |
import pyquery
|
| 30 |
|
31 |
|
| 31 |
ORDER_REDIRECT_URL = 'https://www.amazon.in/gp/css/summary/edit.html?orderID=%s'
|
32 |
ORDER_REDIRECT_URL = 'https://www.amazon.in/gp/css/summary/edit.html?orderID=%s'
|
| 32 |
ORDER_SUCCESS_URL = 'https://www.amazon.in/gp/buy/spc/handlers/static-submit-decoupled.html'
|
33 |
ORDER_SUCCESS_URL = 'https://www.amazon.in/gp/buy/spc/handlers/static-submit-decoupled.html'
|
| 33 |
THANKYOU_URL = 'https://www.amazon.in/gp/buy/thankyou/handlers/display.html'
|
34 |
THANKYOU_URL = 'https://www.amazon.in/gp/buy/thankyou/handlers/display.html'
|
| 34 |
AMAZON_AFF_URL = 'https://assoc-datafeeds-eu.amazon.com/datafeed/listReports'
|
35 |
AMAZON_AFF_URL = 'https://assoc-datafeeds-eu.amazon.com/datafeed/listReports'
|
| Line 52... |
Line 53... |
| 52 |
print parseString, "Order Id to be parsed is :", orderId
|
53 |
print parseString, "Order Id to be parsed is :", orderId
|
| 53 |
resp = {}
|
54 |
resp = {}
|
| 54 |
resp['result'] = 'ORDER_NOT_CREATED'
|
55 |
resp['result'] = 'ORDER_NOT_CREATED'
|
| 55 |
if ORDER_SUCCESS_URL in orderSuccessUrl or THANKYOU_URL in orderSuccessUrl:
|
56 |
if ORDER_SUCCESS_URL in orderSuccessUrl or THANKYOU_URL in orderSuccessUrl:
|
| 56 |
try:
|
57 |
try:
|
| - |
|
58 |
from pyquery import PyQuery as pq
|
| 57 |
soup = BeautifulSoup(rawHtml)
|
59 |
doc = pq(rawHtml)
|
| 58 |
try:
|
60 |
try:
|
| 59 |
orderUrl = soup.find('div', {"id":"thank-you-box-wrapper"}).div.findAll('div', recursive=False)[1].a['href']
|
61 |
orderUrl = doc('a.a-touch-link').attr.href
|
| 60 |
merchantOrderId = re.findall(r'.*&oid=(.*)&?.*?', orderUrl)[0]
|
62 |
merchantOrderId = re.findall(r'.*&oid=(.*)&?.*?', orderUrl)[0]
|
| 61 |
except:
|
63 |
except:
|
| 62 |
merchantOrderId = soup.find(id="orders-list").div.span.b.text
|
64 |
merchantOrderId = doc("#orders-list>div>span>b").html()
|
| 63 |
order = Order(orderId, userId, subTagId, self.store_id, orderSuccessUrl, True)
|
65 |
order = Order(orderId, userId, subTagId, self.store_id, orderSuccessUrl, True)
|
| 64 |
order.orderTrackingUrl = ORDER_REDIRECT_URL % (merchantOrderId)
|
66 |
order.orderTrackingUrl = ORDER_REDIRECT_URL % (merchantOrderId)
|
| 65 |
order.orderSuccessUrl = orderSuccessUrl
|
67 |
order.orderSuccessUrl = orderSuccessUrl
|
| 66 |
order.merchantOrderId = merchantOrderId
|
68 |
order.merchantOrderId = merchantOrderId
|
| 67 |
order.requireDetail = True
|
69 |
order.requireDetail = True
|
| Line 75... |
Line 77... |
| 75 |
else:
|
77 |
else:
|
| 76 |
resp['result'] = 'ORDER_ALREADY_CREATED_IGNORED'
|
78 |
resp['result'] = 'ORDER_ALREADY_CREATED_IGNORED'
|
| 77 |
|
79 |
|
| 78 |
except:
|
80 |
except:
|
| 79 |
#Write all cases here for Order Not created Known
|
81 |
#Write all cases here for Order Not created Known
|
| - |
|
82 |
soup = BeautifulSoup(rawHtml)
|
| 80 |
try:
|
83 |
try:
|
| 81 |
if not soup.body:
|
84 |
if not soup.body:
|
| 82 |
resp['result'] = 'ORDER_NOT_CREATED_KNOWN'
|
85 |
resp['result'] = 'ORDER_NOT_CREATED_KNOWN'
|
| 83 |
elif 'Securely redirecting you' in soup.find("h3").text.strip() or soup.find("h3").text.strip()=="Orders":
|
86 |
elif 'Securely redirecting you' in soup.find("h3").text.strip() or soup.find("h3").text.strip()=="Orders":
|
| 84 |
resp['result'] = 'ORDER_NOT_CREATED_KNOWN'
|
87 |
resp['result'] = 'ORDER_NOT_CREATED_KNOWN'
|
| Line 764... |
Line 767... |
| 764 |
# o = session.query(OrdersRaw).filter_by(id = orderId).one()
|
767 |
# o = session.query(OrdersRaw).filter_by(id = orderId).one()
|
| 765 |
# o.status = 'ORDER_CREATED'
|
768 |
# o.status = 'ORDER_CREATED'
|
| 766 |
# session.commit()
|
769 |
# session.commit()
|
| 767 |
# finally:
|
770 |
# finally:
|
| 768 |
# session.close()
|
771 |
# session.close()
|
| 769 |
store.trackOrdersForUser(10466, 'https://www.amazon.in/gp/css/summary/edit.html?orderID=403-7498756-0837158', readSSh('/AmazonTrack/User10466/403-7498756-0837158'))
|
772 |
#store.trackOrdersForUser(10466, 'https://www.amazon.in/gp/css/summary/edit.html?orderID=403-7498756-0837158', readSSh('/AmazonTrack/User10466/403-7498756-0837158'))
|
| 770 |
store.trackOrdersForUser(10466, 'https://www.amazon.in/gp/css/summary/edit.html?orderID=403-2539406-8617932', readSSh('/AmazonTrack/User10466/403-2539406-8617932'))
|
773 |
#store.trackOrdersForUser(10466, 'https://www.amazon.in/gp/css/summary/edit.html?orderID=403-2539406-8617932', readSSh('/AmazonTrack/User10466/403-2539406-8617932'))
|
| 771 |
#store.parseOrderRawHtml(3324325, '12', 10466, readSSh('/home/amit/s1.html'), 'https://www.amazon.in/gp/css/summary/edit.html?orderID=403-7498756-0837158')
|
774 |
store.parseOrderRawHtml(58599, 'sub123', 9981, readSSh('/home/amit/sample.html'), 'https://www.amazon.in/gp/buy/spc/handlers/static-submit-decoupled.html/ref=ox_spc_place_order?ie=UTF8&fromAnywhere=1&hasWorkingJav')
|
| 772 |
|
775 |
|
| 773 |
def getSummaryFile(directory):
|
776 |
def getSummaryFile(directory):
|
| 774 |
date1 = datetime(2015,1,1)
|
777 |
date1 = datetime(2015,1,1)
|
| 775 |
finalFile = None
|
778 |
finalFile = None
|
| 776 |
try:
|
779 |
try:
|