mirror of
https://github.com/bitbaum/hirnli.git
synced 2026-12-04 04:47:15 +01:00
* 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>
77 lines
2.4 KiB
TypeScript
77 lines
2.4 KiB
TypeScript
#!/usr/bin/env tsx
|
|
/**
|
|
* Import the public programme register from a curated seed file.
|
|
*
|
|
* A DRY RUN unless `--write` is given. Validates every row against
|
|
* programmeSchema (a fact without its page, date and sentence is refused; a
|
|
* missing fact must say why) and refuses the whole file on one bad row.
|
|
*
|
|
* Usage:
|
|
* pnpm exec tsx scripts/programme-import.ts data/programmes/seed-2026-12-01.json
|
|
* DATABASE_URL=… pnpm exec tsx scripts/programme-import.ts <file> --write
|
|
*/
|
|
|
|
import * as fs from 'fs';
|
|
import { programmeSeedFileSchema } from '../src/lib/schemas/programme';
|
|
|
|
async function main() {
|
|
const args = process.argv.slice(2);
|
|
const write = args.includes('--write');
|
|
const file = args.find((a) => a.endsWith('.json'));
|
|
if (!file || !fs.existsSync(file)) {
|
|
console.error('Usage: tsx scripts/programme-import.ts <file.json> [--write]');
|
|
process.exit(1);
|
|
}
|
|
|
|
const parsed = programmeSeedFileSchema.safeParse(JSON.parse(fs.readFileSync(file, 'utf-8')));
|
|
if (!parsed.success) {
|
|
console.error(`${file} is not a valid programme list. Nothing was written.`);
|
|
for (const issue of parsed.error.issues.slice(0, 20)) {
|
|
console.error(` ${issue.path.join('.')}: ${issue.message}`);
|
|
}
|
|
process.exit(1);
|
|
}
|
|
const { programmes, dropped, curation } = parsed.data;
|
|
|
|
const ids = new Set<string>();
|
|
for (const p of programmes) {
|
|
if (ids.has(p.id)) {
|
|
console.error(`Duplicate id '${p.id}'. Nothing was written.`);
|
|
process.exit(1);
|
|
}
|
|
ids.add(p.id);
|
|
}
|
|
|
|
console.log(
|
|
`\n${file}\n Curation: ${curation}\n Rows: ${programmes.length} Dropped: ${dropped.length}\n`,
|
|
);
|
|
for (const p of programmes) {
|
|
const missing = Object.keys(p.notSourced);
|
|
console.log(
|
|
` ${p.id.padEnd(52)} not sourced: ${missing.length ? missing.join(', ') : 'none'}`,
|
|
);
|
|
}
|
|
|
|
if (!write) {
|
|
console.log('\n DRY RUN. Nothing was written. Pass --write to upsert.\n');
|
|
return;
|
|
}
|
|
|
|
const { sql, closeDb } = await import('./lib/db');
|
|
for (const p of programmes) {
|
|
await sql`
|
|
INSERT INTO fundraising_programmes (id, name, data, updated_at)
|
|
VALUES (${p.id}, ${p.name}, ${JSON.stringify(p)}::jsonb, now())
|
|
ON CONFLICT (id) DO UPDATE
|
|
SET name = EXCLUDED.name, data = EXCLUDED.data, updated_at = now()
|
|
`;
|
|
}
|
|
await closeDb();
|
|
console.log(`\n Upserted ${programmes.length} programmes.\n`);
|
|
}
|
|
|
|
main().catch((err) => {
|
|
console.error('Programme import failed:', err);
|
|
process.exit(1);
|
|
});
|