@tricoteuses/arbre-de-la-loi
Version:
Generate ASTs from the French bills & laws; manipulate & export them to Markdown, etc.
53 lines (52 loc) • 1.59 kB
JavaScript
import assert from "assert";
import commandLineArgs from "command-line-args";
import fetch from "node-fetch";
// import inspectUnist from "unist-util-inspect"
import xastFromXml from "xast-util-from-xml";
import { billFromSenatAkomaNtosoXast } from "../senat_akoma_ntoso_parser";
const optionsDefinitions = [
{
alias: "b",
help: "signet of Sénat bill to fetch and convert",
name: "bill",
type: String,
},
{
alias: "s",
help: "don't log anything",
name: "silent",
type: Boolean,
},
{
alias: "v",
help: "verbose logs",
name: "verbose",
type: Boolean,
},
{
defaultOption: true,
help: "directory where to store the parsed bill",
name: "dir",
type: String,
},
];
const options = commandLineArgs(optionsDefinitions);
async function main() {
const billSignet = options.bill;
// const dir = options.dir
const billUrl = `https://www.senat.fr/akomantoso/${billSignet}.akn.xml`;
if (!options.silent) {
console.log(`Retrieving Sénat bill at ${billUrl}…`);
}
const response = await fetch(billUrl);
assert(response.ok, `${response.status} ${response.statusText}`);
const billXml = await response.text();
const billXast = xastFromXml(billXml);
// console.log(inspectUnist.noColor(billXast, {showPositions: false}))
const bill = billFromSenatAkomaNtosoXast(billXast);
console.log(JSON.stringify(bill, null, 2));
}
main().catch((error) => {
console.log(error);
process.exit(1);
});