Skip to content

The collector · Python 3.12

One codebase, two very different sites, one clean catalogue.

SPP is a nested folder tree of numeric IDs. PJM is a set of committee pages with year tabs and an AJAX materials feed. Each site has its own small source adapter that yields the same RemoteFile record. Everything after discovery (skip, download, hash, version, unzip, catalogue) is shared, tested once and works the same for both. Adding MISO or ERCOT later means one new adapter and a few lines of config.

  1. 01

    Discover

    Walk each configured SPP folder recursively (server-rendered HTML, no headless browser) and each PJM committee page, its year tabs and the library listings. Only Appendix A / B containers, never outside links.

  2. 02

    Scope

    Keep files posted on or after --since (default 2025-01-01). Apply the special rules: Tariff Studies → DPA- files + the two ATSS subfolders, FERC Dockets excluded, www2.pjm.com never touched.

  3. 03

    Skip

    Each listing has a fingerprint (URL + listed size + date). If it matches the ledger and the file is on disk, it's skipped with zero requests. That's what makes incremental runs idempotent.

  4. 04

    Download

    Streamed to a temp file with SHA-256 computed on the fly, one request every 2 s per host plus jitter, 5 retries with exponential backoff and Retry-After honoured.

  5. 05

    Version

    Same URL but a new hash means a new revision. The old file stays, the new one is saved as name.rev2.ext and gets its own row. Nothing is ever overwritten.

  6. 06

    Expand

    Every .zip is kept and expanded next to itself. Each member is a row with parent_zip, nested zips are opened too and zip-slip paths are rejected. Office files (docx/xlsx/pptx) are documents, never unpacked.

  7. 07

    Catalogue

    documents.csv is rebuilt atomically from the SQLite ledger with the brief's exact 15 columns. Misses and the per-container coverage report go to _reports/.

  8. Result

    A folder tree you can drop into Google Drive or Dropbox, plus a documents.csv your RAG pipeline can ingest directly.

    See the 15 columns →

Commands

python -m lareg_iso_collector <command>

  • backfill --since 2025-01-01Full collection of everything posted on or after the date
  • incrementalOnly new or changed files since the last run. Safe to schedule daily
  • verifyThe brief's acceptance checks: every row's file exists, hashes match, zips expanded, counts reconcile
  • spot-check -n 10Re-reads 10 random rows per ISO against the live sites (title, posting date, URL)
  • statusLast runs, totals and any open misses
  • rebuild-csvRegenerate documents.csv from the ledger at any time
  • backfill --spp-folders 31491 --pjm-pages committees/mrcScope a run to specific folders or pages
  • backfill --dry-runDiscover and report what would be collected, without downloading
  • publish-supabase / export-portalOptional: push the catalog to a database or this portal

Folder tree delivered

mirrors each site's own structure
LaReg_ISO_Document_Collection/
├── documents.csv                     ← one row per file (and per zip member)
├── SPP/
│   └── Engineering & Planning/
│       └── ITP Postings/
│           ├── 75723_2025 ITP Short Term Reliability Comments.zip   ← zip kept
│           └── 75723_2025 ITP Short Term Reliability Comments__unzipped/
│               └── Comments - Evergy.pdf                            ← member row
├── PJM/
│   └── committees-groups/committees/mrc/
│       └── 2026/20261118/
│           ├── 20261118-agenda.pdf
│           └── 20261118-item-01-sata-package.rev2.pdf              ← new revision
└── _reports/
    ├── coverage_report.csv           ← files listed vs in scope, per container
    ├── misses.csv                    ← anything that failed, retried next run
    └── verify_report.json

Polite by design

Throttling and robots.txt, visible in the code

The brief asks for both to be visible in the code, so here they are, straight from http.py. Every request, including robots.txt itself, passes through one per-host gate.

Per-host throttle

def _throttle(self, host: str) -> None:
    """Block until this host may receive another request."""
    interval = self.cfg.min_interval_seconds + random.uniform(0, self.cfg.jitter_seconds)
    last = self._last.get(host)
    if last is not None:
        wait = interval - (self._clock() - last)
        if wait > 0:
            self.stats["throttle_wait_s"] += wait
            self._sleep(wait)
    self._last[host] = self._clock()

robots.txt + blocked hosts

def allowed(self, url: str) -> bool:
    parts = urlsplit(url)
    host = (parts.hostname or "").lower()
    if host in self.blocked_hosts:          # www2.pjm.com -> never requested
        return False
    if not self.respect_robots:
        return True
    parser = self._robots_for(parts.scheme or "https", parts.netloc.lower())
    return True if parser is None else parser.can_fetch(self.cfg.user_agent, url)

collector.yaml (excerpt)

http:
  user_agent: "LaRegISOCollector/1.0 (public-document research; polite crawler)"
  min_interval_seconds: 2.0     # ~1 request every 2 s per host
  jitter_seconds: 0.4
  read_timeout: 180             # PJM pages can take ~15 s
  max_retries: 5
sources:
  spp:
    folders: [18275, 18343, 18208, 79866, 31491, …]   # Appendix A
    exclude_folder_name_patterns: ["(?i)ferc\\s*dockets?"]
    folder_rules:
      "18372": { direct_file_name_prefixes: ["DPA-"],
                 include_subfolders_named: ["ATSS Documents", "ATSS Backlog Clearing Process"] }
  pjm:
    respect_robots_txt: true
    blocked_hosts: [www2.pjm.com]
    pages: { committees: [teac, pc, mrc, …], task-forces: [destf, …] }   # Appendix B

Acceptance criteria

Every check in the brief is a command you can run

✓Idempotent incremental mode

A second incremental run downloads nothing and changes no rows. A ledger of URL + SHA-256 makes it so.

✓Every row has its file

The verify command re-hashes each local_path. content_sha256 is unique per distinct file.

✓Zips expanded, zip kept

Each member becomes its own row with parent_zip set. Nested zips are opened too and zip-slip is blocked.

✓Counts and sizes reconcile

Per-site file count and total bytes from the CSV match the folder tree on disk.

✓10-row live spot-check

spot-check -n 10 re-reads the live listing for title, posting date and source_url.

✓Throttle + robots.txt in code

One request every 2 s per host with jitter, Retry-After honoured, pjm.com robots.txt and sitemap respected.

Run history

from the collector's own ledger

RunModeSinceStatusStarted (UTC)Finished (UTC)HTTP requests
#1backfill2025-01-01interrupted2026-11-26 08:44:112026-11-26 09:09:49—
#2backfill2025-01-01running2026-11-26 09:09:55——

Built to keep running

Crash-safe and resumable

Files land under a temp name and move into place only after hashing. Stop a run at any point and the next one carries on where it left off.

Built to keep running

Schedule it anywhere

Windows Task Scheduler, cron, or a GitHub Actions nightly job. Incremental mode is safe to run as often as you like.

Built to keep running

Tested end to end

Runs against a local fake SPP/PJM server cover idempotency, revisions, nested zips, zip-slip, retries, robots.txt and tamper detection.