Subversion Repositories SmartDukaan

Rev

Rev 16203 | Rev 16227 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 16203 Rev 16226
Line 338... Line 338...
338
                    orderObj = json.loads(script.text.strip().split('\n')[0].split('orderConfirmation = ')[1].split(';')[0])
338
                    orderObj = json.loads(script.text.strip().split('\n')[0].split('orderConfirmation = ')[1].split(';')[0])
339
                    if merchantOrderId is None:
339
                    if merchantOrderId is None:
340
                        merchantOrderId = orderObj['0']['order_id']
340
                        merchantOrderId = orderObj['0']['order_id']
341
                        emailId = orderObj['0']['email']
341
                        emailId = orderObj['0']['email']
342
            if orderObj is None or merchantOrderId is None:
342
            if orderObj is None or merchantOrderId is None:
-
 
343
                orderIdDiv = rawHtmlSoup.body.find("div", {'class':'conf_succes'})
-
 
344
                if orderIdDiv is None:
-
 
345
                    orderIdArt = rawHtmlSoup.body.find("article", {'class':'white'})
-
 
346
                    if orderIdArt is None:
343
                resp['result'] = 'ORDER_NON_PARSEABLE'
347
                        resp['result'] = 'ORDER_NOT_CREATED_UNKNOWN'
344
                return resp
348
                        return resp
-
 
349
                    else:
-
 
350
                        orderIdDiv= orderIdArt.find('p', recursive=False)
-
 
351
                        orderIdVal = str(orderIdDiv.text.split(' : ')[1])
-
 
352
                        print "Opening Shopclues Login Page"
-
 
353
                        login_url = "https://sm.shopclues.com/login"
-
 
354
                        br1 = login(login_url)
-
 
355
                        orderDetailPage = br1.open("https://sm.shopclues.com/orderconfirmation?order_id="+orderIdVal+"&status=P")
-
 
356
                        orderDetailPage = ungzipResponse(orderDetailPage)
-
 
357
                        rawHtmlSoup = BeautifulSoup(orderDetailPage)
-
 
358
                        for script in rawHtmlSoup.find_all('script'):
-
 
359
                            if 'orderConfirmation' in script.text:
-
 
360
                                orderObj = json.loads(script.text.strip().split('\n')[0].split('orderConfirmation = ')[1].split(';')[0])
-
 
361
                                if merchantOrderId is None:
-
 
362
                                    merchantOrderId = orderObj['0']['order_id']
-
 
363
                                    emailId = orderObj['0']['email']
-
 
364
                        logoutpage = br1.open("https://sm.shopclues.com/logout")
-
 
365
                        print br1.geturl()
-
 
366
                else:
-
 
367
                    orderIdDiv= orderIdDiv.find('div', recursive=False)
-
 
368
                    orderIdVal = str(orderIdDiv.span.text)
-
 
369
                    print "Opening Shopclues Login Page"
-
 
370
                    login_url = "https://sm.shopclues.com/login"
-
 
371
                    br1 = login(login_url)
-
 
372
                    orderDetailPage = br1.open("https://sm.shopclues.com/orderconfirmation?order_id="+orderIdVal+"&status=P")
-
 
373
                    orderDetailPage = ungzipResponse(orderDetailPage)
-
 
374
                    rawHtmlSoup = BeautifulSoup(orderDetailPage)
-
 
375
                    for script in rawHtmlSoup.find_all('script'):
-
 
376
                        if 'orderConfirmation' in script.text:
-
 
377
                            orderObj = json.loads(script.text.strip().split('\n')[0].split('orderConfirmation = ')[1].split(';')[0])
-
 
378
                            if merchantOrderId is None:
-
 
379
                                merchantOrderId = orderObj['0']['order_id']
-
 
380
                                emailId = orderObj['0']['email']
-
 
381
                    logoutpage = br1.open("https://sm.shopclues.com/logout")
-
 
382
                    print br1.geturl()
-
 
383
                    
345
            br = getBrowserObject()
384
            br = getBrowserObject()
346
            url = ORDER_TRACK_URL +'&order_id=' +str(merchantOrderId)+'&email_id='+ emailId
385
            url = ORDER_TRACK_URL +'&order_id=' +str(merchantOrderId)+'&email_id='+ emailId
347
            page = br.open(url)
386
            page = br.open(url)
348
            headers = str(page.info()).split('\n')
387
            headers = str(page.info()).split('\n')
349
            page = ungzipResponse(page)
388
            page = ungzipResponse(page)
Line 529... Line 568...
529
                                    closed = False
568
                                    closed = False
530
                            except:
569
                            except:
531
                                pass
570
                                pass
532
                            continue
571
                            continue
533
                        elif subOrder['closed']:
572
                        elif subOrder['closed']:
-
 
573
                            count = count+1
534
                            continue
574
                            continue
535
                        else:
575
                        else:
536
                            findMap = {"orderId": order['orderId'], "subOrders.merchantSubOrderId": str(subOrderId)+'-'+str(count)}
576
                            findMap = {"orderId": order['orderId'], "subOrders.merchantSubOrderId": str(subOrderId)+'-'+str(count)}
537
                            updateMap = {}
577
                            updateMap = {}
538
                            updateMap["subOrders.$.detailedStatus"] = orderStatus
578
                            updateMap["subOrders.$.detailedStatus"] = orderStatus
Line 649... Line 689...
649
            if not callable(value) and not key.startswith('_')])
689
            if not callable(value) and not key.startswith('_')])
650
        if classkey is not None and hasattr(obj, "__class__"):
690
        if classkey is not None and hasattr(obj, "__class__"):
651
            data[classkey] = obj.__class__.__name__
691
            data[classkey] = obj.__class__.__name__
652
        return data
692
        return data
653
    else:
693
    else:
654
        return obj    
694
        return obj
-
 
695
    
-
 
696
def login(url):
-
 
697
    br = getBrowserObject()
-
 
698
    br.open(url)
-
 
699
    response = br.open(url)
-
 
700
    ungzipResponseBr(response, br)
-
 
701
    #html = response.read()
-
 
702
    #print html
-
 
703
    br.select_form(nr=0)
-
 
704
    br.form['user'] = "imanthetester@gmail.com"
-
 
705
    br.form['password'] = "$Dl8uk"
-
 
706
    response = br.submit()
-
 
707
    print "********************"
-
 
708
    print "Attempting to Login"
-
 
709
    print "********************"
-
 
710
    #ungzipResponse(response, br)
-
 
711
    return br
-
 
712
 
-
 
713
def ungzipResponseBr(r,b):
-
 
714
    headers = r.info()
-
 
715
    if headers['Content-Encoding']=='gzip':
-
 
716
        import gzip
-
 
717
        print "********************"
-
 
718
        print "Deflating gzip response"
-
 
719
        print "********************"
-
 
720
        gz = gzip.GzipFile(fileobj=r, mode='rb')
-
 
721
        html = gz.read()
-
 
722
        gz.close()
-
 
723
        headers["Content-type"] = "text/html; charset=utf-8"
-
 
724
        r.set_data( html )
-
 
725
        b.set_response(r)    
655
 
726
 
656
    
727
    
657
728