---
type: "Source File"
title: "!/usr/bin/env python3"
description: "#!/usr/bin/env python3 \"\"\"Rescore the 5 most recent YouTube videos to populate the three-layer verdict fields.\"\"\" import sys import os import json import sqlite3 # Run from the copecheck-uk directory so imports work."
resource: "https://uk.copecheck.com"
tags: ["copecheck", "uk", "source-file", "py"]
timestamp: "2026-08-16T14:50:17Z"
site: "uk"
source_path: "copecheck-uk/rescore_5.py"
---

# !/usr/bin/env python3

Source path: `copecheck-uk/rescore_5.py`  
Index snapshot generated: `2026-11-24T13:42:54Z`  
File modified: `2026-08-16T14:50:17Z`

```py
#!/usr/bin/env python3
"""Rescore the 5 most recent YouTube videos to populate the three-layer verdict fields."""
import sys
import os
import json
import sqlite3

# Run from the copecheck-uk directory so imports work
sys.path.insert(0, '/home/ben/infra/copecheck-uk')
os.chdir('/home/ben/infra/copecheck-uk')

from youtube_scorer import score_video

DB_PATH = '/home/ben/infra/copecheck-uk/data/copecheck_uk.db'

def get_recent_videos(n=5):
    conn = sqlite3.connect(DB_PATH)
    rows = conn.execute(
        "SELECT id, video_id, title FROM youtube_videos ORDER BY id DESC LIMIT ?", (n,)
    ).fetchall()
    conn.close()
    return rows

def update_video(video_id, result):
    conn = sqlite3.connect(DB_PATH)
    conn.execute("""
        UPDATE youtube_videos SET
            cope_score       = ?,
            cope_summary     = ?,
            video_summary    = ?,
            dt_verdict       = ?,
            butchers_verdict = ?,
            scapegoats       = ?,
            cope_mechanisms  = ?,
            key_quotes       = ?,
            transcript_length= ?,
            status           = 'scored',
            scored_at        = CURRENT_TIMESTAMP
        WHERE video_id = ?
    """, (
        result.get('cope_score'),
        result.get('cope_summary') or result.get('summary', ''),
        result.get('video_summary', ''),
        result.get('dt_verdict', ''),
        result.get('butchers_verdict', ''),
        result.get('scapegoats', ''),
        result.get('cope_mechanisms', ''),
        json.dumps(result.get('key_quotes', [])),
        result.get('transcript_length', 0),
        video_id,
    ))
    conn.commit()
    conn.close()

def main():
    videos = get_recent_videos(5)
    print(f"\n{'='*60}")
    print(f"Rescoring {len(videos)} videos")
    print(f"{'='*60}\n")

    for db_id, video_id, title in videos:
        print(f"\n--- [{db_id}] {title or video_id} ---")
        print(f"    video_id: {video_id}")

        result = score_video(video_id)

        if 'error' in result:
            print(f"    ERROR: {result['error']}")
            continue

        print(f"    cope_score:       {result.get('cope_score')}")
        print(f"    cope_summary:     {(result.get('cope_summary','') or result.get('summary',''))[:120]}...")
        print(f"    video_summary:    {result.get('video_summary','')[:120]}...")
        print(f"    dt_verdict:       {result.get('dt_verdict','')[:120]}...")
        print(f"    butchers_verdict: {result.get('butchers_verdict','')[:120]}...")

        update_video(video_id, result)
        print(f"    DB updated OK")

    print(f"\n{'='*60}")
    print("All done. Verifying DB...")
    print(f"{'='*60}")
    conn = sqlite3.connect(DB_PATH)
    rows = conn.execute("""
        SELECT id, video_id, title, cope_score,
               length(video_summary), length(dt_verdict), length(butchers_verdict)
        FROM youtube_videos ORDER BY id DESC LIMIT 5
    """).fetchall()
    conn.close()
    print(f"\n{'id':<5} {'video_id':<14} {'score':<7} {'vs_len':<8} {'dt_len':<8} {'bv_len':<8} title")
    print("-"*80)
    for r in rows:
        print(f"{r[0]:<5} {r[1]:<14} {str(r[3]):<7} {str(r[4] or 0):<8} {str(r[5] or 0):<8} {str(r[6] or 0):<8} {(r[2] or '')[:40]}")

if __name__ == '__main__':
    main()
```
