Update followers from linkedin
Tags: #hubspot #crm #sales #contact #naas_drivers #linkedin #network #scheduler #naas
Author: Florent Ravenel

Input

Import library

1
from naas_drivers import hubspot, linkedin
2
import naas
3
import pandas as pd
Copied!

Setup your HubSpot

👉 Access your HubSpot API key
1
HS_API_KEY = 'YOUR_HUBSPOT_API_KEY'
Copied!

Setup your LinkedIn

👉 Get your cookies
1
LI_AT = 'YOUR_COOKIE_LI_AT' # EXAMPLE AQFAzQN_PLPR4wAAAXc-FCKmgiMit5FLdY1af3-2
2
JSESSIONID = 'YOUR_COOKIE_JSESSIONID' # EXAMPLE ajax:8379907400220387585
Copied!

Schedule your notebook everyday

1
#-> Uncomment the 2 lines below (by removing the hashtag) to schedule your job everyday at 8:00 AM (NB: you can choose the time of your scheduling bot)
2
# import naas
3
# naas.scheduler.add(cron="0 8 * * *")
4
5
#-> Uncomment the line below (by removing the hashtag) to remove your scheduler
6
# naas.scheduler.delete()
Copied!

Model

Get all contacts in HubSpot

1
properties_list = [
2
"hs_object_id",
3
"firstname",
4
"lastname",
5
"linkedinbio",
6
"linkedinconnections",
7
]
8
hubspot_contacts = hubspot.connect(HS_API_KEY).contacts.get_all(properties_list)
9
hubspot_contacts
Copied!

Filter to get linkedinconnections = "Not Defined" and "linkedinbio" = defined

1
df_to_update = hubspot_contacts.copy()
2
3
# Cleaning
4
df_to_update = df_to_update.fillna("Not Defined")
5
6
# Filter on "Not defined"
7
df_to_update = df_to_update[(df_to_update.linkedinbio != "Not Defined") &
8
(df_to_update.linkedinconnections == "Not Defined")]
9
10
# Limit to last 50 contacts
11
df_to_update = df_to_update.sort_values(by="createdate", ascending=False)[:50].reset_index(drop=True)
12
13
df_to_update
Copied!

Get followers from Linkedin

1
for _, row in df_to_update.iterrows():
2
linkedinbio = row.linkedinbio
3
4
# Get followers
5
df = linkedin.connect(LI_AT, JSESSIONID).profile.get_network(linkedinbio)
6
linkedinconnections = df.loc[0, "FOLLOWERS_COUNT"]
7
8
# Get linkedinbio
9
df_to_update.loc[_, "linkedinconnections"] = linkedinconnections
10
11
df_to_update
Copied!

Output

Update followers in Hubspot

1
for _, row in df_to_update.iterrows():
2
# Init data
3
data = {}
4
5
# Get data
6
hs_object_id = row.hs_object_id
7
linkedinconnections = row.linkedinconnections
8
9
# Update LK Bio
10
if linkedinconnections != None:
11
data = {"properties": {"linkedinconnections": linkedinconnections}}
12
hubspot.connect(HS_API_KEY).contacts.patch(hs_object_id, data)
Copied!
Copy link
Edit on GitHub