Links

Send LinkedIn invitations from spreadsheet

Tags: #googlesheets #invitation #automation #content #notification #email #linkedin
Author: Valentin Goulet
Description: This notebook allows users to quickly and easily send LinkedIn invitations to contacts stored in a Google Sheets spreadsheet.

Input

Import libraries

import naas
from naas_drivers import linkedin, gsheet

Setup Google Sheets

👉 The spreadsheet needs to contains profil's url on the 1st column of the file.
spreadsheet_id = "YOUR_SPREADSHEET_ID"
sheet_name = "YOUR_SHEET_NAME"
profile_col_name = "url"

Setup LinkedIn

# LinkedIn cookies
LI_AT = "YOUR_COOKIE_LI_AT"
JSESSIONID = "YOUR_COOKIE_JSESSIONID"
# LinkedIn limit invitations up to 100 per week (Becareful !)
add_per_launch = 4

Schedule your notebook

# Scheduler your invitation everyday at 8:00 AM
naas.scheduler.add(cron="0 8 * * *")
# Uncomment the line below to delete your scheduler
# naas.scheduler.delete()

Model

Get all list of profiles

df = gsheet.connect(spreadsheet_id).get(sheet_name=sheet_name)

Get restricted list

# Alert when last than 20 urls remains in the gsheet
if len(df) < 20:
email_to = "YOUR_EMAIL"
subject = (
"Invite LinkedIn alert : "
+ str(len(df))
+ " lines left in the Linkedin's url database"
)
content = "You can add more lines to the gsheet or update the Notebook to set a new spreadsheet !"
naas.notification.send(email_to=email_to, subject=subject, html=content)
df = df.head(add_per_launch)
print("Invits will be send to :")
df

Output

Send the invitation and delete profil from Gsheet

for index, row in df.iterrows():
profile = row[profile_col_name]
result = linkedin.connect(LI_AT, JSESSIONID).invitation.send(recipient_url=profile)
print(f"Invitation sent to : {profile}")
# Suppression de la ligne du gsheet
gsheet.connect(spreadsheet_id).delete(sheet_name=sheet_name, rows=[2])