Send invitation to profile from post likes
Tags: #linkedin #post #likes #naas_drivers #invitation #content #snippet
Last update: 2023-05-29 (Created: 2022-05-09)
Description: This notebook allows users to send LinkedIn invitations to profiles based on post likes.
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.
from naas_drivers import linkedin
import pandas as pd
import naas
import time
# Credentials
LI_AT = "YOUR_COOKIE_LI_AT" # EXAMPLE AQFAzQN_PLPR4wAAAXc-FCKmgiMit5FLdY1af3-2
JSESSIONID = "YOUR_COOKIE_JSESSIONID" # EXAMPLE ajax:8379907400220387585
# Post url
POST_URL = "POST_URL"
# Post likes
csv_post_likes = (
f"LINKEDIN_POST_LIKES_{POST_URL.split('activity-')[1].split('-')[0]}.csv"
)
df_post_likes = linkedin.connect(LI_AT, JSESSIONID).post.get_likes(POST_URL)
print("👍 Post likes :", len(df_post_likes))
df_post_likes.tail(1)
def get_connections(df):
for index, row in df.iterrows():
df_network = pd.DataFrame()
profile = row["PUBLIC_ID"]
print(f"➡️ Checking :", profile)
# Get distance with profile
if profile != 0:
df_network = linkedin.connect(LI_AT, JSESSIONID).profile.get_network(
profile
)
# Check if profile is already in your network
if len(df_network) > 0:
distance = df_network.loc[0, "DISTANCE"]
df.loc[index, "DISTANCE"] = distance
df.to_csv(csv_post_likes, index=False)
return df
df_profile = get_connections(df_post_likes)
df_profile
def send_invitation(df):
df = df[~df.DISTANCE.isin(["SELF", "DISTANCE_1"])].reset_index(drop=True)
for index, row in df.iterrows():
fullname = row["FULLNAME"]
profile_id = row["PROFILE_ID"]
print(f"➡️ Sending to :", fullname)
# Get distance with profile
try:
linkedin.invitation.send(recipient_url=profile_id)
except Exception as e:
print("❌ Invitation not sent", e)
time.sleep(3)
return df
df_invitation = send_invitation(df_profile)
df_invitation
Last modified 1mo ago