---
type: "Source File"
title: "!/usr/bin/env python3"
description: "#!/usr/bin/env python3 \"\"\" Run the curated CopeCheck Labs institutional report scanners. This is used by the VPS systemd timer so Goldman Sachs, McKinsey, Accenture, Deloitte, PwC, and BCG reports are scored without."
resource: "https://labs.copecheck.com"
tags: ["copecheck", "labs", "source-file", "py"]
timestamp: "2026-09-26T09:43:36Z"
site: "labs"
source_path: "labs/tools/scan_report_sources.py"
---

# !/usr/bin/env python3

Source path: `labs/tools/scan_report_sources.py`  
Index snapshot generated: `2026-11-24T13:27:52Z`  
File modified: `2026-09-26T09:43:36Z`

```py
#!/usr/bin/env python3
"""
Run the curated CopeCheck Labs institutional report scanners.

This is used by the VPS systemd timer so Goldman Sachs, McKinsey, Accenture,
Deloitte, PwC, and BCG reports are scored without relying on a browser click.
"""
import argparse
import json
import sys
from pathlib import Path

ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT))

from server import REPORT_SCANNER_SOURCES, score_all_report_scanner_sources, score_scanner_source  # noqa: E402


# Error text produced by server.fetch_report_bytes / the article gateway when the
# *source* is the problem rather than this job: an HTTP status refusal, a
# DNS/connection/timeout failure, an oversized or non-public target. Matching on
# these keeps a 403 from a publisher out of the job's exit code.
_UPSTREAM_MARKERS = (
    "returned http ",
    "could not fetch",
    "article gateway",
    "timed out",
    "timeout",
    "too large",
    "redirected to a private",
)


def _is_upstream_block(detail: str) -> bool:
    text = (detail or "").lower()
    return any(marker in text for marker in _UPSTREAM_MARKERS)


def main() -> int:
    parser = argparse.ArgumentParser(description="Run CopeCheck Labs report scanners")
    parser.add_argument("--source", choices=[source["id"] for source in REPORT_SCANNER_SOURCES], help="Run one scanner source")
    parser.add_argument("--limit", type=int, default=2, help="Reports per source to score")
    args = parser.parse_args()

    if args.source:
        payload = score_scanner_source(args.source, args.limit)
    else:
        payload = score_all_report_scanner_sources(args.limit)

    print(json.dumps(payload, ensure_ascii=False, indent=2))
    scans = payload if isinstance(payload, list) else [payload]

    blocked, broken, scored = [], [], 0
    for scan in scans:
        name = scan.get("source", {}).get("name", "unknown")
        scored += len(scan.get("results") or [])
        errors = scan.get("errors") or []
        if not errors:
            continue
        details = [str(item.get("error", "")) for item in errors]
        if all(_is_upstream_block(detail) for detail in details):
            blocked.append((name, details))
        else:
            broken.append((name, details))

    for name, details in blocked:
        print(
            "source unavailable (upstream blocked or unreachable, not a job failure): "
            + "%s - %s" % (name, "; ".join(sorted(set(details)))),
            file=sys.stderr,
        )
    for name, details in broken:
        print(
            "source FAILED (needs looking at): "
            + "%s - %s" % (name, "; ".join(sorted(set(details)))),
            file=sys.stderr,
        )

    # Exit non-zero only for genuine breakage, so a red run actually means
    # something needs looking at. A source refusing to serve us (PwC has
    # returned 403 on both of its curated URLs) is an upstream condition: the
    # scan itself succeeded for every other source. The estate check's
    # freshness monitor on data/report-submissions.jsonl is the backstop if
    # every source were to stop responding, and the zero-results guard below
    # catches a wholesale outage immediately.
    if broken:
        return 1
    if scored == 0:
        print(
            "Scanner produced no scored reports at all across %d source(s)" % len(scans),
            file=sys.stderr,
        )
        return 1
    if blocked:
        print(
            "Scan completed; %d of %d source(s) unavailable upstream: %s"
            % (len(blocked), len(scans), ", ".join(name for name, _ in blocked)),
            file=sys.stderr,
        )
    return 0


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