GuglielmoTor commited on
Commit
0c8b711
·
verified ·
1 Parent(s): 19d591e

Update linkedin_follower_stats.py

Browse files
Files changed (1) hide show
  1. 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(timezone.utc)
181
-
182
- # Calculate the first day of the month, 12 months ago.
183
- # For example, if now is 2025-05-13:
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
- start_ms = int(start_of_period.timestamp() * 1000)
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={start_ms}"
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}")