| Line 17... |
Line 17... |
| 17 |
import pymongo
|
17 |
import pymongo
|
| 18 |
import re
|
18 |
import re
|
| 19 |
import traceback
|
19 |
import traceback
|
| 20 |
import urllib
|
20 |
import urllib
|
| 21 |
import urllib2
|
21 |
import urllib2
|
| - |
|
22 |
from dtr.storage.Mongo import getDealRank
|
| 22 |
|
23 |
|
| 23 |
ORDERSTATUS = {"PAYMENT_PENDING" : 0,
|
24 |
ORDERSTATUS = {"PAYMENT_PENDING" : 0,
|
| 24 |
"PAYMENT_FAILED" : 1,
|
25 |
"PAYMENT_FAILED" : 1,
|
| 25 |
"COD_VERIFICATION_PENDING" : 2,
|
26 |
"COD_VERIFICATION_PENDING" : 2,
|
| 26 |
"SUBMITTED_FOR_PROCESSING" : 3,
|
27 |
"SUBMITTED_FOR_PROCESSING" : 3,
|
| Line 118... |
Line 119... |
| 118 |
'''
|
119 |
'''
|
| 119 |
OrderStatusMap = {
|
120 |
OrderStatusMap = {
|
| 120 |
MStore.ORDER_PLACED : [2,3,4,5,6,7,8,13],
|
121 |
MStore.ORDER_PLACED : [2,3,4,5,6,7,8,13],
|
| 121 |
MStore.ORDER_DELIVERED : [12],
|
122 |
MStore.ORDER_DELIVERED : [12],
|
| 122 |
MStore.ORDER_SHIPPED : [9,10,16,17,20,21,81,80],
|
123 |
MStore.ORDER_SHIPPED : [9,10,16,17,20,21,81,80],
|
| 123 |
MStore.ORDER_CANCELLED : [6,11,14,15,18,19,31,28,53,54,55,56]
|
124 |
MStore.ORDER_CANCELLED : [1,6,11,14,15,18,19,31,34,28,53,54,55,56]
|
| 124 |
}
|
125 |
}
|
| 125 |
|
126 |
|
| 126 |
|
127 |
|
| 127 |
def parseOrderRawHtml(self, orderId, subTagId, userId, rawHtml, orderSuccessUrl):
|
128 |
def parseOrderRawHtml(self, orderId, subTagId, userId, rawHtml, orderSuccessUrl):
|
| 128 |
resp = {}
|
129 |
resp = {}
|
| 129 |
paymentId = int(re.findall(r'=(.*)?',orderSuccessUrl)[0])
|
130 |
paymentId = int(re.findall(r'=(.*)?',orderSuccessUrl)[0])
|
| 130 |
orderRequest = urllib2.Request(SAHOLIC_ORDER_URL %(paymentId), headers=headers)
|
131 |
orderRequest = urllib2.Request(SAHOLIC_ORDER_URL %(paymentId), headers=headers)
|
| 131 |
try:
|
132 |
try:
|
| - |
|
133 |
self.userId = userId
|
| 132 |
connection = urllib2.urlopen(orderRequest)
|
134 |
connection = urllib2.urlopen(orderRequest)
|
| 133 |
response = connection.read()
|
135 |
response = connection.read()
|
| 134 |
connection.close()
|
136 |
connection.close()
|
| 135 |
response = json.loads(response)['response']
|
137 |
response = json.loads(response)['response']
|
| 136 |
payment = response['payment']
|
138 |
payment = response['payment']
|
| Line 175... |
Line 177... |
| 175 |
subOrder.imgUrl = item['imgUrl']
|
177 |
subOrder.imgUrl = item['imgUrl']
|
| 176 |
subOrder.productUrl = "http://m.saholic.com/" + item['url']
|
178 |
subOrder.productUrl = "http://m.saholic.com/" + item['url']
|
| 177 |
subOrder.productCode = item['url'].split('-')[-1]
|
179 |
subOrder.productCode = item['url'].split('-')[-1]
|
| 178 |
subOrder.detailedStatus = order['statusDescription']
|
180 |
subOrder.detailedStatus = order['statusDescription']
|
| 179 |
(cashbackAmount, percentage) = self.getCashbackAmount(subOrder.productCode, amountPaid)
|
181 |
(cashbackAmount, percentage) = self.getCashbackAmount(subOrder.productCode, amountPaid)
|
| - |
|
182 |
dealRank = getDealRank(subOrder.productCode, self.store_id, self.userId)
|
| - |
|
183 |
subOrder.dealRank = dealRank.get('rank')
|
| - |
|
184 |
subOrder.rankDesc = dealRank.get('description')
|
| 180 |
cashbackStatus = Store.CB_PENDING
|
185 |
cashbackStatus = Store.CB_PENDING
|
| 181 |
if cashbackAmount <= 0:
|
186 |
if cashbackAmount <= 0:
|
| 182 |
cashbackStatus = Store.CB_NA
|
187 |
cashbackStatus = Store.CB_NA
|
| 183 |
subOrder.cashBackStatus = cashbackStatus
|
188 |
subOrder.cashBackStatus = cashbackStatus
|
| 184 |
subOrder.cashBackAmount = cashbackAmount
|
189 |
subOrder.cashBackAmount = cashbackAmount
|
| Line 188... |
Line 193... |
| 188 |
def _getStatusFromDetailedStatus(self, detailedStatus):
|
193 |
def _getStatusFromDetailedStatus(self, detailedStatus):
|
| 189 |
for key, value in Store.OrderStatusMap.iteritems():
|
194 |
for key, value in Store.OrderStatusMap.iteritems():
|
| 190 |
if detailedStatus in value:
|
195 |
if detailedStatus in value:
|
| 191 |
return key
|
196 |
return key
|
| 192 |
print "Detailed Status need to be mapped", detailedStatus
|
197 |
print "Detailed Status need to be mapped", detailedStatus
|
| 193 |
raise ParseException("_getStatusFromDetailedStatus", "Found new order status" + detailedStatus)
|
198 |
raise ParseException("_getStatusFromDetailedStatus", "Found new order status" + str(detailedStatus))
|
| 194 |
|
199 |
|
| 195 |
|
200 |
|
| 196 |
def scrapeStoreOrders(self,):
|
201 |
def scrapeStoreOrders(self,):
|
| 197 |
trs = self._getActiveOrders(collectionMap={'merchantOrderId':1, 'sUserId':1})
|
202 |
trs = self._getActiveOrders(collectionMap={'merchantOrderId':1, 'sUserId':1})
|
| 198 |
bulk = self.db.merchantOrder.initialize_ordered_bulk_op()
|
203 |
bulk = self.db.merchantOrder.initialize_ordered_bulk_op()
|