c-stone-invoice-check/backend/fetchers/direct.py
Markus Kruse db8dc1dae3 feat(picker): Grabber (Direktlink-Download), Outbound-Queue, Accountable-Versand mit Freigabe
- Klassifikator: Direktlink nur Allowlist/https-PDF, Login-/Konsolen-Links -> portal
- grabber.py: INBOX/Archive/Trash readonly, Dedupe Message-ID + SHA-256
- Stichtag GRAB_CUTOFF: Rückblick = pending_review, neu = queued
- mailer.py: SMTP an ACCOUNTABLE_INBOX (ohne Adresse kein Versand)
- /outbound: Liste/xlsx, PDF-Vorschau, approve, run

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-13 21:55:17 +01:00

18 lines
720 B
Python

"""Stufe 2: Rechnungs-PDF per Direktlink laden (Stripe, Paddle, ThriveCart, *.pdf)."""
import urllib.request
from typing import Optional
MAX_BYTES = 20 * 1024 * 1024
def fetch_pdf(url: str, timeout: int = 30) -> Optional[bytes]:
"""-> PDF-Bytes oder None (kein PDF, z.B. HTML-Login-Seite). URL ist bereits per DIRECT_LINK geprüft (nur https)."""
if not url.lower().startswith("https://"):
return None
req = urllib.request.Request(url, headers={"User-Agent": "Mozilla/5.0 (C-Stone Invoice Picker)"})
with urllib.request.urlopen(req, timeout=timeout) as r:
data = r.read(MAX_BYTES + 1)
if len(data) > MAX_BYTES or not data.startswith(b"%PDF-"):
return None
return data