示例#1
0
def handle_postconnect_pre(cur, taskrow):
    print('taskrow:', taskrow)
    msgdetail = get_db(cur, message_select, (taskrow[8],))
    print('message detail:', msgdetail)
    # update runniing status
    cur.execute(bottask_update_status_sql, (bottask_status.RUNNING, taskrow[0]))
    return msgdetail
示例#2
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
示例#3
0
def postconnect_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)

    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)

        # pv-s-profile-actions--message
        # connect_btn = driver.find_element_by_class_name("button.pv-s-profile-actions--connect")
        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"""

        # add a note in popup
        addnote_css = """div#li-modal-container>div.modal-content-wrapper 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()

        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)

        # connect send in popup
        connect_css = """div#li-modal-container>div.modal-content-wrapper 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

    # check back id?

    driver.close()

    return status
示例#4
0
def update_contact_connected(cur, connected_date, msgdetail, message=None):
    cur.execute(contact_update_connect_sql, (connected_date, msgdetail[6]))
    contact = get_db(cur, contact_select, (msgdetail[6], ))
    cur.execute(delete_search_result_sql, (contact[10]))
    if message is not None:
        print('-------delete---search result------', contact[10])
        now = datetime.now()
        new_value = (now, now, message, replied_date,
                     bot_msgtype.TALKING_REPLIED_N, msgdetail[6], replied_date,
                     msgdetail[9], msgdetail[10], msgdetail[0], 0, 0, 0)
        print('msgdetail:', msgdetail)
        print(messages_replied_insert_query % new_value)
        cur.execute(messages_replied_insert_query, new_value)
        cur.execute(contact_update_status_connect_sql, (msgdetail[6]))
        print('connect is connected!')
示例#5
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)

    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)

        # pv-s-profile-actions--message
        # connect_btn = driver.find_element_by_class_name("button.pv-s-profile-actions--connect")
        message_btn = wait.until(EC.visibility_of_element_located(
            (By.CSS_SELECTOR, "button.pv-s-profile-actions--message")))

        message_btn_wrapper = wait.until(EC.visibility_of_element_located(
            (By.CSS_SELECTOR, message_btn)))

        pending_btn = wait.until(EC.visibility_of_element_located(
            (By.CSS_SELECTOR, "button.pv-s-profile-actions--pending")))

        pending_btn_wrapper = wait.until(EC.visibility_of_element_located(
            (By.CSS_SELECTOR, pending_btn)))

        inmail_btn = wait.until(EC.visibility_of_element_located(
            (By.CSS_SELECTOR, "button.pv-s-profile-actions--inmail")))

        inmail_btn_wrapper = wait.until(EC.visibility_of_element_located(
            (By.CSS_SELECTOR, inmail_btn)))

        if message_btn_wrapper is not None:
            connect = "connected"

        if pending_btn_wrapper is not None:
            connect = "pending"

        if inmail_btn_wrapper is not None:
            connect = "ignored"

            # 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')
            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)

                # get message
                m = re.search(r'<p class="msg-s-event-listitem__body[^"]*">([^<]+)</p>', html)
                if m:
                    message = m.group(1).strip()
                    print('message:', message)

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

    # check back id?

    driver.close()

    return status, replied_date, connect, message
示例#6
0
def get_fastcontact_ajax(driver, cur, owner_id, check_existed=False):

    driver.get(LINKEDIN_CONNECTIONS_URL)
    time.sleep(10)

    total_connection_counts = driver.find_element_by_tag_name("h2")
    counts_text = total_connection_counts.text
    counts = counts_text.split(" ")

    cnt_all_connections = counts[0].replace(',', '')
    csrf_tocken = get_browser_csrf_tocken(driver)
    #############################################################################################################################
    driver.execute_script("""
      var element = document.createElement('div');
      element.id = "interceptedResponse";
      element.appendChild(document.createTextNode(""));
      document.body.appendChild(element);

      var xhttp = new XMLHttpRequest();

      xhttp.onreadystatechange = function() {
        if (this.readyState == 4 && this.status == 200) {
          document.getElementById("interceptedResponse").innerHTML = this.responseText;
        }
      };
      xhttp.open("GET", "https://www.linkedin.com/voyager/api/relationships/connections?count="""
                          + cnt_all_connections +
                          """&sortType=RECENTLY_ADDED&start=0", true);
      xhttp.setRequestHeader('Csrf-Token', """ + csrf_tocken + """)
      xhttp.send();""")
    #############################################################################################################################
    time.sleep(3)
    responsedata = driver.find_element_by_id('interceptedResponse').text
    #print('responsedata :', responsedata)
    targetjsondata = json.loads(responsedata)
    print('----------------targetjsondata------------------> :',
          targetjsondata)
    time.sleep(100)
    targetjsondata = targetjsondata['elements']
    for itemdata in targetjsondata:
        firstName = itemdata['miniProfile']['firstName']
        lastName = itemdata['miniProfile']['lastName']
        occupation = itemdata['miniProfile']['occupation']
        publicIdentifier = itemdata['miniProfile']['publicIdentifier']
        createdAt = itemdata['createdAt']
        createdAtTime = datetime.fromtimestamp(int(str(createdAt)[0:10]))
        actor_title = ""
        actor_company = ""
        if " at " in occupation:
            title_company = occupation.split(" at ")
            actor_title = title_company[0]
            actor_company = title_company[1]
        else:
            actor_company = ""
            actor_title = occupation
        actor_title = get_contact_title(actor_title)
        values = (
            actor_company,
            "",
            "",
            actor_title,
            publicIdentifier,
            firstName + ' ' + lastName,
        )
        values = values + \
            (createdAtTime, str(botstatus.OLD_CONNECT_N),
             '1', createdAtTime, str(owner_id),)

        if check_existed:
            contact_row = bot_db.get_db(cur, inbox_check_id_query, (
                publicIdentifier,
                owner_id,
            ))
            if contact_row is not None:
                continue

        if cur is not None:
            bot_db.add_to_db2(cur, getcontacts_query, *values)

            if check_existed:
                contact_row = bot_db.get_db(cur, inbox_check_id_query, (
                    publicIdentifier,
                    owner_id,
                ))
                update_contact(driver, cur, publicIdentifier, csrf_tocken,
                               contact_row[0])

    print(' Number of connections : ', len(targetjsondata))
示例#7
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