Files
hirnli/scripts/programme-verify.ts
CatoandClaude Opus 5.5 493f7f7cc0 feat(programmes): public funding programmes beside foundations and investors (#223)
* wip(programmes): the programme schema; the theme matcher moves into the app

Work in progress on a branch with no pull request yet. The theme matcher
(keywords and compounds of an organisation's themes) moves from scripts/lib
into src/lib/domain so public programmes are matched by the same rule as
foundations; the script re-exports it. The programme schema follows the
investor register: every fact with its page, date and verbatim sentence.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmtMwPqoAJ2pHxdSn3t

* feat(programmes): public funding programmes beside foundations and investors

Seven federal, cantonal and EU programmes, read on 2026-12-01 from the
operators' own pages: Innosuisse (three instruments), the EIC Accelerator
via Euresearch, the federal media-literacy grants (Jugend und Medien), and
the canton of Zurich's integration projects and charitable fund. Every fact
carries the page, the day and the sentence it rests on; every sentence was
checked against the downloaded page. What a page does not say is named with
the reason; six programmes looked for and not entered are listed with why.

- Table fundraising_programmes (migration 0023), import script (dry run
  unless --write), and a re-check script that reads every cited page again
  and fails when a quoted sentence is gone.
- Workspace page: open programmes first, then those whose own words hit the
  organisation's themes, by the same keyword rule as the register screen
  (moved to src/lib/domain/theme-match.ts). A programme that asks for an
  organisation is marked for one that has no legal entity yet; programmes
  are now one of the kinds the legal-standing notice names.
- A grant Vorhaben links to the programmes as well as the foundations.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmtMwPqoAJ2pHxdSn3t

* feat(programmes): the seven programmes load with the deploy

Migration 0024 inserts the rows of data/programmes/seed-2026-12-01.json, so
the register is filled when this goes live and nobody runs an import by
hand. A test keeps the migration identical to the sourced data file; ON
CONFLICT DO NOTHING never puts a row back to this first reading once a
later re-check has updated it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmtMwPqoAJ2pHxdSn3t

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-12-01 14:28:49 +01:00

71 lines
2.4 KiB
TypeScript
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env tsx
/**
* Re-read every page a programme row cites and check its quote is still there.
*
* Programme rules change: a deadline passes, a programme period ends, a page
* moves. A row whose sentence is no longer on its page is a lead, not a fact,
* until somebody reads it again. Reads public pages only; writes nothing.
*
* Usage:
* pnpm exec tsx scripts/programme-verify.ts data/programmes/seed-2026-12-01.json
*
* Exit code 1 when any quote is missing or a page does not answer.
*/
import * as fs from 'fs';
import { programmeSeedFileSchema, type Programme } from '../src/lib/schemas/programme';
const FIELDS = ['funds', 'whoMayApply', 'amount', 'ownContribution', 'deadlines'] as const;
/** Page text as a reader sees it: tags out, entities and odd spaces normalised. */
export function pageText(html: string): string {
return html
.replace(/<[^>]+>/g, ' ')
.replace(/&nbsp;|&#160;/g, ' ')
.replace(/&amp;/g, '&')
.replace(/&quot;/g, '"')
.replace(/&#39;|&#x27;|&rsquo;|’/g, "'")
.replace(/[  ]/g, ' ')
.replace(/‑/g, '-')
.replace(/\s+/g, ' ');
}
async function main() {
const file = process.argv.slice(2).find((a) => a.endsWith('.json'));
if (!file) {
console.error('Usage: tsx scripts/programme-verify.ts <file.json>');
process.exit(1);
}
const { programmes } = programmeSeedFileSchema.parse(JSON.parse(fs.readFileSync(file, 'utf-8')));
const pages = new Map<string, string | null>();
let failures = 0;
for (const p of programmes as Programme[]) {
for (const field of FIELDS) {
const fact = p[field];
if (!fact?.quote) continue;
if (!pages.has(fact.sourceUrl)) {
const res = await fetch(fact.sourceUrl).catch(() => null);
pages.set(fact.sourceUrl, res?.ok ? pageText(await res.text()) : null);
}
const text = pages.get(fact.sourceUrl);
const ok = text !== null && text !== undefined && text.includes(pageText(fact.quote));
if (!ok) failures++;
console.log(
`${ok ? 'ok ' : 'MISS'} ${p.id} ${field}${text === null ? ' (page did not answer)' : ''}`,
);
}
}
console.log(
`\n${failures === 0 ? 'Every quote is on its page.' : `${failures} quote(s) not found.`}`,
);
process.exit(failures === 0 ? 0 : 1);
}
if (process.argv[1]?.endsWith('programme-verify.ts')) {
main().catch((err) => {
console.error(err);
process.exit(1);
});
}