Spaces:
Running
Running
Update linkedin_follower_stats.py
Browse files- linkedin_follower_stats.py +7 -13
linkedin_follower_stats.py
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
import json
|
2 |
import requests
|
3 |
import logging
|
@@ -26,7 +27,7 @@ def _fetch_linkedin_names(session, url, params, result_key_path, name_key_path,
|
|
26 |
request_url_for_logging = url
|
27 |
response_obj = None
|
28 |
try:
|
29 |
-
logging.debug(f"_fetch_linkedin_names: About to prepare request. Session token: {session.token}")
|
30 |
req = requests.Request('GET', url, params=params)
|
31 |
prepared_req = session.prepare_request(req)
|
32 |
request_url_for_logging = prepared_req.url
|
@@ -132,7 +133,7 @@ def get_industries_map(session, industry_urns, version="DEFAULT"):
|
|
132 |
response_obj = None
|
133 |
logging.info(f"Fetching all industries (to filter {len(unique_ids)} IDs)")
|
134 |
try:
|
135 |
-
logging.debug(f"get_industries_map: About to prepare request. Session token: {session.token}")
|
136 |
req = requests.Request('GET', url, params=params)
|
137 |
prepared_req = session.prepare_request(req)
|
138 |
request_url_for_logging = prepared_req.url
|
@@ -145,7 +146,6 @@ def get_industries_map(session, industry_urns, version="DEFAULT"):
|
|
145 |
elements = data.get('elements', [])
|
146 |
|
147 |
mapping = {}
|
148 |
-
# ... (rest of the function)
|
149 |
for el in elements:
|
150 |
el_id = el.get('id')
|
151 |
if el_id and str(el_id) in unique_ids:
|
@@ -200,7 +200,6 @@ def get_geo_map(session, geo_urns):
|
|
200 |
geo_params = { 'ids': ids_param_value, 'locale': locale_param_value }
|
201 |
|
202 |
logging.info(f"Fetching names for {len(chunk_ids)} geo IDs (chunk {i//MAX_GEO_IDS_PER_CALL + 1})")
|
203 |
-
# _fetch_linkedin_names will log its own session.token
|
204 |
chunk_mapping = _fetch_linkedin_names(session, url, geo_params, ["results"], ["defaultLocalizedName", "value"])
|
205 |
all_geo_mappings.update(chunk_mapping)
|
206 |
|
@@ -244,8 +243,7 @@ def fetch_monthly_follower_gains(session, org_urn, api_rest_base_url):
|
|
244 |
response_obj = None
|
245 |
|
246 |
try:
|
247 |
-
|
248 |
-
logging.debug(f"fetch_monthly_follower_gains: About to prepare request. Session token: {session.token}")
|
249 |
if session.token and 'access_token' in session.token:
|
250 |
logging.debug(f"fetch_monthly_follower_gains: Access token (partial): {str(session.token['access_token'])[:20]}...")
|
251 |
else:
|
@@ -263,7 +261,6 @@ def fetch_monthly_follower_gains(session, org_urn, api_rest_base_url):
|
|
263 |
data = response_obj.json()
|
264 |
|
265 |
elements = data.get('elements', [])
|
266 |
-
# ... (rest of the function)
|
267 |
if not elements:
|
268 |
logging.info(f"No 'elements' found in monthly follower gains API response for {org_urn} (start_ms {start_ms}). Response data: {json.dumps(data, indent=2)}")
|
269 |
|
@@ -334,8 +331,7 @@ def fetch_follower_demographics(session, org_urn, functions_map, seniorities_map
|
|
334 |
response_obj = None
|
335 |
|
336 |
try:
|
337 |
-
|
338 |
-
logging.debug(f"fetch_follower_demographics: About to prepare request. Session token: {session.token}")
|
339 |
if session.token and 'access_token' in session.token:
|
340 |
logging.debug(f"fetch_follower_demographics: Access token (partial): {str(session.token['access_token'])[:20]}...")
|
341 |
else:
|
@@ -353,7 +349,6 @@ def fetch_follower_demographics(session, org_urn, functions_map, seniorities_map
|
|
353 |
data = response_obj.json()
|
354 |
|
355 |
elements = data.get("elements", [])
|
356 |
-
# ... (rest of the function)
|
357 |
if not elements:
|
358 |
logging.warning(f"No elements found in follower demographics response for {org_urn}. Response data: {json.dumps(data, indent=2)}")
|
359 |
return []
|
@@ -486,8 +481,7 @@ def get_linkedin_follower_stats(comm_client_id, community_token, org_urn):
|
|
486 |
"Accept-Language": "en_US"
|
487 |
})
|
488 |
logging.info(f"Session created and headers updated for org {org_urn}.")
|
489 |
-
|
490 |
-
logging.debug(f"get_linkedin_follower_stats: Session token after creation and header update: {session.token}")
|
491 |
if session.token and 'access_token' in session.token:
|
492 |
logging.debug(f"get_linkedin_follower_stats: Access token in session (partial): {str(session.token['access_token'])[:20]}...")
|
493 |
else:
|
@@ -519,4 +513,4 @@ def get_linkedin_follower_stats(comm_client_id, community_token, org_urn):
|
|
519 |
else:
|
520 |
logging.info(f"Successfully compiled {len(all_follower_data)} total follower stat entries for {org_urn}.")
|
521 |
|
522 |
-
return all_follower_data
|
|
|
1 |
+
# -- coding: utf-8 --
|
2 |
import json
|
3 |
import requests
|
4 |
import logging
|
|
|
27 |
request_url_for_logging = url
|
28 |
response_obj = None
|
29 |
try:
|
30 |
+
logging.debug(f"_fetch_linkedin_names: About to prepare request. Session token: {session.token}, Session authorized: {session.authorized}")
|
31 |
req = requests.Request('GET', url, params=params)
|
32 |
prepared_req = session.prepare_request(req)
|
33 |
request_url_for_logging = prepared_req.url
|
|
|
133 |
response_obj = None
|
134 |
logging.info(f"Fetching all industries (to filter {len(unique_ids)} IDs)")
|
135 |
try:
|
136 |
+
logging.debug(f"get_industries_map: About to prepare request. Session token: {session.token}, Session authorized: {session.authorized}")
|
137 |
req = requests.Request('GET', url, params=params)
|
138 |
prepared_req = session.prepare_request(req)
|
139 |
request_url_for_logging = prepared_req.url
|
|
|
146 |
elements = data.get('elements', [])
|
147 |
|
148 |
mapping = {}
|
|
|
149 |
for el in elements:
|
150 |
el_id = el.get('id')
|
151 |
if el_id and str(el_id) in unique_ids:
|
|
|
200 |
geo_params = { 'ids': ids_param_value, 'locale': locale_param_value }
|
201 |
|
202 |
logging.info(f"Fetching names for {len(chunk_ids)} geo IDs (chunk {i//MAX_GEO_IDS_PER_CALL + 1})")
|
|
|
203 |
chunk_mapping = _fetch_linkedin_names(session, url, geo_params, ["results"], ["defaultLocalizedName", "value"])
|
204 |
all_geo_mappings.update(chunk_mapping)
|
205 |
|
|
|
243 |
response_obj = None
|
244 |
|
245 |
try:
|
246 |
+
logging.debug(f"fetch_monthly_follower_gains: About to prepare request. Session token: {session.token}, Session authorized: {session.authorized}")
|
|
|
247 |
if session.token and 'access_token' in session.token:
|
248 |
logging.debug(f"fetch_monthly_follower_gains: Access token (partial): {str(session.token['access_token'])[:20]}...")
|
249 |
else:
|
|
|
261 |
data = response_obj.json()
|
262 |
|
263 |
elements = data.get('elements', [])
|
|
|
264 |
if not elements:
|
265 |
logging.info(f"No 'elements' found in monthly follower gains API response for {org_urn} (start_ms {start_ms}). Response data: {json.dumps(data, indent=2)}")
|
266 |
|
|
|
331 |
response_obj = None
|
332 |
|
333 |
try:
|
334 |
+
logging.debug(f"fetch_follower_demographics: About to prepare request. Session token: {session.token}, Session authorized: {session.authorized}")
|
|
|
335 |
if session.token and 'access_token' in session.token:
|
336 |
logging.debug(f"fetch_follower_demographics: Access token (partial): {str(session.token['access_token'])[:20]}...")
|
337 |
else:
|
|
|
349 |
data = response_obj.json()
|
350 |
|
351 |
elements = data.get("elements", [])
|
|
|
352 |
if not elements:
|
353 |
logging.warning(f"No elements found in follower demographics response for {org_urn}. Response data: {json.dumps(data, indent=2)}")
|
354 |
return []
|
|
|
481 |
"Accept-Language": "en_US"
|
482 |
})
|
483 |
logging.info(f"Session created and headers updated for org {org_urn}.")
|
484 |
+
logging.debug(f"get_linkedin_follower_stats: Session token after creation and header update: {session.token}, Session authorized: {session.authorized}")
|
|
|
485 |
if session.token and 'access_token' in session.token:
|
486 |
logging.debug(f"get_linkedin_follower_stats: Access token in session (partial): {str(session.token['access_token'])[:20]}...")
|
487 |
else:
|
|
|
513 |
else:
|
514 |
logging.info(f"Successfully compiled {len(all_follower_data)} total follower stat entries for {org_urn}.")
|
515 |
|
516 |
+
return all_follower_data
|