😎
Templates
Google Analytics
Google Drive
Google Search
Google Sheets
Hugging Face
Johns Hopkins
Jupyter Notebooks
Metrics Store
Microsoft Teams
Microsoft Word
Naas Auth
Get polls from post
Tags: #linkedin #post #polls #naas_drivers
Author: Florent Ravenel

Input

Import library

1
from naas_drivers import linkedin
2
import plotly.express as px
Copied!

Get your cookies

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

Enter post URL

1
POST_URL = "POST_URL"
Copied!

Model

Get poll results from post

1
df = linkedin.connect(LI_AT, JSESSIONID).post.get_polls(POST_URL)
2
print("📝 Nb of poll results", len(df))
3
df.head(5)
Copied!

Output

Save your result in csv

1
df.to_csv("POLL.csv", index=False)
2
print("💾 Poll results saved in csv")
Copied!

Create, export and share your graph

1
def create_polls_graph(df):
2
poll_id = df.POLL_ID.unique()[0]
3
title = df.POLL_QUESTION.unique()[0]
4
5
# Create dataframe
6
df = df.groupby(["POLL_RESULT"], as_index=False).agg({"PROFILE_ID": "count"})
7
df["VALUE"] = df["PROFILE_ID"] / df["PROFILE_ID"].sum() * 100
8
df["VALUE_D"] = df["VALUE"].map('{:.0f}%'.format)
9
10
# Count voters
11
voters = df.PROFILE_ID.sum()
12
13
# Create fig
14
fig = px.bar(df,
15
y="POLL_RESULT",
16
x="PROFILE_ID",
17
orientation='h',
18
title=f"{title}<br><span style='font-size: 13px;'>Total amount of votes: {voters}</span>",
19
text="VALUE_D",
20
labels={
21
"POLL_RESULT": "Options",
22
"PROFILE_ID": "Nb of votes",
23
"VALUE_D": "% of votes"
24
},
25
)
26
fig.update_traces(marker_color='black')
27
fig.update_layout(
28
plot_bgcolor="#ffffff",
29
width=600,
30
height=400,
31
font=dict(family="Arial", size=14, color="black"),
32
paper_bgcolor="white",
33
xaxis_title=None,
34
xaxis_showticklabels=False,
35
yaxis_title=None,
36
margin_pad=10,
37
)
38
fig.write_html(f"{poll_id}.html")
39
fig.show()
40
asset = naas.asset.add(f"{poll_id}.html")
41
return asset
42
43
create_polls_graph(df)
Copied!
Copy link
Edit on GitHub