Spaces:
Sleeping
Sleeping
Update linkedin_follower_stats.py
Browse files- linkedin_follower_stats.py +7 -12
linkedin_follower_stats.py
CHANGED
|
@@ -2,8 +2,7 @@
|
|
| 2 |
import json
|
| 3 |
import requests
|
| 4 |
import logging
|
| 5 |
-
from datetime import datetime, timezone
|
| 6 |
-
from dateutil.relativedelta import relativedelta # For robust month arithmetic
|
| 7 |
from urllib.parse import quote
|
| 8 |
|
| 9 |
# Assuming you have a sessions.py with create_session
|
|
@@ -177,16 +176,12 @@ def fetch_monthly_follower_gains(session, org_urn, api_rest_base):
|
|
| 177 |
Fetches monthly follower gains for the last 12 full months.
|
| 178 |
The start date is set to the first day of the month, 12 months prior to the current month, at midnight UTC.
|
| 179 |
"""
|
| 180 |
-
now = datetime.now(
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
# - twelve_months_ago_date becomes 2024-05-13.
|
| 185 |
-
# - start_of_period becomes 2024-05-01 00:00:00 UTC.
|
| 186 |
-
twelve_months_ago_date = now - relativedelta(months=12)
|
| 187 |
-
start_of_period = twelve_months_ago_date.replace(day=1, hour=0, minute=0, second=0, microsecond=0, tzinfo=timezone.utc)
|
| 188 |
|
| 189 |
-
|
| 190 |
|
| 191 |
# Build URL with explicit query string
|
| 192 |
url = (
|
|
@@ -194,7 +189,7 @@ def fetch_monthly_follower_gains(session, org_urn, api_rest_base):
|
|
| 194 |
f"?q=organizationalEntity"
|
| 195 |
f"&organizationalEntity={org_urn}"
|
| 196 |
f"&timeIntervals.timeGranularityType=MONTH"
|
| 197 |
-
f"&timeIntervals.timeRange.start={
|
| 198 |
# LinkedIn defaults the end of the timeRange to the current time if not specified.
|
| 199 |
)
|
| 200 |
logging.info(f"Fetching monthly follower gains from URL: {url}")
|
|
|
|
| 2 |
import json
|
| 3 |
import requests
|
| 4 |
import logging
|
| 5 |
+
from datetime import datetime, timezone, timedelta
|
|
|
|
| 6 |
from urllib.parse import quote
|
| 7 |
|
| 8 |
# Assuming you have a sessions.py with create_session
|
|
|
|
| 176 |
Fetches monthly follower gains for the last 12 full months.
|
| 177 |
The start date is set to the first day of the month, 12 months prior to the current month, at midnight UTC.
|
| 178 |
"""
|
| 179 |
+
now = datetime.now()
|
| 180 |
+
|
| 181 |
+
twelve_months_ago = now - timedelta(days=365)
|
| 182 |
+
twelve_months_ago = twelve_months_ago.replace(day=1)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 183 |
|
| 184 |
+
start_date = int(twelve_months_ago.timestamp() * 1000)
|
| 185 |
|
| 186 |
# Build URL with explicit query string
|
| 187 |
url = (
|
|
|
|
| 189 |
f"?q=organizationalEntity"
|
| 190 |
f"&organizationalEntity={org_urn}"
|
| 191 |
f"&timeIntervals.timeGranularityType=MONTH"
|
| 192 |
+
f"&timeIntervals.timeRange.start={start_date}"
|
| 193 |
# LinkedIn defaults the end of the timeRange to the current time if not specified.
|
| 194 |
)
|
| 195 |
logging.info(f"Fetching monthly follower gains from URL: {url}")
|