diff --git a/scripts/language_stats.py b/scripts/language_stats.py index 203a8b7..133a44d 100644 --- a/scripts/language_stats.py +++ b/scripts/language_stats.py @@ -142,12 +142,26 @@ def aggregate_language_bytes(session: requests.Session, repos: list[dict]) -> di totals: dict[str, int] = defaultdict(int) for repo in repos: - langs = session.get( + resp = session.get( f"{BASE_URL}/api/v1/repos/{USERNAME}/{repo['name']}/languages", timeout=30, - ).json() + ) + if not resp.ok: + # Skip repos we can't access (e.g., token scope limitations) + print(f"Warning: Could not fetch languages for {repo['name']}: {resp.status_code}", file=sys.stderr) + continue + langs = resp.json() + # Skip error responses (e.g., {"message": "..."}) + if not isinstance(langs, dict) or "message" in langs: + print(f"Warning: Unexpected response for {repo['name']}: {langs}", file=sys.stderr) + continue for lang, bytes_ in langs.items(): - totals[lang] += int(bytes_) + # Handle bytes as either int or string + if isinstance(bytes_, int): + totals[lang] += bytes_ + elif isinstance(bytes_, str) and bytes_.isdigit(): + totals[lang] += int(bytes_) + # Skip non-numeric values return dict(totals)