Spaces:
Running
Running
Update Linkedin_Data_API_Calls.py
Browse files- Linkedin_Data_API_Calls.py +37 -0
Linkedin_Data_API_Calls.py
CHANGED
|
@@ -144,3 +144,40 @@ def fetch_posts_and_stats(comm_client_id, community_token, org_urn, count=10):
|
|
| 144 |
post["category"] = structured["category"]
|
| 145 |
|
| 146 |
return posts, org_name, sentiments
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
post["category"] = structured["category"]
|
| 145 |
|
| 146 |
return posts, org_name, sentiments
|
| 147 |
+
|
| 148 |
+
def prepare_data_for_bubble(posts, sentiments):
|
| 149 |
+
li_posts = []
|
| 150 |
+
li_post_stats = []
|
| 151 |
+
li_post_comments = []
|
| 152 |
+
|
| 153 |
+
for post in posts:
|
| 154 |
+
li_posts.append({
|
| 155 |
+
"author_urn": post["author_urn"],
|
| 156 |
+
"id": post["id"],
|
| 157 |
+
"is_ad": post["is_ad"],
|
| 158 |
+
"media_type": post["media_type"],
|
| 159 |
+
"published_at": post["published_at"],
|
| 160 |
+
"sentiment": sentiments.get(post["id"], {}).get("sentiment", "Neutral"),
|
| 161 |
+
"text": post["text"]
|
| 162 |
+
})
|
| 163 |
+
|
| 164 |
+
li_post_stats.append({
|
| 165 |
+
"clickCount": post["clicks"],
|
| 166 |
+
"commentCount": post["comments"],
|
| 167 |
+
"engagement": post["engagement"],
|
| 168 |
+
"impressionCount": post["impressions"],
|
| 169 |
+
"likeCount": post["likes"],
|
| 170 |
+
"shareCount": post["shares"],
|
| 171 |
+
"uniqueImpressionsCount": post.get("uniqueImpressionsCount", 0),
|
| 172 |
+
"post_id": post["id"]
|
| 173 |
+
})
|
| 174 |
+
|
| 175 |
+
for comment in post.get("comments_data", []):
|
| 176 |
+
message = comment.get('message', {}).get('text')
|
| 177 |
+
if message:
|
| 178 |
+
li_post_comments.append({
|
| 179 |
+
"comment_text": message,
|
| 180 |
+
"post_id": post["id"]
|
| 181 |
+
})
|
| 182 |
+
|
| 183 |
+
return li_posts, li_post_stats, li_post_comments
|