From 96bf16f7a7c5c00c1cfcc04f60107424021b56e3 Mon Sep 17 00:00:00 2001 From: Mark Eaton Date: Wed, 13 Aug 2025 12:46:57 -0400 Subject: [PATCH] feat: add option to exclude specific files from language stats totals Co-authored-by: aider (o3) --- scripts/language_stats.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/scripts/language_stats.py b/scripts/language_stats.py index 4a7bec6..cc6b511 100644 --- a/scripts/language_stats.py +++ b/scripts/language_stats.py @@ -30,6 +30,12 @@ if not BASE_URL or not TOKEN or not USERNAME: session = requests.Session() session.headers["Authorization"] = f"token {TOKEN}" +# List of files whose byte-counts should be excluded from the totals. +# Each tuple: (repository_name, file_path, language_name) +EXCLUDE_FILES: list[tuple[str, str, str]] = [ + ("ar-scavenger-hunt", "static/aframe.js", "JavaScript"), +] + # ---------- collect repositories ---------- page = 1 repos = [] @@ -57,6 +63,20 @@ for repo in repos: for lang, bytes_ in langs.items(): totals[lang] += bytes_ +# ---------- subtract excluded files ---------- +for repo_name, file_path, language in EXCLUDE_FILES: + try: + meta = session.get( + f"{BASE_URL}/api/v1/repos/{USERNAME}/{repo_name}/contents/{file_path}", + timeout=30, + ) + if meta.ok: + size = meta.json().get("size", 0) + totals[language] = max(0, totals[language] - size) + except requests.RequestException: + # Ignore failures – continue with best-effort stats + pass + total_bytes = sum(totals.values()) if total_bytes == 0: sys.exit("No language data returned from API.")