had to switch over to Pushpull API because Reddit was blocking the DigitalOcean IP
This commit is contained in:
@@ -8,11 +8,11 @@ from backend.config import settings
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
BASE_URL = "https://old.reddit.com"
|
||||
BASE_URL = "https://api.pullpush.io"
|
||||
|
||||
# Simple in-process rate limiter: track request timestamps
|
||||
_request_times: list[float] = []
|
||||
MAX_REQUESTS_PER_MINUTE = 9 # Stay under Reddit's ~10/min limit
|
||||
MAX_REQUESTS_PER_MINUTE = 9
|
||||
|
||||
|
||||
async def _wait_for_rate_limit():
|
||||
@@ -29,9 +29,9 @@ async def _wait_for_rate_limit():
|
||||
|
||||
|
||||
async def fetch_json(client: httpx.AsyncClient, path: str, params: dict | None = None) -> dict | None:
|
||||
"""Fetch a Reddit .json endpoint with rate limiting and error handling."""
|
||||
"""Fetch a Pullpush API endpoint with rate limiting and error handling."""
|
||||
await _wait_for_rate_limit()
|
||||
url = f"{BASE_URL}{path}.json"
|
||||
url = f"{BASE_URL}{path}"
|
||||
try:
|
||||
response = await client.get(url, params=params)
|
||||
if response.status_code == 429:
|
||||
@@ -40,7 +40,7 @@ async def fetch_json(client: httpx.AsyncClient, path: str, params: dict | None =
|
||||
await asyncio.sleep(retry_after)
|
||||
return await fetch_json(client, path, params)
|
||||
if response.status_code >= 500:
|
||||
logger.warning(f"Reddit returned {response.status_code} for {path}")
|
||||
logger.warning(f"Pullpush returned {response.status_code} for {path}")
|
||||
return None
|
||||
response.raise_for_status()
|
||||
return response.json()
|
||||
@@ -50,13 +50,9 @@ async def fetch_json(client: httpx.AsyncClient, path: str, params: dict | None =
|
||||
|
||||
|
||||
def create_client() -> httpx.AsyncClient:
|
||||
"""Create an httpx client configured for Reddit."""
|
||||
"""Create an httpx client configured for Pullpush API."""
|
||||
return httpx.AsyncClient(
|
||||
headers={
|
||||
"User-Agent": settings.reddit_user_agent,
|
||||
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
|
||||
"Accept-Language": "en-US,en;q=0.5",
|
||||
},
|
||||
headers={"User-Agent": settings.reddit_user_agent},
|
||||
timeout=30.0,
|
||||
follow_redirects=True,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user