Exemple #1
0
def postmessage_browser(cur, taskrow, msgdetail):
    email, password = get_user_email_pw(cur, taskrow[6])
    contact = get_db(cur, contact_select, (msgdetail[6], ))
    print('contact:', contact)
    # driver = login_linkedin_withwebdriver(email, password)
    driver = get_driver(email, password)
    # go to the user homme
    userhome = "{0}/in/{1}/".format(LINKEDIN_URL, contact[10])
    print('userhome:', userhome)
    status = True
    # click on the send message
    try:
        wait = WebDriverWait(driver, IDLE_INTERVAL_IN_SECONDS)
        driver.get(userhome)
        # pv-s-profile-actions--message
        #message_btn = driver.find_element_by_class_name("pv-s-profile-actions--message")
        message_btn = wait.until(EC.visibility_of_element_located(
            (By.CSS_SELECTOR, "button.pv-s-profile-actions--message")))
        message_btn.click()
        # post the text in the right box
        box_css = """div.application-outlet>aside.msg-overlay-container div.msg-overlay-conversation-bubble div.msg-overlay-conversation-bubble__content-wrapper form.msg-form """
        #  textarea.ember-text-area msg-form__textarea"
        form_box = wait.until(EC.visibility_of_element_located(
            (By.CSS_SELECTOR, box_css)))
        script = "window.scrollBy({x},{y});".format(x=form_box.location.get('x', 0),
                                                    y=form_box.location.get('y', 1000))
        print('script:', script)
        driver.execute_script(script)
        #print('get_attribute:', form_box.get_attribute('innerHTML'))
        text_box_css = "{0} {1}".format(
            box_css, "div.msg-form__compose-area>textarea[name='message']")
        print('text_box_css:', text_box_css)
        message_box = wait.until(EC.visibility_of_element_located(
                (By.CSS_SELECTOR, text_box_css)))
        message_box.send_keys(msgdetail[3])
        message_box.send_keys(Keys.RETURN)
        time.sleep(IDLE_INTERVAL_IN_SECONDS)
        # send
        button_css = "{0} {1}".format(
            box_css, "footer button.msg-form__send-button")
        try:
            send_btn = wait.until(EC.visibility_of_element_located(
                (By.CSS_SELECTOR, button_css)))
            send_btn.click()
        except Exception as e:
            print('------->', e)
        print('---->click end message<------')
        message_time = get_send_message_date(driver)
        if message_time is not None:
            try:
                cur.execute(message_time_update_sql, (message_time, msgdetail[0]))
            except Exception as e:
                print('----->', e)
        time.sleep(IDLE_INTERVAL_IN_SECONDS)
    except Exception as err:
        print('send message error:', err)
        status = False
    # check back id?
    driver.close()
    return status
Exemple #2
0
def checkmessage_browser(cur, taskrow, msgdetail):
    email, password = get_user_email_pw(cur, taskrow[6])
    try:
        contact = get_db(cur, contact_select, (msgdetail[6], ))
    except Exception as e:
        print('----->', e)
        return
    print('contact:', contact)
    # driver = login_linkedin_withwebdriver(email, password)
    driver = get_driver(email, password)
    user_path = "/in/{0}/".format(contact[10])
    # go to the user homme
    userhome = "{0}{1}".format(LINKEDIN_URL, user_path)
    print('userhome:', userhome)
    status = True
    replied_date = None
    message = ""
    # click on the send message
    try:
        wait = WebDriverWait(driver, IDLE_INTERVAL_IN_SECONDS)
        driver.get(userhome)
        # pv-s-profile-actions--message
        #message_btn = driver.find_element_by_class_name("pv-s-profile-actions--message")
        message_btn = wait.until(EC.visibility_of_element_located(
            (By.CSS_SELECTOR, "button.pv-s-profile-actions--message")))
        message_btn.click()
        # post the text in the right box
        box_css = """div.application-outlet>aside.msg-overlay-container div.msg-overlay-conversation-bubble div.msg-overlay-conversation-bubble__content-wrapper div.msg-s-message-list-container """
        #  textarea.ember-text-area msg-form__textarea"
        msg_box = wait.until(EC.visibility_of_element_located(
            (By.CSS_SELECTOR, box_css)))
        script = "window.scrollBy({x},{y});".format(x=msg_box.location.get('x', 0),
                                                    y=msg_box.location.get('y', 1000))
        print('script:', script)
        driver.execute_script(script)
        # print('get_attribute:', msg_box.get_attribute('innerHTML'))
        msg_list_css = "{0} {1}".format(box_css, "ul.msg-s-message-list>li")
        print('msg_list_css:', msg_list_css)
        message_list = driver.find_elements_by_css_selector(msg_list_css)
        html = message_list[-1].get_attribute('innerHTML')
        if user_path in html:
            # found replied
            replied_date = datetime.now()
            m = re.search(r'([\d]+):([\d]+)\s+([AP]M)', html)
            print('time:', m)

            if m:
                hr = int(m.group(1))
                mi = int(m.group(2))
                if m.group(3) == "PM":
                    hr += 12
                d = replied_date.day
                if hr < replied_date.hour:
                    d = d - 1

                replied_date = replied_date.replace(minute=mi, hour=hr,
                                                    day=d)
                print('replied_date:', replied_date)
            # get message
            try:
                m = message_list[-1].find_element_by_css_selector('p.msg-s-event-listitem__body').text
            except Exception as e:
                print('error ----->', e)
                pass
            if m:
                message = m.strip()
                print('message:', message)
    except Exception as err:
        print('send message error:', err)
        status = False
    # check back id?
    driver.close()
    return status, replied_date, message
Exemple #3
0
def postconnect_browser(cur, taskrow, msgdetail):
    print('------------postconnect_browser-------------')
    email, password = get_user_email_pw(cur, taskrow[6])
    contact = get_db(cur, contact_select, (msgdetail[6], ))
    print('contact:', contact)
    # driver = login_linkedin_withwebdriver(email, password)
    driver = get_driver(email, password)

    user_path = "/in/{0}/".format(contact[10])
    # go to the user homme
    userhome = "{0}{1}".format(LINKEDIN_URL, user_path)
    print('userhome:', userhome)
    status = True
    replied_date = None
    message = ""
    # click on the send connect
    try:
        wait = WebDriverWait(driver, IDLE_INTERVAL_IN_SECONDS)
        driver.get(userhome)
        print('-----------finding--------pass_connect_btn----------------')
        try:
            connect_btn = wait.until(
                EC.visibility_of_element_located(
                    (By.CSS_SELECTOR, "button.pv-s-profile-actions--connect")))
        except Exception as e:
            more_button_btn = wait.until(
                EC.visibility_of_element_located(
                    (By.CSS_SELECTOR,
                     "button.pv-s-profile-actions__overflow-toggle")))
            more_button_btn.click()
            connect_btn = wait.until(
                EC.visibility_of_element_located(
                    (By.CSS_SELECTOR, "button.pv-s-profile-actions--connect")))
        connect_btn.click()

        # post the text in the popup
        box_css = """div#li-modal-container>div.modal-content-wrapper"""
        print('-------------------pass_connect_btn----------------')

        # add a note in popup
        addnote_css = """div.send-invite__actions>button.button-secondary-large"""
        btn_addnote = wait.until(
            EC.visibility_of_element_located((By.CSS_SELECTOR, addnote_css)))
        btn_addnote.click()
        print('-------------------btn_addnote----------------')

        # text_box_css = "{0} {1}".format(box_css, "div.msg-form__compose-area>textarea[name='message']")
        text_box_css = "textarea#custom-message"
        print('text_box_css:', text_box_css)
        message_box = wait.until(
            EC.visibility_of_element_located((By.CSS_SELECTOR, text_box_css)))
        message_box.send_keys(msgdetail[3])
        print('-------------------message_box----------------', msgdetail[3])

        message_box.send_keys(Keys.RETURN)
        time.sleep(IDLE_INTERVAL_IN_SECONDS)

        # connect send in popup
        connect_css = "div.send-invite__actions>button.button-primary-large"
        btn_send = wait.until(
            EC.visibility_of_element_located((By.CSS_SELECTOR, connect_css)))

        btn_send.click()

        time.sleep(IDLE_INTERVAL_IN_SECONDS)

    except Exception as err:
        print('send connect error:', err)
        status = False
    driver.close()
    return status
Exemple #4
0
def checkconnect_browser(cur, taskrow, msgdetail):
    email, password = get_user_email_pw(cur, taskrow[6])
    contact = get_db(cur, contact_select, (msgdetail[6], ))
    print('contact:', contact)
    # driver = login_linkedin_withwebdriver(email, password)
    driver = get_driver(email, password)
    user_path = "/in/{0}/".format(contact[10])
    # go to the user homme
    userhome = "{0}{1}".format(LINKEDIN_URL, user_path)
    print('userhome:', userhome)
    status = True
    replied_date = datetime.now()
    connect = ""
    message = None
    # click on the send connect
    try:
        wait = WebDriverWait(driver, IDLE_INTERVAL_IN_SECONDS)
        driver.get(userhome)
        message_btn = None
        pending_btn = None
        inmail_btn = None
        try:
            pending_btn = wait.until(
                EC.visibility_of_element_located(
                    (By.CSS_SELECTOR, "button.pv-s-profile-actions--pending")))
        except Exception as e:
            print('---no pending---', e)
            try:
                inmail_btn = wait.until(
                    EC.visibility_of_element_located(
                        (By.CSS_SELECTOR,
                         "button.pv-s-profile-actions--send-in-mail")))
            except Exception as e:
                print('---no ignored---', e)
                try:
                    message_btn = wait.until(
                        EC.visibility_of_element_located(
                            (By.CSS_SELECTOR,
                             "button.pv-s-profile-actions--message")))
                except Exception as e:
                    print('---no connected---', e)

        if inmail_btn is not None:
            connect = "ignored"

        if pending_btn is not None:
            connect = "pending"

        if message_btn is not None or inmail_btn is not None:
            if message_btn is not None:
                connect = "connected"
                find_contact_on_message_box(driver, contact)
                # open_msg_box_btn = "button.msg-overlay-bubble-header__control--new-convo-btn"
                # open_msg_box = wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, open_msg_box_btn)))
                # message_btn.click()
            if inmail_btn is not None:
                find_contact_on_message_box(driver, contact)
            box_css = """div.application-outlet>aside.msg-overlay-container div.msg-overlay-conversation-bubble div.msg-overlay-conversation-bubble__content-wrapper div.msg-s-message-list-container"""
            try:
                msg_box = wait.until(
                    EC.visibility_of_element_located(
                        (By.CSS_SELECTOR, box_css)))
            except Exception as e:
                print('error:->', e)
            script = "window.scrollBy({x},{y});".format(
                x=msg_box.location.get('x', 0),
                y=msg_box.location.get('y', 1000))
            print('script:', script)
            driver.execute_script(script)
            msg_list_css = "{0} {1}".format(box_css,
                                            "ul.msg-s-message-list>li")
            # print('msg_list_css:', msg_list_css)
            message_list = driver.find_elements_by_css_selector(msg_list_css)
            html = message_list[-1].get_attribute('innerHTML')
            # print('message_list:', html)
            if user_path in html:
                # found replied
                replied_date = datetime.now()
                m = re.search(r'([\d]+):([\d]+)\s+([AP]M)', html)
                print('time:', m)

                if m:
                    hr = int(m.group(1))
                    mi = int(m.group(2))
                    if m.group(3) == "PM":
                        hr += 12
                    d = replied_date.day
                    if hr < replied_date.hour:
                        d = d - 1
                    replied_date = replied_date.replace(minute=mi,
                                                        hour=hr,
                                                        day=d)
                    print('replied_date:', replied_date)
                try:
                    m = message_list[-1].find_element_by_css_selector(
                        'p.msg-s-event-listitem__body').text
                except Exception as e:
                    print(e)
                    pass
                if m:
                    message = m.strip()
                    print('message:', message)

    except Exception as err:
        print('check connect error:', err)
        status = False

    driver.close()
    return status, replied_date, connect, message