---
type: "Source File"
title: "!/usr/bin/env python3"
description: "#!/usr/bin/env python3 \"\"\"Grandfather every already-indexable article into the publish ledger. Without this, the first time an existing published article is re-analysed or re-linked it would consume one of the five new."
resource: "https://www.copecheck.com"
tags: ["copecheck", "main", "source-file", "py"]
timestamp: "2026-09-25T16:30:37Z"
site: "main"
source_path: "copecheck/seed_publish_ledger.py"
---

# !/usr/bin/env python3

Source path: `copecheck/seed_publish_ledger.py`  
Index snapshot generated: `2026-11-24T13:42:54Z`  
File modified: `2026-09-25T16:30:37Z`

```py
#!/usr/bin/env python3
"""Grandfather every already-indexable article into the publish ledger.

Without this, the first time an existing published article is re-analysed or
re-linked it would consume one of the five new daily slots. Seeding them as
exempt rows dated to their original analysis means the cap only ever governs
genuinely NEW publications.

Writes only to publish_ledger. Does not touch the articles table.
"""
import os
import sys

sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
import db  # noqa: E402
import publish_gate as gate  # noqa: E402

with db.conn() as c:
    gate.ensure_schema(c)
    c.execute("BEGIN IMMEDIATE")
    before = c.execute("SELECT COUNT(*) FROM publish_ledger").fetchone()[0]
    c.execute(
        """INSERT OR IGNORE INTO publish_ledger
             (slug, publish_date, channel, index_status, priority, exempt,
              published_at)
           SELECT slug,
                  substr(COALESCE(analysed_at, created_at), 1, 10),
                  COALESCE(indexed_source, 'rss'),
                  index_status,
                  COALESCE(relevance, 0),
                  1,
                  COALESCE(analysed_at, created_at)
             FROM articles
            WHERE index_status IN ('index', 'trial_index')"""
    )
    after = c.execute("SELECT COUNT(*) FROM publish_ledger").fetchone()[0]
    print(f"ledger rows: {before} -> {after} (seeded {after - before} as exempt)")
    print("cap-consuming rows today:", gate.published_today(c))
    print("slots remaining today:", gate.remaining_today(c))
```
