Spaces:
Running
Running
Update mentions_dashboard.py
Browse files- mentions_dashboard.py +6 -5
mentions_dashboard.py
CHANGED
@@ -11,6 +11,8 @@ from requests_oauthlib import OAuth2Session
|
|
11 |
from textblob import TextBlob
|
12 |
import matplotlib.pyplot as plt
|
13 |
|
|
|
|
|
14 |
|
15 |
def extract_text_from_commentary(commentary):
|
16 |
return re.sub(r"{.*?}", "", commentary).strip()
|
@@ -21,13 +23,12 @@ def analyze_sentiment(text):
|
|
21 |
|
22 |
|
23 |
def generate_mentions_dashboard(comm_client_id, comm_token_dict):
|
24 |
-
linkedin = OAuth2Session(comm_client_id, token=comm_token_dict)
|
25 |
|
26 |
org_urn = "urn:li:organization:19010008"
|
27 |
encoded_urn = quote(org_urn, safe='')
|
28 |
|
29 |
-
|
30 |
-
|
31 |
"X-Restli-Protocol-Version": "2.0.0"
|
32 |
})
|
33 |
|
@@ -44,7 +45,7 @@ def generate_mentions_dashboard(comm_client_id, comm_token_dict):
|
|
44 |
|
45 |
while True:
|
46 |
url = f"{base_url}&start={start}"
|
47 |
-
resp =
|
48 |
if resp.status_code != 200:
|
49 |
break
|
50 |
|
@@ -67,7 +68,7 @@ def generate_mentions_dashboard(comm_client_id, comm_token_dict):
|
|
67 |
continue
|
68 |
encoded_share_urn = quote(share_urn, safe='')
|
69 |
share_url = f"https://api.linkedin.com/rest/posts/{encoded_share_urn}"
|
70 |
-
response =
|
71 |
|
72 |
if response.status_code != 200:
|
73 |
continue
|
|
|
11 |
from textblob import TextBlob
|
12 |
import matplotlib.pyplot as plt
|
13 |
|
14 |
+
from sessions import create_session
|
15 |
+
|
16 |
|
17 |
def extract_text_from_commentary(commentary):
|
18 |
return re.sub(r"{.*?}", "", commentary).strip()
|
|
|
23 |
|
24 |
|
25 |
def generate_mentions_dashboard(comm_client_id, comm_token_dict):
|
|
|
26 |
|
27 |
org_urn = "urn:li:organization:19010008"
|
28 |
encoded_urn = quote(org_urn, safe='')
|
29 |
|
30 |
+
session = create_session(comm_client_id, token=comm_token_dict)
|
31 |
+
session.headers.update({
|
32 |
"X-Restli-Protocol-Version": "2.0.0"
|
33 |
})
|
34 |
|
|
|
45 |
|
46 |
while True:
|
47 |
url = f"{base_url}&start={start}"
|
48 |
+
resp = session.get(url)
|
49 |
if resp.status_code != 200:
|
50 |
break
|
51 |
|
|
|
68 |
continue
|
69 |
encoded_share_urn = quote(share_urn, safe='')
|
70 |
share_url = f"https://api.linkedin.com/rest/posts/{encoded_share_urn}"
|
71 |
+
response = session.get(share_url)
|
72 |
|
73 |
if response.status_code != 200:
|
74 |
continue
|