Spaces:
Running
Running
Update linkedin_follower_stats.py
Browse files- linkedin_follower_stats.py +7 -10
linkedin_follower_stats.py
CHANGED
@@ -196,21 +196,18 @@ def fetch_monthly_follower_gains(session, org_urn, api_rest_base):
|
|
196 |
# )
|
197 |
# logging.info(f"Fetching monthly follower gains from URL: {url}")
|
198 |
|
199 |
-
|
200 |
-
twelve_months_ago = now - timedelta(days=365)
|
201 |
-
twelve_months_ago = twelve_months_ago.replace(day=1)
|
202 |
-
|
203 |
-
start_date = int(twelve_months_ago.timestamp() * 1000)
|
204 |
-
end_date = int(now.timestamp() * 1000) # You could omit this if letting LinkedIn default
|
205 |
|
206 |
-
|
|
|
|
|
207 |
|
|
|
208 |
url = (
|
209 |
f"{api_rest_base}/organizationalEntityFollowerStatistics"
|
210 |
f"?q=organizationalEntity"
|
211 |
f"&organizationalEntity={org_urn}"
|
212 |
-
f"&timeIntervals.timeRange.start={
|
213 |
-
f"&timeIntervals.timeRange.end={end_date}"
|
214 |
f"&timeIntervals.timeGranularityType=MONTH"
|
215 |
)
|
216 |
|
@@ -222,7 +219,7 @@ def fetch_monthly_follower_gains(session, org_urn, api_rest_base):
|
|
222 |
|
223 |
elements = data.get('elements', [])
|
224 |
if not elements:
|
225 |
-
logging.info(f"No 'elements' found in API response for {org_urn} for start_ms {
|
226 |
|
227 |
for item in elements:
|
228 |
time_range = item.get('timeRange', {})
|
|
|
196 |
# )
|
197 |
# logging.info(f"Fetching monthly follower gains from URL: {url}")
|
198 |
|
199 |
+
session.headers.setdefault('LinkedIn-Version', '202502')
|
|
|
|
|
|
|
|
|
|
|
200 |
|
201 |
+
now = datetime.now(timezone.utc)
|
202 |
+
twelve_months_ago = (now - timedelta(days=365)).replace(day=1)
|
203 |
+
start_ms = int(twelve_months_ago.timestamp() * 1000)
|
204 |
|
205 |
+
# only pass start + granularity
|
206 |
url = (
|
207 |
f"{api_rest_base}/organizationalEntityFollowerStatistics"
|
208 |
f"?q=organizationalEntity"
|
209 |
f"&organizationalEntity={org_urn}"
|
210 |
+
f"&timeIntervals.timeRange.start={start_ms}"
|
|
|
211 |
f"&timeIntervals.timeGranularityType=MONTH"
|
212 |
)
|
213 |
|
|
|
219 |
|
220 |
elements = data.get('elements', [])
|
221 |
if not elements:
|
222 |
+
logging.info(f"No 'elements' found in API response for {org_urn} for start_ms {start_ms}.")
|
223 |
|
224 |
for item in elements:
|
225 |
time_range = item.get('timeRange', {})
|