From ClassCharts to Oracle: anatomy of an automated school-data pipeline

How a parent-portal feed with no API becomes a queryable Oracle table — via a browser agent, a normaliser that runs inside the page, a Postgres staging database in Docker, and a small batch bridge into an OCI Autonomous Database.

The short version

ClassCharts parent portal (SPA, no API)
  → OpenClaw browser agent harvests the rendered Activity feed
  → normalise in-page to 17 columns
  → data/activity-normalized.{json,csv}
  → python/load_activity.py
  → Postgres "mydb" on orzo (docker staging)
  → sync_classcharts_activity.py
  → Oracle ADB, schema FOON_DETECT

Every stage is idempotent, every stage has a gate, and the part that runs unattended is deliberately boring: one agent, one run-book, three plain commands.

1. The problem: a feed, not an API

ClassCharts’ parent portal is a mobile-style single-page app. There is no supported API key, no CSV export and no paginated endpoint we can call. What exists is a rendered Activity feed under a hash route:

https://www.classcharts.com/mobile/parent#<pupilId>,behaviour

Everything the pipeline needs is visible text in that feed: a day heading, a signed points bubble, a sentence naming the award or detention, an optional comment, and a trailing time. The browser is therefore not a workaround bolted onto an API — it is the data source.

Authentication is handled once, by hand. The agent drives a managed Chromium profile whose cookies survive browser restarts, so a logged-in session persists. Credentials never enter the repository, a script, a log, or a prompt. If the portal shows a login form during an unattended run, the run stops rather than guessing.

2. Reading the feed

Opening the right view

After login the app lands on /mobile/parent. Because it is hash-routed, the agent deep-links straight to the pupil’s behaviour section instead of clicking through the dashboard. No brittle element ids, no coordinate clicking.

Setting the window

The date range uses a Material-UI picker with a read-only range field. Typing into it fails by design; the field only opens a calendar. The picker is driven by month label and day number, and the dates are computed at run time — the start is a fixed parameter, the end is the machine’s current date:

const startISO = '2026-05-01';
const endISO   = iso(new Date());   // end of window = today

Month arrows are unnamed SVG icon buttons, so they are clicked through the DOM, not through accessibility refs. One subtle bug is worth recording: while the calendar slides between months, the header contains both the outgoing and incoming month, separated by a newline. Parsing the whole string makes the navigation compare against the wrong month and overshoot. Taking the first non-empty line fixes it.

After applying, the script asserts that the header matches the expected range and day count. A mismatch means a click landed in the wrong month, and the run stops.

Harvesting an infinite scroll

The Activity feed is not paginated. Ten rows load per scroll and the document grows by roughly 1,500 px each time. The harvest loop extracts every .activity-entry, scrolls to the bottom, waits, and repeats until the page height stops growing twice in a row. Rows accumulate in a page-level object keyed by iso|time|value|text, which makes re-extraction idempotent.

The completion gate is simple and strong: the number of collected rows must equal the number of .activity-entry nodes in the DOM. If they differ, the dedupe key has collapsed real rows and the run must not continue.

Interpreting a row

  • Day heading: the nearest preceding h6 that is outside any activity entry. Inside a row, h6 is the pupil’s name — a trap that silently corrupts a naive selector.
  • Points bubble: the leaf element whose text matches a signed integer.
  • Polarity: read from the bubble’s computed background colour — green rgb(126,215,93) positive, red rgb(255,74,81) negative, otherwise neutral. Polarity is not inferred from the sign of the number, although the two agree on every row seen so far.
  • Time: the trailing HH:MM; the row’s time[datetime] attribute provides the exact instant.

Three data quirks that must be handled before storage

  1. Detentions lie about time. On a detention row, time[datetime] is not the event instant — it is the detention’s scheduled slot. The calendar date must come from the day heading, and the due date/time must be parsed from the row’s inner Date:/Time: fields.
  2. Notes have no bubble. Rows that say a teacher “left a note” carry no points element. The correct value is NULL, not zero.
  3. The portal returns one extra day. A window starting 1 May includes 30 April. That is the app’s inclusive behaviour, not a parsing error. The loader accepts it; strictness can be applied with a filter if ever needed.

3. Normalising inside the page

Rather than dumping flat text and reparsing it later, the normaliser runs in the page and walks the Activity section in document order, carrying the day heading forward. Each row yields 17 columns:

pupil_id  pupil  activity_date  activity_time  event_at  points  polarity
kind  reason  teacher  class_group  comment
detention_location  detention_type  detention_due_date  detention_due_time
raw_text

Sentences are parsed by grammar, not by position:

Rendered pattern kind reason teacher class
<Award> awarded by <Teacher> in <Class>. award award name yes yes
<Award> awarded by <Teacher>. award award name yes null
Detention issued for <Cause> in <Class> by <Teacher> detention cause yes yes
Detention issued for <Cause> by <Teacher> detention cause yes null
<Teacher> left a note. note “Note” yes null

Detention detail blocks yield location, type, due date and due time. The trailing period on class codes is stripped; everything else stays verbatim. raw_text is the untouched row text, retained for audit and re-parsing — it is also what makes the dedupe hash stable.

The latest verified harvest (25 November 2026) produced 177 rows spanning 30 April to 25 November, with zero rows missing a teacher or reason and kind counts summing to the row count.

4. Staging in Postgres

The landing zone is the mydb database on the LAN host orzo, a Docker-hosted Postgres. Keeping a staging copy has three practical benefits: the browser session and the Oracle wallet never have to be live at the same moment; a bad harvest can be inspected without touching the reporting database; and the loader can be re-run as often as needed without writing to Oracle.

Schema with real constraints

The table is not a generic dumping ground. Its constraints encode rules learned from the source:

  • polarity is limited to positive, negative or neutral.
  • kind is limited to award, detention or note.
  • Points may be null only for notes (there is no bubble to read).
  • Non-detention rows must have all four detention fields null; detentions must have a due date.
  • source_hash must be 32 lowercase hex characters, unique per pupil.

Two indexes cover the obvious access paths: pupil plus date descending, and pupil plus kind plus date. Column comments document where each value came from, including the awkward ones (detention due slot versus issue instant).

Idempotency that is actually tested

The loader computes:

source_hash = md5( event_at in UTC  +  \x1f  +  raw_text )

and inserts with:

ON CONFLICT (pupil_id, source_hash) DO NOTHING
RETURNING id

Every harvest re-reads a whole window, so most rows on a later run already exist. The loader reports inserted and skipped separately, and the apply step runs the loader twice: the second run must insert zero rows. If it inserts anything, the hash is unstable and the pipeline stops. That is a stronger guarantee than “it looked fine once”.

Chunked transport out of the browser

A single evaluate call returning the full normalised array is around 20 KB and gets truncated. The rows are therefore sliced into 43-row chunks, each written to data/.parts/norm-N.json, then merged by a Python subcommand that also enforces the gates: row count, unique hashes, raw_text present, 17 CSV columns, day heading agreeing with activity_date, and kind counts summing correctly. Only after those hold are the JSON and CSV artefacts written.

A dry run inserts inside a transaction, reports counts, then rolls back via a sentinel exception. A real run commits. Both paths validate the same invariants first.

5. Transporting to Oracle

The reporting target is an Oracle Autonomous Database, schema FOON_DETECT, where the data feeds an APEX application. The bridge is a standalone Python script in the APEX repository, deliberately separate from the harvester.

Reading from Postgres

The script opens a named server-side cursor and reads classcharts_activity ordered by id, in batches of 500. A server-side cursor matters: the source table grows, and the bridge should not try to hold the whole history in memory.

Writing to Oracle

For each batch it executes an insert-only MERGE:

merge into foon_detect.classcharts_activity target
using (select :source_id source_id, ... from dual) source_row
on (target.source_id = source_row.source_id)
when not matched then insert (...);

The Postgres identity id is carried across as Oracle’s source_id primary key. That single decision makes the whole bridge idempotent: a row that already exists is ignored, and a row that was never copied is inserted. There is no update path, so a repeated full scan cannot rewrite history.

Type mapping is where these projects usually break

  • Postgres date becomes an Oracle DATE at midnight.
  • Oracle has no TIME type, so activity_time and detention_due_time are stored as varchar2(32) in ISO form.
  • event_at and harvested_at map to timestamp with time zone.
  • comment is renamed activity_comment (the original name is reserved-ish in practice and confusing next to other comments).
  • Free-text fields are CLOB, and the cursor declares those input sizes explicitly so the driver binds them correctly.

The Oracle table mirrors the Postgres uniqueness rule with unique (pupil_id, source_hash), in addition to the source_id primary key. If the same logical row somehow arrives twice under different source ids, Oracle refuses it.

Why a full scan every time

Copying “only ids greater than the last one seen” looks efficient but is wrong under concurrent commits: a transaction with a lower id can commit after a higher one was already read, and the row is missed forever. The bridge therefore scans everything, ordered by id, and lets the merge discard what is already there. At this data volume the cost is trivial; the correctness is not.

Credentials follow the same discipline as the rest of the project: Postgres from the gitignored two-line file, Oracle from an environment variable or the desktop Secret Service keyring, with a wallet and Instant Client in thick mode. Nothing is printed, and --dry-run counts pending rows without writing.

6. The automation: OpenClaw as the operator

The harvest is scheduled as an OpenClaw automation named Classcharts fetch. Its shape matters more than its schedule:

  • Agent: a dedicated classcharts agent, not the main assistant.
  • Session: isolated, so every run starts with a clean context and cannot drift into unrelated work.
  • Schedule: every 5 days — frequent enough to keep the window fresh, sparse enough not to hammer a school portal.
  • Model: a small, fast model; the intelligence is in the run-book, not in improvisation.
  • Delivery: none. The run records its own status; it does not announce itself.

The prompt is an operating procedure

The automation message does not say “scrape ClassCharts”. It names the repository, the reading order (AGENTS.md, then the harvest run-book), and the exact stages: open the portal, confirm the session, deep-link to behaviour, set the computed date range, scroll to exhaustion, run the stage-5 normaliser verbatim, export in 43-row chunks, then run three commands:

python3 python/harvest_tools.py merge
python3 python/load_activity.py --dry-run
python3 python/harvest_tools.py apply

It also defines success and failure in machine-checkable terms: a login page means stop; a header mismatch means stop; apply must report a second run with zero inserts; if nothing new was inserted, reply with silence rather than a notification.

The command contract exists because nobody is watching

This is the least obvious and most important design constraint. The agent runs unattended, so a command that lands in an approval prompt is a failed run. The run-book therefore forbids:

  • cd repo && ... chains, ;, ||, pipes, redirects and heredocs;
  • inline environment prefixes such as VAR=x cmd;
  • ad-hoc scripts written at run time.

One plain command per call, with the working directory passed as a parameter. New logic goes into harvest_tools.py as a subcommand, where it can be reviewed and reused. The result is a pipeline shaped by the permission model rather than fighting it: every step is a single allowlisted invocation, and the run never needs a human to click approve.

What a run actually looks like

At the time of writing the automation’s last run was 25 November 2026, status ok, duration about 161 seconds, next run in four days. That run produced the 177-row harvest described above. The first full load, on 16 November, landed 170 rows covering 1 May to 16 November: 138 awards, 28 detentions and 4 notes.

7. What is automated, and what is not

Being precise about the boundary is worth more than a tidy diagram:

  • Automated: opening the portal, confirming the session, setting the range, harvesting, normalising, merging, dry-running, loading into Postgres, proving idempotency, writing a one-line run note.
  • Not automated: the Postgres → Oracle bridge. sync_classcharts_activity.py is run on demand, with a dry run first. Nothing schedules it today.
  • Human, once: the initial portal login. The managed browser profile keeps the session afterwards.

So the current end-to-end story is “scheduled harvest into staging, deliberate transport into Oracle”. That is a defensible split while the Oracle side is still being shaped, but it is a split: if the bridge is meant to be hands-off, it needs its own step in the automation (after apply) or a second job with its own schedule. Until then, a green automation status only proves that staging is current.

8. Failure modes worth knowing

The run-book carries a “traps already paid for” section, and it earns its place:

  • Browser refs renumber after a restart; never persist them across calls.
  • The calendar’s month arrows have no accessible name; the range input is read-only.
  • The month label contains two months mid-transition; parse the first line.
  • Inside a row, h6 is the pupil’s name; only an h6 outside an entry is a day heading.
  • Detention rows put the scheduled slot in the inner fields; the row timestamp is the issue instant.
  • A hand-written 16-column CSV projection once failed the load because it dropped raw_text; the merge now fixes the column list in one place.
  • Hard-coded calendar months rot. The picker is driven from computed dates, and the run-book records that it previously contained a hard-coded November 2026.

Two operational gaps are worth stating plainly. First, the automation prompt still says to expect the range to end on 16 November 2026, while the run-book computes “today”; the agent copes, but the prompt is stale and should be updated. Second, delivery is set to none, so a failed run does not notify anyone — the failure lives in lastRunStatus/lastError until someone looks. For a pipeline that is supposed to be autonomous, adding a failure notification is probably the next small win.

9. Why this design holds together

Three decisions do most of the work:

  1. Normalise as close to the source as possible. The page knows what a points bubble, a day heading and a detention block are. Doing that work in the page avoids shipping a fragile text parser downstream.
  2. Make every layer idempotent for its own reasons. Postgres dedupes on a content hash; Oracle dedupes on the source primary key. The full re-read at each layer is safe because the writes are insert-only.
  3. Treat the unattended agent as a constrained executor. The run-book, the command contract and the gates exist so a small model can succeed without judgement calls — and fail loudly when the page changes.

The result is not glamorous: a browser, a spreadsheet-shaped table, a second table in a second database, and a scheduler. But it turns a feed that only exists while someone is logged in into history that can be queried, charted and trusted — which is the whole point.

Privacy note: the harvested artefacts contain a real pupil’s school records. data/ is gitignored, only aggregate counts appear in run reports, and no pupil identifiers or credentials are reproduced here.