---
type: "Source File"
title: "!/usr/bin/env python3"
description: "#!/usr/bin/env python3 \"\"\" Rescore all existing analyzed articles against tracked figures. Re-runs _crosslink_figures on each article with the loosened quality gates. Run: cd /home/ben/infra/copecheck && source .env &&."
resource: "https://www.copecheck.com"
tags: ["copecheck", "main", "source-file", "py"]
timestamp: "2026-05-11T09:01:36Z"
site: "main"
source_path: "copecheck/rescore_all.py"
---

# !/usr/bin/env python3

Source path: `copecheck/rescore_all.py`  
Index snapshot generated: `2026-11-24T13:42:54Z`  
File modified: `2026-05-11T09:01:36Z`

```py
#!/usr/bin/env python3
"""
Rescore all existing analyzed articles against tracked figures.
Re-runs _crosslink_figures on each article with the loosened quality gates.
Run: cd /home/ben/infra/copecheck && source .env && python3 rescore_all.py
"""
import logging
import time
import sys

logging.basicConfig(
    level=logging.INFO,
    format="%(asctime)s %(levelname)s %(name)s | %(message)s",
    handlers=[logging.StreamHandler()],
)
log = logging.getLogger("rescore")

import db
import pipeline

db.init()
pipeline.sync_figures()

# Get all analyzed articles
with db.conn() as c:
    cur = c.execute(
        "SELECT * FROM articles WHERE status = 'analysed' AND body IS NOT NULL ORDER BY id ASC"
    )
    articles = [dict(r) for r in cur.fetchall()]

log.info("Rescoring %d analyzed articles against all tracked figures...", len(articles))

total_new = 0
errors = 0
for i, article in enumerate(articles):
    if i % 50 == 0 and i > 0:
        # Check progress
        with db.conn() as c:
            cur = c.execute("SELECT COUNT(*) FROM cope_entries")
            n_entries = cur.fetchone()[0]
        log.info("Progress: %d/%d articles processed, %d cope entries so far",
                 i, len(articles), n_entries)
    try:
        # Build a fake oracle_result (not needed by _crosslink_figures but
        # the function signature expects it — it only uses article_row though)
        oracle_result = {"verdict_md": article.get("verdict_md", "")}
        pipeline._crosslink_figures(article, oracle_result)
    except Exception as e:
        errors += 1
        log.warning("Error on article %s: %s", article.get("slug", "?")[:40], e)
        if errors > 20:
            log.error("Too many errors, aborting")
            break

# Final count
with db.conn() as c:
    cur = c.execute("SELECT COUNT(*) FROM cope_entries")
    final_entries = cur.fetchone()[0]
    cur = c.execute("SELECT COUNT(DISTINCT figure_id) FROM cope_entries")
    figures_with_entries = cur.fetchone()[0]
    cur = c.execute(
        "SELECT f.name, f.cope_score, f.total_quotes FROM figures f "
        "WHERE f.total_quotes > 0 ORDER BY f.total_quotes DESC"
    )
    scored_figures = cur.fetchall()

log.info("=== RESCORE COMPLETE ===")
log.info("Total cope entries: %d", final_entries)
log.info("Figures with entries: %d", figures_with_entries)
log.info("Errors: %d", errors)
log.info("")
log.info("Top scored figures:")
for fig in scored_figures:
    log.info("  %s: score=%.1f, quotes=%d", fig[0], fig[1], fig[2])
```
