Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions substack_api/category.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from time import sleep
from typing import Any, Dict, List, Optional, Tuple

import requests
Expand Down Expand Up @@ -127,6 +128,7 @@ def _fetch_newsletters_data(
full_url = endpoint + str(page_num)
r = requests.get(full_url, headers=HEADERS, timeout=30)
r.raise_for_status()
sleep(2) # Be polite to the server

resp = r.json()
newsletters = resp["publications"]
Expand Down
10 changes: 5 additions & 5 deletions substack_api/newsletter.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,12 @@ def _make_request(self, endpoint: str, **kwargs) -> requests.Response:
The response object from the request
"""
if self.auth and self.auth.authenticated:
return self.auth.get(endpoint, **kwargs)
resp = self.auth.get(endpoint, **kwargs)
else:
return requests.get(endpoint, headers=HEADERS, **kwargs)
resp = requests.get(endpoint, headers=HEADERS, **kwargs)

sleep(2) # Be polite to the server
return resp

def _fetch_paginated_posts(
self, params: Dict[str, str], limit: Optional[int] = None, page_size: int = 15
Expand Down Expand Up @@ -112,9 +115,6 @@ def _fetch_paginated_posts(
if len(items) < batch_size:
more_items = False

# Be nice to the API
sleep(0.5)

# Instead of creating Post objects directly, return the URLs
# The caller will create Post objects as needed
return results
Expand Down