jupyter-naas / awesome-notebooks

A powerful data & AI notebook templates catalog: prompts, plugins, models, workflow automation, analytics, code snippets - following the IMO framework to be searchable and reusable in any context.
https://naas.ai/search
BSD 3-Clause "New" or "Revised" License
2.68k stars 453 forks source link

LinkedIn - Follow Number of Content Published #426

Closed Dr0p42 closed 2 years ago

Dr0p42 commented 2 years ago
Naas

LinkedIn - Follow Number of Content Published

Tags: #linkedin #html# plotly# csv# image #content #analytics# automation

Author: Firstname Lastname

With this notebook, you can see the evolution the number of content published on LinkedIn on your personal profile, cumulated, daily since first activity.

Input

Import libraries

from naas_drivers import linkedin
import naas
import pandas as pd

Setup LinkedIn

# Lindekin cookies
LI_AT = "AQEDARCNSioDe6wmAAABfqF-HR4AAAF-xYqhHlYAtSu7EZZEpFer0UZF-GLuz2DNSz4asOOyCRxPGFjenv37irMObYYgxxxxxxx"
JSESSIONID = "ajax:12XXXXXXXXXXXXXXXXX"

# Enter profile URL
PROFILE_URL = "PROFILE_URL"

Setup Outputs

# Outputs
name_output = "My_output"
csv_output = f"{name_output}.csv"
html_output = f"{name_output}.html"
image_output = f"{name_output}.png"

Setup Naas

# Schedule your notebook everyday at 9:00 AM
naas.scheduler.add(cron="0 9 * * *")

#-> Uncomment the line below to remove your scheduler
# naas.scheduler.delete()

Model

Get posts feed

# Get posts feed from CSV stored in your local (Return empty if CSV does not exist)
def my_function(csv_output):
    ...
    df = pd.read_csv(csv_output)
    return df

df_posts_feed = my_function(csv_output)
df_posts_feed

Get new posts

def my_function(df):
    ...
    # Get last post URL in dataframe
    last_post_url = None

    # Get new posts since last url (this part is important to optimize script performance)
    until = {}
  if last_post_url:
        until = {"POST_URL": last_post_url}
    df_posts_feed = linkedin.connect(LI_AT, JSESSIONID).profile.get_posts_feed(PROFILE_URL, until=until, limit=-1)

    # Merge dataframe 
    return

merged_df = my_function(df)
merged_df

Get trend

# Create dataframe with number of LinkedIn posts cumulated by date with daily variation
# -> Empty date must be fullfiled with last value
def get_trend(df):
    ...
    return df

df_trend = get_trend()
df_trend 

Output

Display result

def create_linechart(df, label, value, title):
        ...
    # Init
    fig = go.Figure()

    # Create fig
    fig.add_trace(
        go.Scatter(
            x=df[label],
            y=df[value],
            mode="lines",
        )
    )
    fig.update_traces(marker_color='black')
    fig.update_layout(
        title=title,
        title_font=dict(family="Arial", size=18, color="black"),
        plot_bgcolor="#ffffff",
        width=1200,
        height=800,
        paper_bgcolor="white",
        margin_pad=10,
    )
    fig.show()
    return fig

fig = create_linechart(df_trend, label="", value="", title=title)

Save and share your csv file

# Save your dataframe in CSV
merged_df.to_csv(csv_output, index=False)

# Share output with naas
naas.asset.add(csv_output)

#-> Uncomment the line below to remove your asset
# naas.asset.delete(csv_output)

Save and share your graph in HTML

# Save your graph in HTML
fig.write_html(html_output)

# Share output with naas
naas.asset.add(html_output, params={"inline": True})

#-> Uncomment the line below to remove your asset
# naas.asset.delete(html_output)

Save and share your graph in image

# Save your graph in PNG
fig.write_image(image_output)

# Share output with naas
naas.asset.add(image_output, params={"inline": True})

#-> Uncomment the line below to remove your asset
# naas.asset.delete(image_output)
Dr0p42 commented 2 years ago

🚀 Branch and template have been created and pushed.

You should work on: