def test_get_for_email(self): response = get_contacts( self.auth_token, **{'contact_email': '*****@*****.**'}) obj = json.loads(response) contacts = obj['FindContactResponse']['FindContactResponseDetail'][ 'FindCandidate'] print contacts self.assertEqual(1, len(contacts))
def test_get(self): response = get_contacts( self.auth_token, **{ 'company_search_term': 'Dell', 'contacts_search_term': 'Michael Dell' }) print response self.assertTrue(response)
def test_extract_job_title_from_contact(self): response = get_contacts( self.auth_token, **{'contact_email': '*****@*****.**'}) obj = json.loads(response) contacts = obj['FindContactResponse']['FindContactResponseDetail'][ 'FindCandidate'] contact = contacts[0] self.assertEqual("Information Technology Manager", extract_job_title_from_contact(contact))
def test_extract_management_responsibility_code(self): response = get_contacts( self.auth_token, **{ 'contact_email': '*****@*****.**', 'duns': '607009755' }) obj = json.loads(response) contacts = obj['FindContactResponse']['FindContactResponseDetail'][ 'FindCandidate'] contact = contacts[0] self.assertEqual("Manager", extract_management_responsibility_code(contact))
def test_get_for_duns(self): response = get_contacts( self.auth_token, **{ 'contact_search_term': 'Angie Harper', 'duns': '186830733' }) obj = json.loads(response) contacts = obj['FindContactResponse']['FindContactResponseDetail'][ 'FindCandidate'] print contacts self.assertTrue(response)
writer.writeheader() i = 1 contact_matches = 0 for row in reader: #if i == 10: # break full_name = ' '.join([row['First Name'], row['Last Name']]).strip() query = {'contact_email' : row['email'], 'contact_search_term' : full_name, 'company_search_term' : row['orgname'], 'duns' : row['siteLevelDUNS']} auth_token = get_auth_token("*****@*****.**", "dnbdirect123") try: response = get_contacts(auth_token, **query) contacts = extract_contacts_from_response(response) if (len(contacts) == 1): contact_matches += 1 manager_code = extract_management_responsibility_code(contacts[0]) job_title = extract_job_title_from_contact(contacts[0]) # Augment with additional data points row['Job Title'] = job_title row['Management Responsibility'] = manager_code logging.debug("Extracted job title & management responsibility for contact on line %d" % i) except: logging.debug("Problem getting contacts for line %d (%s, %s)" % (i, full_name, row['email'])) logging.debug(query) writer.writerow(row) i += 1
import csv from dnbdirect.rest.contacts import get_contacts from dnbdirect.rest.auth import get_auth # Get fields from contacts_whitespace.csv with open("contacts_whitespace.csv", "r") as input_file: reader = csv.DictReader(input_file) with open("contacts_job_summary.csv", "w") as output_file: for row in reader: if row.get('siteLevelDUNS').strip() == '\N': print "No duns for " + row.get("orgname") continue auth_token = get_auth('*****@*****.**', 'dnbdirect123') # Get contacts query = {'company_search_term' : row['orgname']} contacts = get_contacts(auth_token, **query)