Subversion Repositories SmartDukaan

Rev

Rev 15766 | Blame | Compare with Previous | Last modification | View Log | RSS feed

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
from dtr.utils.utils import get_mongo_connection
import optparse

USER_NAME = "saholic-snapdeal@saholic.com"
PASSWORD = "snapsaholic2015"
VOI_USER_NAME = "spiceonlineretailvoi@gmail.com"
VOI_PASSWORD = "saholicsnapdeal2"

parser = optparse.OptionParser()
parser.add_option("-m", "--m", dest="mongoHost",
                      default="localhost",
                      type="string", help="The HOST where the mongo server is running",
                      metavar="mongo_host")

(options, args) = parser.parse_args()


def run():
    try:
        driver = webdriver.PhantomJS('/usr/local/bin/phantomjs')
        driver.set_window_size(1124, 850) # set browser size.
        driver.get("http://sellers.snapdeal.com")
        driver.maximize_window()
        element = driver.find_element_by_name("pgLogin:navbar:txtUserName")
        element.send_keys(USER_NAME)
        element = driver.find_element_by_name("pgLogin:navbar:txtPassword")
        element.send_keys(PASSWORD)
        
        element = driver.find_element_by_name("pgLogin:navbar:j_id12")
        element.click()
        time.sleep(20)
        driver.get("http://seller.snapdeal.com/inventory")
        cookies =  driver.get_cookies()
        print cookies
        try:
            for cookie in cookies:
                if cookie.get('name') == "SERVERID":
                    SERVERID = cookie.get('value')
                if cookie.get('name') == "sfJSESSIONID":
                    sfJSESSIONID = cookie.get('value')
            print SERVERID
            print sfJSESSIONID
            get_mongo_connection(host=options.mongoHost).Snapdeal.Cookies.update({"_id":1},{"$set":{"SERVERID":SERVERID,"sfJSESSIONID":sfJSESSIONID}},multi=False,upsert=True)
        except:
            pass
        driver.get("http://shipping.snapdeal.com/vendor/product-shipment/shippingDashboard")
        time.sleep(10)
        cookies =  driver.get_cookies()
        try:
            for cookie in cookies:
                if cookie.get('name') == "AWSELB":
                    AWSELB = cookie.get('value')
                if cookie.get('name') == "JSESSIONID":
                    JSESSIONID = cookie.get('value')
            print JSESSIONID
            print AWSELB
            get_mongo_connection(host=options.mongoHost).Snapdeal.Cookies.update({"_id":1},{"$set":{"JSESSIONID":JSESSIONID,"AWSELB":AWSELB}},multi=False,upsert=True)
        except:
            pass    
    finally:    
        driver.quit()
    
def voiCookies():
    try:
        driver = webdriver.PhantomJS('/usr/local/bin/phantomjs')
        driver.set_window_size(1124, 850) # set browser size.
        driver.get("http://sellers.snapdeal.com")
        driver.maximize_window()
        element = driver.find_element_by_name("pgLogin:navbar:txtUserName")
        element.send_keys(VOI_USER_NAME)
        element = driver.find_element_by_name("pgLogin:navbar:txtPassword")
        element.send_keys(VOI_PASSWORD)
        
        element = driver.find_element_by_name("pgLogin:navbar:j_id12")
        element.click()
        time.sleep(20)
        driver.get("http://seller.snapdeal.com/inventory")
        cookies =  driver.get_cookies()
        print cookies
        try:
            for cookie in cookies:
                if cookie.get('name') == "SERVERID":
                    SERVERID = cookie.get('value')
                if cookie.get('name') == "sfJSESSIONID":
                    sfJSESSIONID = cookie.get('value')
            print SERVERID
            print sfJSESSIONID
            get_mongo_connection(host=options.mongoHost).Snapdeal.VoiCookies.update({"_id":1},{"$set":{"SERVERID":SERVERID,"sfJSESSIONID":sfJSESSIONID}},multi=False,upsert=True)
        except:
            pass
    finally:    
        driver.quit()



if __name__=='__main__':
    run()
    voiCookies()