def _f_process(self):
        authentication_key = APIKey("API KEY")
        connection = PortalConnection(authentication_key, "Forduplicates")
        df1 = pd.DataFrame([
            contact.email_address for contact in get_all_contacts(connection)
        ])
        df2 = pd.DataFrame(
            [contact.properties for contact in get_all_contacts(connection)])
        df3 = pd.concat([df1, df2], axis=1)

        # cleanse dataframe
        df3.drop(['company', 'lastmodifieddate'], axis=1, inplace=True)
        df4 = df3.dropna(subset=['firstname', 'lastname'], axis=0)
        df4 = df4.apply(lambda x: x.str.lower())

        # find duplicates
        df5 = df4[df4.duplicated(subset=['firstname', 'lastname'], keep=False)]
        df6 = df5.sort_values(by=['firstname', 'lastname'])
        df6.reset_index(drop=True, inplace=True)
        contact_list = df6.values.tolist()
        count_row = df6.shape[0]

        self.text.SetLabel("        Total " + str(count_row) +
                           " contacts are duplicated!")

        # fill list
        for i in contact_list:
            index = self.list.InsertItem(sys.maxint, i[0])
            self.list.SetItem(index, 1, i[1])
            self.list.SetItem(index, 2, i[2])
Esempio n. 2
0
 def save_contact_to_hub(self):
     """
     Calls hubspot api and created a contact (if not exists) and saves it to 
     the HubSpot Account registered 
     """
     try:
         self.logger.debug('Inside save_contact_to_hub() function')
         self.vid = self.phone_number
         self.logger.debug("Saving contact to hub {}{}{}{}{}".format(self.vid,self.first_name,\
         self.last_name,self.email,self.phone_number))
         with PortalConnection(self.authentication_key,
                               self.app_name) as connection:
             for contact in get_all_contacts(connection,
                                             property_names=('phone', )):
                 if 'unassigned' in contact.email_address and \
                 'unassigned' in self.email:
                     raise Exception('Contact {} already saved in hubspot'.\
                     format(self.phone_number))
             contact = []
             contact.append(Contact(vid=self.vid, email_address=self.email, \
             properties={u'lastname':self.last_name, u'firstname': \
             self.first_name,u'phone':str(self.phone_number),u'channelid':str(self.channel_id)},))
             save_contacts(contact, connection)
     except Exception as e:
         self.logger.exception("Error saving contact to Hubspot. {}".format(
             e.message))
Esempio n. 3
0
def _update_random_contact(connection):
    all_contacts = get_all_contacts(connection)
    first_contact = next(all_contacts)

    del first_contact.properties['lastmodifieddate']
    first_contact.properties['lastname'] = 'First User'

    return save_contacts([first_contact], connection)
def test_save_contacts():
    with _get_portal_connection() as connection:
        all_contacts = get_all_contacts(connection)
        first_contact = next(all_contacts)

        del first_contact.properties['lastmodifieddate']

        result = save_contacts([first_contact], connection)
        assert_is_none(result)
def test_save_contacts():
    with _get_portal_connection() as connection:
        all_contacts = get_all_contacts(connection)
        first_contact = next(all_contacts)

        del first_contact.properties['lastmodifieddate']

        result = save_contacts([first_contact], connection)
        assert_is_none(result)
def test_getting_all_contacts():
    with _get_portal_connection() as connection:
        all_contacts = get_all_contacts(connection)
        first_contact = next(all_contacts)
        assert_in('lastmodifieddate', first_contact.properties)

        requested_property_names = ('email',)
        all_contacts = get_all_contacts(
            connection,
            property_names=requested_property_names,
            )
        first_contact = next(all_contacts)

        expected_property_names = \
            ('lastmodifieddate',) + requested_property_names
        assert_items_equal(
            expected_property_names,
            first_contact.properties.keys(),
            )
Esempio n. 7
0
def test_getting_all_contacts():
    with _get_portal_connection() as connection:
        all_contacts = get_all_contacts(connection)
        first_contact = next(all_contacts)
        assert_in('lastmodifieddate', first_contact.properties)

        requested_property_names = ('email',)
        all_contacts = get_all_contacts(
            connection,
            property_names=requested_property_names,
        )
        first_contact = next(all_contacts)

        expected_property_names = \
            ('lastmodifieddate',) + requested_property_names
        assert_items_equal(
            expected_property_names,
            first_contact.properties.keys(),
        )
def test_static_lists():
    with _get_portal_connection() as connection:
        new_contact_list_name = 'contactlisttest'
        created_static_list = \
            create_static_contact_list(new_contact_list_name, connection)
        eq_(new_contact_list_name, created_static_list.name)

        all_contact_lists = get_all_contact_lists(connection)
        assert_in(created_static_list, all_contact_lists)

        all_contacts = get_all_contacts(connection)
        first_contact = next(all_contacts)
        added_contact_vids = add_contacts_to_list(
            created_static_list,
            [first_contact],
            connection,
            )
        assert_in(first_contact.vid, added_contact_vids)

        contacts_in_list = list(
            get_all_contacts_from_list(connection, created_static_list)
            )
        assert_in(first_contact, contacts_in_list)

        removed_contact_vids = remove_contacts_from_list(
            created_static_list,
            [first_contact],
            connection,
            )
        assert_in(first_contact.vid, removed_contact_vids)

        contacts_in_list = list(
            get_all_contacts_from_list(connection, created_static_list)
            )
        assert_not_in(first_contact, contacts_in_list)

        delete_contact_list(created_static_list.id, connection)

        all_contact_lists = get_all_contact_lists(connection)
        assert_not_in(created_static_list, all_contact_lists)
Esempio n. 9
0
def test_static_lists():
    with _get_portal_connection() as connection:
        new_contact_list_name = 'contactlisttest'
        created_static_list = \
            create_static_contact_list(new_contact_list_name, connection)
        eq_(new_contact_list_name, created_static_list.name)

        all_contact_lists = get_all_contact_lists(connection)
        assert_in(created_static_list, all_contact_lists)

        all_contacts = get_all_contacts(connection)
        first_contact = next(all_contacts)
        added_contact_vids = add_contacts_to_list(
            created_static_list,
            [first_contact],
            connection,
        )
        assert_in(first_contact.vid, added_contact_vids)

        contacts_in_list = list(
            get_all_contacts_from_list(connection, created_static_list)
        )
        assert_in(first_contact, contacts_in_list)

        removed_contact_vids = remove_contacts_from_list(
            created_static_list,
            [first_contact],
            connection,
        )
        assert_in(first_contact.vid, removed_contact_vids)

        contacts_in_list = list(
            get_all_contacts_from_list(connection, created_static_list)
        )
        assert_not_in(first_contact, contacts_in_list)

        delete_contact_list(created_static_list.id, connection)

        all_contact_lists = get_all_contact_lists(connection)
        assert_not_in(created_static_list, all_contact_lists)