| Line 223... |
Line 223... |
| 223 |
divStr = str(div)
|
223 |
divStr = str(div)
|
| 224 |
divStr = divStr.replace("\n","").replace("\t", "")
|
224 |
divStr = divStr.replace("\n","").replace("\t", "")
|
| 225 |
updateMap = {}
|
225 |
updateMap = {}
|
| 226 |
for line in divStr.split("<br />"):
|
226 |
for line in divStr.split("<br />"):
|
| 227 |
if "Suborder ID" in line:
|
227 |
if "Suborder ID" in line:
|
| 228 |
merchantSubOrderId = re.findall(r'\d+', line)[0]
|
228 |
merchantSubOrderId = re.findall(r'\d+', line)[0]
|
| - |
|
229 |
#break if suborder is inactive
|
| 229 |
findMap = {"orderId": order['orderId'], "subOrders.merchantSubOrderId": merchantSubOrderId}
|
230 |
findMap = {"orderId": order['orderId'], "subOrders.merchantSubOrderId": merchantSubOrderId}
|
| - |
|
231 |
if not self._isSubOrderActive(order, merchantSubOrderId):
|
| - |
|
232 |
break
|
| 230 |
elif "Status" in line:
|
233 |
elif "Status" in line:
|
| 231 |
detailedStatus = re.findall('>(.*?)</span>', line, re.IGNORECASE)[0]
|
234 |
detailedStatus = re.findall('>(.*?)</span>', line, re.IGNORECASE)[0]
|
| 232 |
detailedStatus = re.findall('>(.*?)</span>', line, re.IGNORECASE)[0]
|
235 |
detailedStatus = re.findall('>(.*?)</span>', line, re.IGNORECASE)[0]
|
| 233 |
updateMap["subOrders.$.detailedStatus"] = detailedStatus
|
236 |
updateMap["subOrders.$.detailedStatus"] = detailedStatus
|
| 234 |
status = self._getStatusFromDetailedStatus(detailedStatus)
|
237 |
status = self._getStatusFromDetailedStatus(detailedStatus)
|
| - |
|
238 |
closedStatus = status in [Store.ORDER_DELIVERED, Store.ORDER_CANCELLED]
|
| 235 |
if closed:
|
239 |
if closedStatus:
|
| - |
|
240 |
#if status is closed then change the paybackStatus accordingly
|
| 236 |
closed = status in [Store.ORDER_DELIVERED, Store.ORDER_CANCELLED]
|
241 |
if closedStatus == Store.ORDER_DELIVERED:
|
| - |
|
242 |
if order.get("cashBackStatus") == Store.CB_PENDING:
|
| - |
|
243 |
updateMap["subOrders.$.cashBackStatus"] = Store.CB_APPROVED
|
| - |
|
244 |
elif closedStatus == Store.ORDER_CANCELLED:
|
| - |
|
245 |
if order.get("cashBackStatus") == Store.CB_PENDING:
|
| - |
|
246 |
updateMap["subOrders.$.cashBackStatus"] = Store.CB_CANCELLED
|
| - |
|
247 |
|
| - |
|
248 |
else:
|
| - |
|
249 |
closed = False
|
| 237 |
elif "Est. Shipping Date" in line:
|
250 |
elif "Est. Shipping Date" in line:
|
| 238 |
estimatedShippingDate = line.split(":")[1].strip()
|
251 |
estimatedShippingDate = line.split(":")[1].strip()
|
| 239 |
updateMap["subOrders.$.estimatedShippingDate"] = estimatedShippingDate
|
252 |
updateMap["subOrders.$.estimatedShippingDate"] = estimatedShippingDate
|
| 240 |
elif "Est. Delivery Date" in line:
|
253 |
elif "Est. Delivery Date" in line:
|
| 241 |
estimatedDeliveryDate = line.split(":")[1].strip()
|
254 |
estimatedDeliveryDate = line.split(":")[1].strip()
|
| Line 250... |
Line 263... |
| 250 |
bulk.find(findMap).update({'$set' : updateMap})
|
263 |
bulk.find(findMap).update({'$set' : updateMap})
|
| 251 |
bulk.find({'orderId': order['orderId']}).update({'$set':{'closed': closed}})
|
264 |
bulk.find({'orderId': order['orderId']}).update({'$set':{'closed': closed}})
|
| 252 |
result = bulk.execute()
|
265 |
result = bulk.execute()
|
| 253 |
pprint(result)
|
266 |
pprint(result)
|
| 254 |
|
267 |
|
| 255 |
"""
|
- |
|
| 256 |
This will insert records with changes only
|
- |
|
| 257 |
"""
|
- |
|
| 258 |
|
268 |
|
| 259 |
def _getActiveOrders(self):
|
269 |
def _isSubOrderActive(self,order, merchantSubOrderId):
|
| 260 |
collection = self.db.merchantOrder
|
270 |
subOrders = order.get("subOrders")
|
| 261 |
collectionMap = {"orderSuccessUrl":1, "orderId":1,"subOrders.merchantSubOrderId":1,"subOrders.closed":1}
|
271 |
for subOrder in subOrders:
|
| 262 |
stores = collection.find({"closed": False, "storeId" : self.store_id}, collectionMap)
|
272 |
if merchantSubOrderId == subOrder.get("merchantSubOrderId"):
|
| 263 |
return [store for store in stores]
|
273 |
return True
|
| - |
|
274 |
return False
|
| 264 |
|
275 |
|
| 265 |
|
276 |
|
| 266 |
|
277 |
|
| 267 |
def _saveToAffiliate(self, offers):
|
278 |
def _saveToAffiliate(self, offers):
|
| 268 |
collection = self.db.snapdealOrderAffiliateInfo
|
279 |
collection = self.db.snapdealOrderAffiliateInfo
|
| 269 |
try:
|
280 |
try:
|
| Line 330... |
Line 341... |
| 330 |
)
|
341 |
)
|
| 331 |
#Encode the parameters
|
342 |
#Encode the parameters
|
| 332 |
return urllib.urlencode(parameters)
|
343 |
return urllib.urlencode(parameters)
|
| 333 |
|
344 |
|
| 334 |
def main():
|
345 |
def main():
|
| - |
|
346 |
|
| 335 |
store = getStore(3)
|
347 |
store = getStore(3)
|
| 336 |
store.scrapeStoreOrders()
|
348 |
store._isSubOrderActive(8, "5970688907")
|
| 337 |
|
349 |
|
| 338 |
#store.parseOrderRawHtml(12345, "subtagId", 122323, "html", 'https://m.snapdeal.com/purchaseMobileComplete?code=1f4166d13ea799b65aa9dea68b3e9e70&order=4509499363')
|
350 |
#store.parseOrderRawHtml(12345, "subtagId", 122323, "html", 'https://m.snapdeal.com/purchaseMobileComplete?code=1f4166d13ea799b65aa9dea68b3e9e70&order=4509499363')
|
| 339 |
|
351 |
|
| 340 |
def ungzipResponse(r,b):
|
352 |
def ungzipResponse(r,b):
|
| 341 |
headers = r.info()
|
353 |
headers = r.info()
|