fix(newsletter): use follow_redirects=False to avoid false positive on 404 redirect

Beehiiv redirects non-existent newsletters to /?404=... with HTTP 302.
With follow_redirects=True, the final 200 was misread as "newsletter exists".
Fix: disable redirect following so only a direct HTTP 200 = newsletter real.
Also reset state back to last_sent=13 (real).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-03 17:06:00 +00:00
parent 5fafc29dc1
commit 9d447b9ff1
2 changed files with 7 additions and 7 deletions

View File

@@ -1,5 +1 @@
{
"last_sent": 13,
"year": 2026,
"last_sent_at": "2026-04-02T18:59:37.878273+00:00"
}
{"last_sent": 13, "year": 2026, "last_sent_at": "2026-04-02T18:18:46.000000+00:00"}

View File

@@ -35,10 +35,14 @@ def _write_state(state: dict) -> None:
async def _newsletter_exists(n: int, year: int) -> bool:
"""Return True if newsletter #{n}/{year} returns HTTP 200."""
"""Return True if newsletter #{n}/{year} exists (HTTP 200, no redirect to 404 page).
Beehiiv redirects non-existent newsletters: /p/newsletter-N-din-YEAR → /?404=... (302)
A real newsletter returns 200 directly without redirect.
"""
url = NEWSLETTER_BASE_URL.format(n=n, year=year)
try:
async with httpx.AsyncClient(follow_redirects=True) as client:
async with httpx.AsyncClient(follow_redirects=False) as client:
resp = await client.get(url, timeout=10)
return resp.status_code == 200
except Exception as e: