---
type: "Source File"
title: "!/usr/bin/env python3"
description: "#!/usr/bin/env python3 \"\"\"READ-ONLY: quantify each candidate pruning tier for CopeCheck. Opens every database read-only. Changes nothing. \"\"\" import json import os import sqlite3 HERE =."
resource: "https://www.copecheck.com"
tags: ["copecheck", "main", "source-file", "py"]
timestamp: "2026-09-25T16:33:27Z"
site: "main"
source_path: "copecheck/prune_tiers.py"
---

# !/usr/bin/env python3

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

```py
#!/usr/bin/env python3
"""READ-ONLY: quantify each candidate pruning tier for CopeCheck.

Opens every database read-only. Changes nothing.
"""
import json
import os
import sqlite3

HERE = os.path.dirname(os.path.abspath(__file__))
DB = os.path.join(HERE, "data", "copecheck.db")
AN = os.path.join(HERE, "data", "analytics.db")
GSC = os.path.join(HERE, "data", "search-console-page-stats.json")

c = sqlite3.connect(f"file:{DB}?mode=ro", uri=True)
c.row_factory = sqlite3.Row
c.execute(f"ATTACH DATABASE 'file:{AN}?mode=ro' AS an")

# Real (non-automated) human traffic per slug.
c.execute("""CREATE TEMP TABLE real AS
  SELECT replace(substr(path,4),'/','') slug, COUNT(*) hits,
[redacted secret-like line]
         SUM(CASE WHEN referrer LIKE '%google.%' OR referrer LIKE '%bing.%'
                   OR referrer LIKE '%duckduckgo%' THEN 1 ELSE 0 END) organic
    FROM an.pageviews
   WHERE path LIKE '/v/%'
     AND user_agent LIKE 'Mozilla/%'
     AND user_agent NOT LIKE '%bot%' AND user_agent NOT LIKE '%Bot%'
     AND user_agent NOT LIKE '%spider%' AND user_agent NOT LIKE '%crawl%'
     AND user_agent NOT LIKE '%HeadlessChrome%'
   GROUP BY 1""")
c.execute("CREATE INDEX temp.ix_real ON real(slug)")

gsc = set()
try:
    pages = json.load(open(GSC))["pages"]
    gsc = {k[3:] for k, v in pages.items()
           if k.startswith("/v/") and v.get("impressions", 0) > 0}
except Exception as e:
    print("GSC snapshot unavailable:", e)
c.execute("CREATE TEMP TABLE gsc(slug TEXT PRIMARY KEY)")
c.executemany("INSERT OR IGNORE INTO gsc VALUES (?)", [(s,) for s in gsc])

IDX = "index_status IN ('index','trial_index')"


def q(sql):
    return c.execute(sql).fetchone()[0]


def ex(sql, n=3):
    return [r[0] for r in c.execute(sql + f" LIMIT {n}").fetchall()]


TOTAL = q("SELECT COUNT(*) FROM articles")
INDEXABLE = q(f"SELECT COUNT(*) FROM articles WHERE {IDX}")

print("=" * 72)
print(f"CORPUS: {TOTAL} articles | {INDEXABLE} indexable "
      f"| {TOTAL - INDEXABLE} already noindex")
print("=" * 72)

tiers = []


def tier(code, label, where, note):
    n = q(f"SELECT COUNT(*) FROM articles WHERE {where}")
    ni = q(f"SELECT COUNT(*) FROM articles WHERE ({where}) AND {IDX}")
    samples = ex(f"SELECT title FROM articles WHERE ({where}) "
                 "ORDER BY created_at DESC")
    tiers.append((code, label, n, ni, note, samples))
    print(f"\n[{code}] {label}")
    print(f"      total matching: {n:>6}   of which INDEXABLE: {ni:>5}")
    print(f"      {note}")
    for s in samples:
        print(f"        · {(s or '')[:78]}")


print("\n" + "-" * 72)
print("TIER 1 — OBVIOUSLY SAFE (no editorial judgement required)")
print("-" * 72)

tier("1a", "Quarantined: extraction failed (consent walls, blocks, stubs)",
     "status='quarantined'",
     "Not real articles. Body is a cookie/consent page, not content.")

tier("1b", "Never analysed: no verdict, no one-liner, no score",
     "status='pending' AND (verdict_md IS NULL OR trim(verdict_md)='')",
     "Scanner ingested them but the Oracle never produced a verdict.")

tier("1c", "Exact duplicate titles (keeping the earliest of each group)",
     """slug IN (SELECT slug FROM (
          SELECT slug, ROW_NUMBER() OVER (
            PARTITION BY title_hash ORDER BY created_at ASC) rn
            FROM articles WHERE title_hash IS NOT NULL) WHERE rn>1)""",
     "Same normalised headline already covered by an earlier entry.")

print("\n" + "-" * 72)
print("TIER 2 — LOW RISK (thin or unproven, all evidence points one way)")
print("-" * 72)

tier("2a", "INDEXABLE but body under 500 chars",
     f"{IDX} AND LENGTH(COALESCE(body,'')) < 500",
     "Too little text to rank for anything; classic thin-content signal.")

tier("2b", "Stuck in 'review': high signal but never earned a search impression",
     "index_status='review'",
     "Already withheld from the index; confirms the review bucket works.")

tier("2c", "INDEXABLE with ZERO real human pageviews ever",
     f"{IDX} AND slug NOT IN (SELECT slug FROM real)",
     "Excludes GuzzleHttp/bot traffic. Nobody has ever read these.")

print("\n" + "-" * 72)
print("TIER 3 — JUDGEMENT CALLS (valid content, just no demand yet)")
print("-" * 72)

tier("3a", "INDEXABLE, >90 days old, no organic entry AND no GSC impression",
     f"""{IDX} AND julianday('now') - julianday(created_at) > 90
         AND slug NOT IN (SELECT slug FROM real WHERE organic > 0)
         AND slug NOT IN (SELECT slug FROM gsc)""",
     "Had a full quarter to prove itself in search and did not.")

tier("3b", "INDEXABLE, >90 days old, fewer than 3 unique human visitors",
     f"""{IDX} AND julianday('now') - julianday(created_at) > 90
         AND slug IN (SELECT slug FROM real WHERE uniq < 3)""",
     "Real but negligible demand. Consolidation candidates.")

tier("3c", "Aggregator/syndicated sources (HN, arXiv listings, Google Alerts)",
     "index_reason LIKE '%aggregator or syndicated%'",
     "Already noindex. Listed to show the syndication tail is handled.")

print("\n" + "=" * 72)
print("CUMULATIVE EFFECT ON THE INDEXABLE SET")
print("=" * 72)

keep1 = q(f"""SELECT COUNT(*) FROM articles WHERE {IDX}
  AND status <> 'quarantined'
  AND slug NOT IN (SELECT slug FROM (
        SELECT slug, ROW_NUMBER() OVER (
          PARTITION BY title_hash ORDER BY created_at ASC) rn
          FROM articles WHERE title_hash IS NOT NULL) WHERE rn>1)""")
keep2 = q(f"""SELECT COUNT(*) FROM articles WHERE {IDX}
  AND status <> 'quarantined'
  AND LENGTH(COALESCE(body,'')) >= 500
  AND slug IN (SELECT slug FROM real)""")
keep3 = q(f"""SELECT COUNT(*) FROM articles WHERE {IDX}
  AND status <> 'quarantined'
  AND LENGTH(COALESCE(body,'')) >= 500
  AND (slug IN (SELECT slug FROM real WHERE organic > 0)
       OR slug IN (SELECT slug FROM gsc)
       OR julianday('now') - julianday(created_at) <= 90
       OR slug IN (SELECT slug FROM real WHERE uniq >= 3))""")

print(f"  today                          {INDEXABLE:>6} indexable")
print(f"  after Tier 1                   {keep1:>6} indexable")
print(f"  after Tier 1+2                 {keep2:>6} indexable")
print(f"  after Tier 1+2+3               {keep3:>6} indexable")
print(f"\n  whole-corpus rows stay at {TOTAL} unless Ben chooses deletion; "
      "all tiers above are index decisions.")

print("\n" + "=" * 72)
print("PROVEN-VALUE CORE (what is definitely earning its keep)")
print("=" * 72)
print("  indexable w/ organic search entry :",
      q(f"SELECT COUNT(*) FROM articles WHERE {IDX} "
        "AND slug IN (SELECT slug FROM real WHERE organic>0)"))
print("  indexable w/ GSC impressions      :",
      q(f"SELECT COUNT(*) FROM articles WHERE {IDX} "
        "AND slug IN (SELECT slug FROM gsc)"))
print("  indexable w/ >=10 unique humans   :",
      q(f"SELECT COUNT(*) FROM articles WHERE {IDX} "
        "AND slug IN (SELECT slug FROM real WHERE uniq>=10)"))
print("  linked to figure cope evidence    :",
      q("SELECT COUNT(*) FROM articles WHERE indexed_source='curated'"))
c.close()
```
