---
type: "Source File"
title: "!/usr/bin/env python3"
description: "#!/usr/bin/env python3 \"\"\"Quarantine placeholder AI citations and clear the retired Adzuna link.\"\"\" from __future__ import annotations import argparse import json import sqlite3 from datetime import datetime, timezone."
resource: "https://uk.copecheck.com"
tags: ["copecheck", "uk", "source-file", "py"]
timestamp: "2026-08-24T12:57:08Z"
site: "uk"
source_path: "copecheck-uk/quarantine_unverified_ai_tracker.py"
---

# !/usr/bin/env python3

Source path: `copecheck-uk/quarantine_unverified_ai_tracker.py`  
Index snapshot generated: `2026-11-24T13:42:54Z`  
File modified: `2026-08-24T12:57:08Z`

```py
#!/usr/bin/env python3
"""Quarantine placeholder AI citations and clear the retired Adzuna link."""
from __future__ import annotations

import argparse
import json
import sqlite3
from datetime import datetime, timezone
from pathlib import Path


PLACEHOLDER_URLS = (
    "https://www.bbc.co.uk/news/business/bt-ai-jobs",
    "https://www.ft.com/content/bt-group-55000-jobs-ai",
    "https://www.reuters.com/business/finance/hsbc-ai-transformation",
    "https://www.ft.com/content/[redacted]",
    "https://www.legalcheek.com/freshfields-ai-restructure",
    "https://www.legalweek.com/bclp-ai-roles",
    "https://www.theguardian.com/media/reach-plc-ai-redundancies",
    "https://www.bbc.co.uk/news/technology/ibm-ai-jobs",
    "https://www.bbc.co.uk/news/business/vodafone-jobs",
    "https://www.theguardian.com/media/sky-job-cuts-ai",
    "https://www.ft.com/content/lloyds-banking-ai-jobs",
)
BROKEN_ADZUNA_URL = "https://www.adzuna.co.uk/jobs/job-market-report"


def backup_database(db_path: Path) -> Path:
    stamp = datetime.now(timezone.utc).strftime("%Y%m%dT%H%M%SZ")
    backup_path = db_path.with_name(f"{db_path.name}.bak-ai-ledger-quality-{stamp}")
    # The caller holds BEGIN IMMEDIATE.  Back up from a second read connection
    # to capture committed state without stalling on the lock-owning handle.
    with sqlite3.connect(db_path) as source, sqlite3.connect(backup_path) as target:
        source.backup(target)
    return backup_path


def find_rows(connection: sqlite3.Connection) -> list[dict]:
    placeholders = ",".join("?" for _ in PLACEHOLDER_URLS)
    connection.row_factory = sqlite3.Row
    return [dict(row) for row in connection.execute(
        f"""SELECT * FROM ai_redundancy_tracker
              WHERE source_url IN ({placeholders})
              ORDER BY id""",
        PLACEHOLDER_URLS,
    )]


def main() -> int:
    parser = argparse.ArgumentParser()
    parser.add_argument("--db", required=True, type=Path)
    parser.add_argument("--apply", action="store_true")
    args = parser.parse_args()

    database = (
        sqlite3.connect(args.db)
        if args.apply
        else sqlite3.connect(args.db.resolve().as_uri() + "?mode=ro", uri=True)
    )
    with database as connection:
        if args.apply:
            connection.execute("BEGIN IMMEDIATE")
        rows = find_rows(connection)
        adzuna_links = connection.execute(
            "SELECT COUNT(*) FROM adzuna_snapshot WHERE source_url = ?",
            (BROKEN_ADZUNA_URL,),
        ).fetchone()[0]
        summary = {
            "database": str(args.db),
            "mode": "apply" if args.apply else "dry-run",
            "rows": len(rows),
            "companies": [row.get("company") for row in rows],
            "adzuna_broken_links_cleared": adzuna_links if args.apply else 0,
            "adzuna_broken_links_found": adzuna_links,
        }
        if args.apply and (rows or adzuna_links):
            summary["backup"] = str(backup_database(args.db))
        if args.apply and rows:
            connection.execute("""
                CREATE TABLE IF NOT EXISTS ai_redundancy_tracker_quarantine (
                    quarantine_id INTEGER PRIMARY KEY AUTOINCREMENT,
                    original_id INTEGER UNIQUE NOT NULL,
                    company TEXT NOT NULL,
                    sector TEXT,
                    announced_date TEXT,
                    roles_cut INTEGER,
                    ai_cited INTEGER,
                    source_url TEXT,
                    classification TEXT,
                    notes TEXT,
                    created_at TEXT,
                    reason TEXT NOT NULL,
                    quarantined_at TEXT DEFAULT CURRENT_TIMESTAMP
                )
            """)
            ids = [row["id"] for row in rows]
            for row in rows:
                connection.execute("""
                    INSERT OR IGNORE INTO ai_redundancy_tracker_quarantine (
                        original_id, company, sector, announced_date, roles_cut,
                        ai_cited, source_url, classification, notes, created_at,
                        reason
                    ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
                """, (
                    row["id"], row["company"], row.get("sector"),
                    row.get("announced_date"), row.get("roles_cut"),
                    row.get("ai_cited"), row.get("source_url"),
                    row.get("classification"), row.get("notes"),
                    row.get("created_at"),
                    "legacy seed citation was placeholder/non-reproducible",
                ))
            placeholders = ",".join("?" for _ in ids)
            connection.execute(
                f"DELETE FROM ai_redundancy_tracker WHERE id IN ({placeholders})",
                ids,
            )
        if args.apply and adzuna_links:
            connection.execute(
                "UPDATE adzuna_snapshot SET source_url = NULL WHERE source_url = ?",
                (BROKEN_ADZUNA_URL,),
            )
        if args.apply:
            connection.commit()

    print(json.dumps(summary, indent=2, sort_keys=True))
    return 0


if __name__ == "__main__":
    raise SystemExit(main())
```
