| Line 124... |
Line 124... |
| 124 |
elif "Subtotal" in subTrString:
|
124 |
elif "Subtotal" in subTrString:
|
| 125 |
if int(qty) > 0:
|
125 |
if int(qty) > 0:
|
| 126 |
amountPaid = str(int(re.findall(r'\d+', subTrString)[0])/int(qty))
|
126 |
amountPaid = str(int(re.findall(r'\d+', subTrString)[0])/int(qty))
|
| 127 |
else:
|
127 |
else:
|
| 128 |
amountPaid = "0"
|
128 |
amountPaid = "0"
|
| - |
|
129 |
|
| - |
|
130 |
#TODO: cashbackAmount = getCashbackAmount()
|
| - |
|
131 |
cashbackAmount = 0
|
| - |
|
132 |
cashbackStatus = Store.CB_PENDING
|
| - |
|
133 |
if cashbackAmount <= 0:
|
| - |
|
134 |
cashbackStatus = Store.CB_NA
|
| 129 |
|
135 |
|
| 130 |
divs = subOrderElement.findAll("div", {"class": "blk lrPad subordrs"})
|
136 |
divs = subOrderElement.findAll("div", {"class": "blk lrPad subordrs"})
|
| 131 |
if len(divs)<=0:
|
137 |
if len(divs)<=0:
|
| 132 |
raise ParseException("subOrder", "Could not Parse suborders for Snapdeal")
|
138 |
raise ParseException("subOrder", "Could not Parse suborders for Snapdeal")
|
| 133 |
|
139 |
|
| Line 139... |
Line 145... |
| 139 |
subOrder.amountPaid = amountPaid
|
145 |
subOrder.amountPaid = amountPaid
|
| 140 |
subOrder.deliveryCharges = deliveryCharges
|
146 |
subOrder.deliveryCharges = deliveryCharges
|
| 141 |
subOrder.offerDiscount = offerDiscount
|
147 |
subOrder.offerDiscount = offerDiscount
|
| 142 |
subOrder.unitPrice = unitPrice
|
148 |
subOrder.unitPrice = unitPrice
|
| 143 |
subOrder.productCode = re.findall(r'\d+$', productUrl)[0]
|
149 |
subOrder.productCode = re.findall(r'\d+$', productUrl)[0]
|
| - |
|
150 |
subOrder.cashBackStatus = cashbackStatus
|
| - |
|
151 |
subOrder.cashBackAmount = cashbackAmount
|
| - |
|
152 |
|
| 144 |
|
153 |
|
| 145 |
trackAnchor = div.find("a")
|
154 |
trackAnchor = div.find("a")
|
| 146 |
if trackAnchor is not None:
|
155 |
if trackAnchor is not None:
|
| 147 |
subOrder.tracingkUrl = str(trackAnchor['href'])
|
156 |
subOrder.tracingkUrl = str(trackAnchor['href'])
|
| 148 |
|
157 |
|
| Line 184... |
Line 193... |
| 184 |
for key, value in Store.OrderStatusMap.iteritems():
|
193 |
for key, value in Store.OrderStatusMap.iteritems():
|
| 185 |
if detailedStatus in value:
|
194 |
if detailedStatus in value:
|
| 186 |
return key
|
195 |
return key
|
| 187 |
raise ParseException("_getStatusFromDetailedStatus", "Found new order status" + detailedStatus)
|
196 |
raise ParseException("_getStatusFromDetailedStatus", "Found new order status" + detailedStatus)
|
| 188 |
|
197 |
|
| - |
|
198 |
def settlePayBack(self):
|
| - |
|
199 |
pass
|
| - |
|
200 |
|
| 189 |
def scrapeStoreOrders(self,):
|
201 |
def scrapeStoreOrders(self,):
|
| 190 |
orders = self._getActiveOrders()
|
202 |
orders = self._getActiveOrders()
|
| 191 |
br = getBrowserObject()
|
203 |
br = getBrowserObject()
|
| 192 |
for order in orders:
|
204 |
for order in orders:
|
| 193 |
url = ORDER_TRACK_URL + re.findall('.*(\?.*?)$', order['orderSuccessUrl'],re.IGNORECASE)[0]
|
205 |
url = ORDER_TRACK_URL + re.findall('.*(\?.*?)$', order['orderSuccessUrl'],re.IGNORECASE)[0]
|
| Line 206... |
Line 218... |
| 206 |
divs = subOrderElement.findAll("div", {"class": "blk lrPad subordrs"})
|
218 |
divs = subOrderElement.findAll("div", {"class": "blk lrPad subordrs"})
|
| 207 |
if len(divs)<=0:
|
219 |
if len(divs)<=0:
|
| 208 |
raise ParseException("subOrder", "Could not Parse suborders for Snapdeal")
|
220 |
raise ParseException("subOrder", "Could not Parse suborders for Snapdeal")
|
| 209 |
|
221 |
|
| 210 |
for div in divs:
|
222 |
for div in divs:
|
| 211 |
trackAnchor = div.find("a")
|
- |
|
| 212 |
if trackAnchor is not None:
|
- |
|
| 213 |
tracingkUrl = str(trackAnchor['href'])
|
- |
|
| 214 |
|
- |
|
| 215 |
divStr = str(div)
|
223 |
divStr = str(div)
|
| 216 |
divStr = divStr.replace("\n","").replace("\t", "")
|
224 |
divStr = divStr.replace("\n","").replace("\t", "")
|
| 217 |
updateMap = {}
|
225 |
updateMap = {}
|
| 218 |
for line in divStr.split("<br />"):
|
226 |
for line in divStr.split("<br />"):
|
| 219 |
if "Suborder ID" in line:
|
227 |
if "Suborder ID" in line:
|
| 220 |
merchantSubOrderId = re.findall(r'\d+', line)[0]
|
228 |
merchantSubOrderId = re.findall(r'\d+', line)[0]
|
| 221 |
findMap = {"id": order['id'], "subOrders.merchantSubOrderId": merchantSubOrderId}
|
229 |
findMap = {"orderId": order['orderId'], "subOrders.merchantSubOrderId": merchantSubOrderId}
|
| 222 |
elif "Status" in line:
|
230 |
elif "Status" in line:
|
| 223 |
detailedStatus = re.findall('>(.*?)</span>', line, re.IGNORECASE)[0]
|
231 |
detailedStatus = re.findall('>(.*?)</span>', line, re.IGNORECASE)[0]
|
| 224 |
detailedStatus = re.findall('>(.*?)</span>', line, re.IGNORECASE)[0]
|
232 |
detailedStatus = re.findall('>(.*?)</span>', line, re.IGNORECASE)[0]
|
| 225 |
updateMap["subOrders.$.detailedStatus"] = detailedStatus
|
233 |
updateMap["subOrders.$.detailedStatus"] = detailedStatus
|
| 226 |
status = self._getStatusFromDetailedStatus(detailedStatus)
|
234 |
status = self._getStatusFromDetailedStatus(detailedStatus)
|
| 227 |
if closed:
|
235 |
if closed:
|
| 228 |
closed = status in [Store.ORDER_PLACED, Store.ORDER_CANCELLED]
|
236 |
closed = status in [Store.ORDER_DELIVERED, Store.ORDER_CANCELLED]
|
| 229 |
elif "Est. Shipping Date" in line:
|
237 |
elif "Est. Shipping Date" in line:
|
| 230 |
estimatedShippingDate = line.split(":")[1].strip()
|
238 |
estimatedShippingDate = line.split(":")[1].strip()
|
| 231 |
updateMap["subOrders.$.estimatedShippingDate"] = estimatedShippingDate
|
239 |
updateMap["subOrders.$.estimatedShippingDate"] = estimatedShippingDate
|
| 232 |
elif "Est. Delivery Date" in line:
|
240 |
elif "Est. Delivery Date" in line:
|
| 233 |
estimatedDeliveryDate = line.split(":")[1].strip()
|
241 |
estimatedDeliveryDate = line.split(":")[1].strip()
|
| Line 237... |
Line 245... |
| 237 |
updateMap["subOrders.$.courierName"] = courierName
|
245 |
updateMap["subOrders.$.courierName"] = courierName
|
| 238 |
elif "Tracking No" in line:
|
246 |
elif "Tracking No" in line:
|
| 239 |
trackingNumber = line.split(":")[1].strip()
|
247 |
trackingNumber = line.split(":")[1].strip()
|
| 240 |
updateMap["subOrders.$.trackingNumber"] = trackingNumber
|
248 |
updateMap["subOrders.$.trackingNumber"] = trackingNumber
|
| 241 |
|
249 |
|
| 242 |
updateMap["subOrders.$.closed"] = closed
|
- |
|
| 243 |
bulk.find(findMap).update({'$set' : updateMap})
|
250 |
bulk.find(findMap).update({'$set' : updateMap})
|
| - |
|
251 |
bulk.find({'orderId': order['orderId']}).update({'$set':{'closed': closed}})
|
| 244 |
result = bulk.execute()
|
252 |
result = bulk.execute()
|
| 245 |
pprint(result)
|
253 |
pprint(result)
|
| 246 |
|
254 |
|
| 247 |
"""
|
255 |
"""
|
| 248 |
This will insert records with changes only
|
256 |
This will insert records with changes only
|
| 249 |
"""
|
257 |
"""
|
| 250 |
|
258 |
|
| 251 |
def _getActiveOrders(self):
|
259 |
def _getActiveOrders(self):
|
| 252 |
collection = self.db.merchantOrder
|
260 |
collection = self.db.merchantOrder
|
| - |
|
261 |
collectionMap = {"orderSuccessUrl":1, "orderId":1,"subOrders.merchantSubOrderId":1,"subOrders.closed":1}
|
| 253 |
stores = collection.find({"closed": False, "storeId" : self.store_id}, {"orderSuccessUrl":1, "id":1})
|
262 |
stores = collection.find({"closed": False, "storeId" : self.store_id}, collectionMap)
|
| 254 |
return [store for store in stores]
|
263 |
return [store for store in stores]
|
| 255 |
|
264 |
|
| 256 |
|
265 |
|
| 257 |
|
266 |
|
| 258 |
def _saveToAffiliate(self, offers):
|
267 |
def _saveToAffiliate(self, offers):
|