Update grao

From atanasster/electionsbg · View interactive version

Update grao is an AI agent skill from the GitHub repository atanasster/electionsbg. Refresh the ГРАО settlement-level registered-population data (data/grao_population.json) — re-fetch the latest quarterly "по постоянен и настоящ адрес" table from grao.bg and join settlement names to EKATTE. Use when the daily watch report flags "ГРАО" as changed, when the user asks to refresh ГРАО

How to use this skill

Skill file

Update ГРАО skill

<!-- pipeline-pointer:start (generated from the registry; edit scripts/pipeline/registry) -->

Pipeline: handler CODE0 runs this unattended — pnpm run pipeline:ingest --only update-grao. The registry holds its commands, gates and publish set; this runbook covers what a script cannot do (operator steps, judgement calls, troubleshooting). When a step fails, start from the repair packet the run writes, not from the procedure below.

<!-- pipeline-pointer:end -->

Refreshes data/grao_population.json — per-settlement (EKATTE) population by permanent and current address, the only frequently-updated population source below municipality grain between the decennial censuses.

Source contract:

| Field | Source | Granularity | Cadence |

|---|---|---|---|

| permanent, current | ГРАО t41nm-DD-MM-YYYY_N.txt table at grao.bg/tables.html | settlement (EKATTE) — ~5,100 settlements | quarterly (+ annual 15 Dec) |

The ГРАО file is plain text, Windows-1251 encoded, pipe-delimited, organised as per-municipality област … община … blocks. It carries no EKATTE codes — scripts/grao/fetch.ts joins each settlement name to EKATTE within its oblast via data/settlements.json.

When to run

| Trigger | Action |

|---|---|

| Daily watcher reports ГРАО: ... new quarterly table | Step 1 |

| User asks to "refresh ГРАО" / "update settlement population" | Step 1 |

| Fresh clone with no data/grao_population.json | Step 1 |

ГРАО publishes the settlement table four times a year (quarterly, plus a year-end table on 15 December). Day-to-day there is nothing to do.

Step 1 — Fetch

pnpm exec tsx scripts/grao/fetch.ts          # uses the cached raw file if present
pnpm exec tsx scripts/grao/fetch.ts --force  # re-download the raw .txt

The script resolves the most recent t41nm file from the ГРАО index, downloads it to raw_data/grao/, decodes Windows-1251, parses the per-municipality blocks, joins settlement names → EKATTE, and writes the full bundle data/grao_population.json plus one ~1 KB slice per municipality under data/grao/<obshtina>.json (what the settlement pages actually fetch).

Expected output:

ГРАО latest settlement table: t41nm-15-03-2026_2.txt (2026-03-15)
Parsed ~5,140 settlement rows.
Joined ~5,115 / ~5,140 rows to EKATTE (~23 unmatched, ~22 ambiguous).
Wrote .../data/grao_population.json + ~272 per-municipality slices to .../data/grao/ (~5,106 settlements as of 2026-03-15).

Step 2 — Verify

node -e "
const g = require('./data/grao_population.json');
const codes = Object.keys(g.settlements);
console.log('asOf      ', g.asOf);
console.log('settlements', codes.length);
const s = g.settlements['56784']; // Plovdiv
console.log('Plovdiv (56784)', JSON.stringify(s));
"

Eyeball:

Step 3 — Upload to bucket

pnpm run bucket:sync:dry   # preview
pnpm run bucket:sync       # rsync data/ to gs://data-electionsbg-com/

Step 4 — Commit

git add data/grao_population.json data/grao/
git commit -m "grao: refresh settlement population through <asOf>"

Known limitations

What this skill does NOT do

File map

| Path | Purpose |

|---|---|

| scripts/grao/fetch.ts | CLI entry — fetch, decode, parse, join, write |

| raw_data/grao/t41nm-*.txt | cached raw ГРАО file (Windows-1251) |

| data/grao_population.json | full bundle — per-EKATTE permanent + current population |

| data/grao/<obshtina>.json | per-municipality slices (~1 KB) — fetched by settlement pages |

| scripts/watch/sources/grao.ts | daily watcher — fingerprints the latest quarterly table |

| src/data/grao/useGraoPopulation.tsx | React Query hook |

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.