changing-the-scraperlisted
Install: claude install-skill ontech7/ollama-usage
# Changing the scraper
## Overview
Ollama exposes **no public usage API**. The numbers come from scraping the
logged-in settings page HTML. That makes the parser the most fragile part of the
project, and the rule that keeps it usable is: **a page change must degrade, not
crash.**
Files: `src/ollama_usage/parser.py`, `src/ollama_usage/fetch.py`,
fixture `tests/fixtures/settings.html`.
## What the parser reads
```
[data-usage-meter] ← parent; the reset time is its sibling
└─ [data-usage-track] aria-label="Session usage 2.2% used"
└─ [data-usage-segment] data-model="…" data-requests="12"
[data-time="2026-08-04T16:30:00Z"] ← next sibling of the meter
```
- `identifier`: `"session"` in the aria-label → `5h`; `"weekly"` → `weekly`.
- `pct_used`: first `([\d.]+)%` match in the aria-label.
- `reset_at`: `data-time` parsed as ISO 8601 (`Z` → `+00:00`).
- `models`: each segment's `data-model` / `data-requests`.
## The degradation rule
Every failure path returns *less data*, never an exception:
| Broken input | Behaviour |
|---|---|
| aria-label unknown or without a `%` | **skip that track**, keep the others |
| `data-time` unparseable | `reset_at = None` |
| `data-requests` not an integer | `requests = 0` |
| segment without `data-model` | segment skipped |
| no `[data-usage-meter]` parent | `reset_at = None` |
Keep this shape. A parser that raises turns a cosmetic page tweak into a
`status` line that says `🦙 Unexpected Error` for every user