def upload_company(name, domain, email_format=None): ''' uploads a company to hubspot :param name: name of company :param domain: domain of company :param email_format: email format for company :return: status ''' url = '{}/companies/v2/companies/?hapikey={}'.format( BASE_URL, HUBSPOT_API_KEY) headers = {"content-type": "application/json"} data = { "properties": [{ "name": "name", "value": name }, { "name": "domain", "value": domain }, { "name": "format", "value": email_format }] } data_dump = dumps(data) return post_json(url, data_dump, headers)
def company_domain_search(domain): ''' searches hubspot companies for a domain :param domain: domain to search for :return: retuns the domain data ''' headers = {"content-type": "application/json"} post_data = { "limit": 2, "requestOptions": { "properties": ["domain", "createdate", "name", "hs_lastmodifieddate"] }, "offset": { "isPrimary": True, "companyId": 0 } } dump_data = dumps(post_data) url = '{}/companies/v2/domains/{}/companies?hapikey={}'.format( BASE_URL, domain, HUBSPOT_API_KEY) r = post_json(url, dump_data, headers) if 'error' in r: return None if r['results'] == []: return None return r
def post_lead(lead): ''' posts a lead to the kindling DB :param lead: lead to add to the DB :return lead: the lead object created in the DB on success ''' url = KINDLING_URL + 'lead/' + KINDLING_API_KEY res = post_json(url, post=lead) print(res) return res
def post_user(user): ''' posts a users information to the database :param user: contact info in dictionary :return contact: on success the server returns the contact object created ''' url = KINDLING_URL + 'user/' + KINDLING_API_KEY res = post_json(url, post=user) print(res) return res
def post_domain(domain): ''' posts a new domains information to the DB :param domain: the domain to post to the DB :return domain: returns the domain object in the DB on success ''' url = KINDLING_URL + 'domain/' + KINDLING_API_KEY res = post_json(url, post=domain) print(res) return res
def post_format(email_format): ''' posts email format to kindling DB :param email_format: email format to post to DB :return format: returns the object created in the DB if successful ''' url = KINDLING_URL + 'format/' + KINDLING_API_KEY res = post_json(url, post=email_format) print(res) return res
def lead_csv_to_db(csv_name): ''' Imports lead info to the DB :param csv_name: the name of the csv to import :return status: status of how the import went ''' list_data = csv_to_list(csv_name) while list_data: contact = list_data.pop() email_format = get_email_format(contact[0], contact[1], contact[6]) if email_format: format_res = post_json('https://agile-beyond-80033.herokuapp.com/format/' + KINDLING_API_KEY, post={ "company": contact[2], "domain": contact[4], "format": email_format }) print('Uploaded Format:') print(format_res) sleep(0.4) lead = { "first": contact[0], "last": contact[1], "company": contact[2], "title": contact[3], "domain": contact[4], "location": contact[5], "email": contact[6] } lead_res = post_json('https://agile-beyond-80033.herokuapp.com/lead/' + KINDLING_API_KEY, post=lead) print('\nUploaded Lead:') print(lead_res) print() sleep(0.4) return 'success'
def tech_lookup(url, keys): ''' Used to call tech lookup API :param url: the domain to check for the technology :param keys: the piece of code to look for in the page source - array :return: bool - if the code exists in the page ''' check_url = 'https://tech-lookup.herokuapp.com/techSearch' headers = {"content-type": "application/json"} found = False try: data = {"url": url, "keys": keys} print('res sent') res = post_json(check_url, post=dumps(data), headers=headers) print(res) if res and res['result']: found = True except Exception: print('something went wrong calling page') return found