Spaces:
Running
Running
Update linkedin_follower_stats.py
Browse files- linkedin_follower_stats.py +26 -8
linkedin_follower_stats.py
CHANGED
@@ -149,7 +149,9 @@ def get_geo_map(session, geo_urns):
|
|
149 |
|
150 |
# Parameters must be passed in the URL string directly for this specific API format
|
151 |
# The `params` dict for session.get() will be empty.
|
152 |
-
url = f"{API_V2_BASE}/geo?ids={
|
|
|
|
|
153 |
|
154 |
logging.info(f"Fetching names for {len(unique_ids)} unique geo IDs using URL: {url}")
|
155 |
return _fetch_linkedin_names(session, url, {}, ["results"], ["defaultLocalizedName", "value"])
|
@@ -176,23 +178,39 @@ def fetch_monthly_follower_gains(session, org_urn, api_rest_base):
|
|
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 = (
|
188 |
f"{api_rest_base}/organizationalEntityFollowerStatistics"
|
189 |
f"?q=organizationalEntity"
|
190 |
f"&organizationalEntity={org_urn}"
|
191 |
-
f"&timeIntervals
|
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}")
|
196 |
|
197 |
results = []
|
198 |
try:
|
|
|
149 |
|
150 |
# Parameters must be passed in the URL string directly for this specific API format
|
151 |
# The `params` dict for session.get() will be empty.
|
152 |
+
url = f"{API_V2_BASE}/geo?ids={ids_param_string}&locale={locale_param_string}"
|
153 |
+
#url = f"{API_V2_BASE}/geo?ids=List({','.join(map(str, unique_ids))})&locale=(language:en,country:US)"
|
154 |
+
|
155 |
|
156 |
logging.info(f"Fetching names for {len(unique_ids)} unique geo IDs using URL: {url}")
|
157 |
return _fetch_linkedin_names(session, url, {}, ["results"], ["defaultLocalizedName", "value"])
|
|
|
178 |
Fetches monthly follower gains for the last 12 full months.
|
179 |
The start date is set to the first day of the month, 12 months prior to the current month, at midnight UTC.
|
180 |
"""
|
181 |
+
# now = datetime.now()
|
182 |
|
183 |
+
# twelve_months_ago = now - timedelta(days=365)
|
184 |
+
# twelve_months_ago = twelve_months_ago.replace(day=1)
|
185 |
+
|
186 |
+
# start_date = int(twelve_months_ago.timestamp() * 1000)
|
187 |
+
|
188 |
+
# # Build URL with explicit query string
|
189 |
+
# url = (
|
190 |
+
# f"{api_rest_base}/organizationalEntityFollowerStatistics"
|
191 |
+
# f"?q=organizationalEntity"
|
192 |
+
# f"&organizationalEntity={org_urn}"
|
193 |
+
# f"&timeIntervals.timeGranularityType=MONTH"
|
194 |
+
# f"&timeIntervals.timeRange.start={start_date}"
|
195 |
+
# # LinkedIn defaults the end of the timeRange to the current time if not specified.
|
196 |
+
# )
|
197 |
+
# logging.info(f"Fetching monthly follower gains from URL: {url}")
|
198 |
+
|
199 |
+
now = datetime.now(timezone.utc)
|
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 |
+
time_intervals = f"(timeRange:(start:{start_date},end:{end_date}),timeGranularityType:MONTH)"
|
207 |
|
|
|
208 |
url = (
|
209 |
f"{api_rest_base}/organizationalEntityFollowerStatistics"
|
210 |
f"?q=organizationalEntity"
|
211 |
f"&organizationalEntity={org_urn}"
|
212 |
+
f"&timeIntervals={time_intervals}"
|
|
|
|
|
213 |
)
|
|
|
214 |
|
215 |
results = []
|
216 |
try:
|