UNPKG

@tricoteuses/senat

Version:

Handle French Sénat's open data

33 lines (32 loc) 1.17 kB
import { JSDOM } from "jsdom"; function transformCompteRendu(document, debat) { const compteRendu = { sections: [], }; for (const section of debat.sections) { const compteRenduSection = { id: section.id, interventions: [], }; compteRendu.sections.push(compteRenduSection); for (const sectionIntervention of section.interventions) { const interventionAnchor = document.querySelector(`a[name="int${sectionIntervention.id}"]`); const interventionParent = interventionAnchor?.parentElement; compteRenduSection.interventions.push({ id: sectionIntervention.id, texteHtml: interventionParent?.outerHTML || null, }); } } return compteRendu; } export async function parseCompteRenduFromFile(htmlFilePath, debat) { try { const { document } = (await JSDOM.fromFile(htmlFilePath, { contentType: "text/html" })).window; return transformCompteRendu(document, debat); } catch (error) { console.error(`Could not parse compte-rendu with error ${error}`); } return null; }