Comment on page

Send profile followers by email

Tags: #linkedin #network #followers #naas_drivers #content #snippet #dataframe
Author: Florent Ravenel​
Last update: 2023-05-29 (Created: 2022-06-02)
Description: This notebook allows users to send emails to their LinkedIn profile followers.
Disclaimer: This code is in no way affiliated with, authorized, maintained, sponsored or endorsed by Linkedin or any of its affiliates or subsidiaries. It uses an independent and unofficial API. Use at your own risk.
This project violates Linkedin's User Agreement Section 8.2, and because of this, Linkedin may (and will) temporarily or permanently ban your account. We are not responsible for your account being banned.


Import library

from naas_drivers import linkedin, emailbuilder
import naas
import pandas as pd
from datetime import datetime

Setup LinkedIn

# LinkedIn cookies

Setup Outputs

Create CSV to store your followers. PS: This CSV could be used in others LinkedIn templates.
csv_output = f"LINKEDIN_FOLLOWERS.csv"

Setup Naas notification

EMAIL_TO = "ENTER_RECIPIENT_EMAIL_HERE" # you will receive weekly summary at this email
EMAIL_FROM = "ENTER_SENDER_EMAIL_HERE" # summary will have this email as sender. Only available for your naas email
EMAIL_SUBJECT = "LinkedIn Followers Export" # subject of your email

Setup Naas scheduler

Schedule your notebook with the naas scheduler feature
# the default settings below will make the notebook run at 08:00 on the 1st of every month
# for information on changing this setting, please check for information on the required CRON syntax
naas.scheduler.add(cron="0 8 1 * *")
# to de-schedule this notebook, simply run the following command:
# naas.scheduler.delete()


Get followers from CSV

def read_csv(file_path):
df = pd.read_csv(file_path)
except FileNotFoundError as e:
# Empty dataframe returned
return pd.DataFrame()
return df
df_followers = read_csv(csv_output)

Update new followers

If CSV is empty, we will get all your followers
def update_last_posts(df, csv_output):
# Init output
df_new = pd.DataFrame()
# Check if dataframe init is empty
if len(df) > 0:
# If dataframe not empty, get last followers
profiles = df.PROFILE_ID.unique()
start = 0
count = 100
while True:
tmp_new = linkedin.connect(LI_AT, JSESSIONID).network.get_followers(
start=start, limit=count
# Check if existing profile in each call
tmp_df = tmp_new[tmp_new.PROFILE_ID.isin(profiles)]
if len(tmp_df) > 0:
# Get more profile
df_new = pd.concat([df_new, tmp_new])
start += count
# If dataframe empty, get all followers
df_new = linkedin.connect(LI_AT, JSESSIONID).network.get_followers(limit=-1)
# Concat
print(f"-> New followers fetched: {len(df_new)}.")
df_update = pd.concat([df, df_new])
# Cleaning to remove duplicates if needed
if len(df_update) > 0:
df_update = df_update.drop_duplicates("PROFILE_ID", keep="first")
# Add extract date
df_update["DATE_EXTRACT"] ="%Y-%m-%d %H:%M:%S")
# Save dataframe in CSV
df_update.to_csv(csv_output, index=False)
# Return all followers
print(f"Total followers fetched: {len(df_update)}.")
return df_update.reset_index(drop=True)
df_update = update_last_posts(df_followers, csv_output)

Share output with naas

# Share output with naas
csv_link = naas.asset.add(csv_output)
# -> Uncomment the line below to remove your asset
# naas.asset.delete(csv_output)

Create email content

def email_content(csv_link):
content = {
"header_naas": (
"<a href=''>"
"<img align='center' width='30%' target='_blank' style='border-radius:5px;'"
"alt='Please provide more information.'/>"
"txt_0": emailbuilder.text(
f"Hi there,<br><br>"
f"Here's your LinkedIn followers report as of {'%Y-%m-%d')}.<br><br>"
"button": emailbuilder.button(csv_link, "Download CSV"),
"signature": "Naas Team",
"footer": emailbuilder.footer_company(naas=True),
email_content = emailbuilder.generate(display="iframe", **content)
return email_content
email_content = email_content(csv_link)


Send followers by email

# sends the email