@tricoteuses/senat 2.11.4 → 2.11.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,9 +9,9 @@ import fs from "fs-extra";
9
9
  import path from "path";
10
10
  import StreamZip from "node-stream-zip";
11
11
  import * as cheerio from "cheerio";
12
- import { AGENDA_FOLDER, COMPTES_RENDUS_FOLDER, DATA_ORIGINAL_FOLDER, DATA_TRANSFORMED_FOLDER, } from "../loaders";
12
+ import { AGENDA_FOLDER, COMPTES_RENDUS_FOLDER, DATA_ORIGINAL_FOLDER, DATA_TRANSFORMED_FOLDER } from "../loaders";
13
13
  import { commonOptions } from "./shared/cli_helpers";
14
- import { deriveTitreObjetFromSommaire, parseCompteRenduSlotFromFile, parseYYYYMMDD, sessionStartYearFromDate } from "../model/seance";
14
+ import { deriveTitreObjetFromSommaire, parseCompteRenduSlotFromFile, parseYYYYMMDD, sessionStartYearFromDate, } from "../model/seance";
15
15
  import { makeGroupUid } from "../utils/reunion_grouping";
16
16
  import { getSessionsFromStart } from "../types/sessions";
17
17
  import { ensureAndClearDir, fetchWithRetry } from "./shared/util";
@@ -22,7 +22,7 @@ const optionsDefinitions = [
22
22
  help: "parse and convert comptes-rendus des débats into JSON",
23
23
  name: "parseDebats",
24
24
  type: Boolean,
25
- }
25
+ },
26
26
  ];
27
27
  const options = commandLineArgs(optionsDefinitions);
28
28
  const CRI_ZIP_URL = "https://data.senat.fr/data/debats/cri.zip";
@@ -151,9 +151,7 @@ export async function retrieveCriXmlDump(dataDir, options = {}) {
151
151
  if (!(await fs.pathExists(originalSessionDir))) {
152
152
  continue;
153
153
  }
154
- const xmlFiles = (await fs.readdir(originalSessionDir))
155
- .filter((f) => /^d\d{8}\.xml$/i.test(f))
156
- .sort();
154
+ const xmlFiles = (await fs.readdir(originalSessionDir)).filter((f) => /^d\d{8}\.xml$/i.test(f)).sort();
157
155
  const transformedSessionDir = path.join(transformedRoot, String(session));
158
156
  if (options["parseDebats"])
159
157
  await fs.ensureDir(transformedSessionDir);
@@ -224,31 +222,30 @@ main()
224
222
  async function linkCriSlotIntoAgendaGrouped(dataDir, yyyymmdd, slot, crUid, cr, session) {
225
223
  const groupedDir = path.join(dataDir, AGENDA_FOLDER, DATA_TRANSFORMED_FOLDER, session.toString());
226
224
  fs.ensureDirSync(groupedDir);
227
- const groupedPath = path.join(groupedDir, 'RUSN' + yyyymmdd + 'IDS-' + slot + '.json');
228
- let groups = [];
225
+ const groupedPath = path.join(groupedDir, `RUSN${yyyymmdd}IDS-${slot}.json`);
226
+ let group = null;
229
227
  if (fs.existsSync(groupedPath)) {
230
228
  try {
231
- groups = JSON.parse(fs.readFileSync(groupedPath, "utf8"));
232
- if (!Array.isArray(groups))
233
- groups = [];
229
+ const parsed = JSON.parse(fs.readFileSync(groupedPath, "utf8"));
230
+ if (Array.isArray(parsed)) {
231
+ // Take correct slot if multiple or first one if no direct match ?
232
+ group = parsed.find((g) => g?.slot === slot) ?? parsed[0] ?? null;
233
+ }
234
+ else {
235
+ group = parsed;
236
+ }
234
237
  }
235
238
  catch (e) {
236
239
  console.warn(`[AGENDA] unreadable grouped JSON → ${groupedPath} (${e}) → recreating`);
237
- groups = [];
240
+ group = null;
238
241
  }
239
242
  }
240
- // find existing group with same slot
241
- const sameSlot = groups.filter(g => g?.slot === slot);
242
- let target = null;
243
- if (sameSlot.length > 1) {
244
- console.warn(`[AGENDA] multiple groups for ${yyyymmdd} ${slot} in ${groupedPath} → linking the first`);
245
- }
246
- target = sameSlot[0] ?? null;
247
243
  const dateISO = `${yyyymmdd.slice(0, 4)}-${yyyymmdd.slice(4, 6)}-${yyyymmdd.slice(6, 8)}`;
248
244
  const sommaire = cr?.metadonnees?.sommaire;
249
245
  const { titre: dTitre, objet: dObjet } = deriveTitreObjetFromSommaire(sommaire, slot);
250
- if (!target) {
251
- const newGroup = {
246
+ // Création si manquant
247
+ if (!group) {
248
+ group = {
252
249
  uid: makeGroupUid(dateISO, slot),
253
250
  chambre: "SN",
254
251
  date: dateISO,
@@ -262,13 +259,10 @@ async function linkCriSlotIntoAgendaGrouped(dataDir, yyyymmdd, slot, crUid, cr,
262
259
  events: [],
263
260
  compteRenduRefUid: crUid,
264
261
  };
265
- groups.push(newGroup);
266
262
  }
267
263
  else {
268
- target.compteRenduRefUid = crUid;
269
- }
270
- await fs.writeJSON(groupedPath, groups, { spaces: 2 });
271
- if (!options["silent"]) {
272
- console.log(`[AGENDA] Linked CR ${crUid} → ${path.basename(groupedPath)} [${slot}]`);
264
+ group.compteRenduRefUid = crUid;
273
265
  }
266
+ await fs.writeJSON(groupedPath, group, { spaces: 2 });
267
+ console.log(`[AGENDA] Linked CR ${crUid} → ${path.basename(groupedPath)} [${slot}]`);
274
268
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tricoteuses/senat",
3
- "version": "2.11.4",
3
+ "version": "2.11.5",
4
4
  "description": "Handle French Sénat's open data",
5
5
  "keywords": [
6
6
  "France",