@tricoteuses/senat 2.22.12 → 2.22.14

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.
@@ -33,14 +33,8 @@ export type IterItem<T> = {
33
33
  export declare function iterFilePaths(dirPath: string): Generator<string>;
34
34
  export declare function iterLoadSenatAmendements(dataDir: string, session: number | undefined, options?: {}): Generator<IterItem<AmendementResult>>;
35
35
  export declare function iterLoadSenatDebats(dataDir: string, session: number | undefined, options?: {}): Generator<IterItem<DebatResult>>;
36
- export declare function iterLoadSenatComptesRendusSeances(dataDir: string, session: number): Generator<{
37
- compteRendu: CompteRendu;
38
- session: number;
39
- }>;
40
- export declare function iterLoadSenatComptesRendusCommissions(dataDir: string, session: number): Generator<{
41
- compteRendu: CompteRendu;
42
- session: number;
43
- }>;
36
+ export declare function iterLoadSenatComptesRendusSeances(dataDir: string, session: number | undefined, options?: {}): Generator<IterItem<CompteRendu>>;
37
+ export declare function iterLoadSenatComptesRendusCommissions(dataDir: string, session: number, options?: {}): Generator<IterItem<CompteRendu>>;
44
38
  export declare function iterLoadSenatDossiersLegislatifs(dataDir: string, session: number | undefined, options?: {}): Generator<IterItem<DossierLegislatifResult>>;
45
39
  export declare function iterLoadSenatRapportUrls(dataDir: string, session: number | undefined): Generator<IterItem<DocumentMetadata>>;
46
40
  export declare function iterLoadSenatTexteUrls(dataDir: string, session: number | undefined): Generator<IterItem<DocumentMetadata>>;
@@ -118,33 +118,15 @@ export function* iterLoadSenatDebats(dataDir, session, options = {}) {
118
118
  yield debatItem;
119
119
  }
120
120
  }
121
- function* iterLoadSenatComptesRendusGeneric(dataDir, session, subFolder) {
122
- const basePath = path.join(dataDir, subFolder, DATA_TRANSFORMED_FOLDER, String(session));
123
- if (!fs.existsSync(basePath)) {
124
- return;
125
- }
126
- const files = (fs.readdirSync(basePath) || []).filter((f) => f.endsWith(".json")).sort();
127
- for (const fileName of files) {
128
- const filePath = path.join(basePath, fileName);
129
- try {
130
- const fileContent = fs.readFileSync(filePath, "utf-8");
131
- const compteRendu = JSON.parse(fileContent);
132
- if (!compteRendu?.uid) {
133
- console.warn(`[SN] CR without uid → ${fileName}`);
134
- continue;
135
- }
136
- yield { compteRendu, session };
137
- }
138
- catch (err) {
139
- console.warn(`[SN] error reading CR → ${fileName}`, err);
140
- }
121
+ export function* iterLoadSenatComptesRendusSeances(dataDir, session, options = {}) {
122
+ for (const compteRenduItem of iterLoadSenatItems(dataDir, COMPTES_RENDUS_FOLDER, session, DATA_TRANSFORMED_FOLDER, options)) {
123
+ yield compteRenduItem;
141
124
  }
142
125
  }
143
- export function* iterLoadSenatComptesRendusSeances(dataDir, session) {
144
- yield* iterLoadSenatComptesRendusGeneric(dataDir, session, COMPTES_RENDUS_FOLDER);
145
- }
146
- export function* iterLoadSenatComptesRendusCommissions(dataDir, session) {
147
- yield* iterLoadSenatComptesRendusGeneric(dataDir, session, COMMISSION_FOLDER);
126
+ export function* iterLoadSenatComptesRendusCommissions(dataDir, session, options = {}) {
127
+ for (const compteRenduItem of iterLoadSenatItems(dataDir, COMMISSION_FOLDER, session, DATA_TRANSFORMED_FOLDER, options)) {
128
+ yield compteRenduItem;
129
+ }
148
130
  }
149
131
  export function* iterLoadSenatDossiersLegislatifs(dataDir, session, options = {}) {
150
132
  for (const dossierLegislatifItem of iterLoadSenatItems(dataDir, datasets.dosleg.database, session, DOSLEG_DOSSIERS_FOLDER, options)) {
@@ -11,6 +11,7 @@ import { sessionStartYearFromDate } from "../model/seance";
11
11
  import { getSessionsFromStart } from "../types/sessions";
12
12
  import { ensureAndClearDir, fetchWithRetry } from "./shared/util";
13
13
  import { jaccard, jaccardTokenSim } from "../utils/scoring";
14
+ import * as git from "../git.js";
14
15
  class CommissionCRDownloadError extends Error {
15
16
  constructor(message, url) {
16
17
  super(`An error occurred while retrieving Commission CR ${url}: ${message}`);
@@ -104,6 +105,15 @@ async function discoverCommissionWeeklyPages(fromSession) {
104
105
  }
105
106
  return results.sort((a, b) => a.yyyymmdd.localeCompare(b.yyyymmdd));
106
107
  }
108
+ function commitAndPushGit(datasetDir, options) {
109
+ let exitCode = 10; // 0: some data changed, 10: no modification
110
+ if (options.commit) {
111
+ const errorCode = git.commitAndPush(datasetDir, "Nouvelle moisson", options.remote);
112
+ if ((exitCode === 10 && errorCode !== 10) || (exitCode === 0 && errorCode !== 0 && errorCode !== 10)) {
113
+ exitCode = errorCode;
114
+ }
115
+ }
116
+ }
107
117
  function toHourShort(hhmm) {
108
118
  if (!hhmm)
109
119
  return null;
@@ -348,6 +358,8 @@ async function retrieveCommissionCRs(options = {}) {
348
358
  }
349
359
  }
350
360
  }
361
+ const debatsDir = path.join(dataDir, COMMISSION_FOLDER, DATA_TRANSFORMED_FOLDER);
362
+ commitAndPushGit(debatsDir, options);
351
363
  }
352
364
  async function main() {
353
365
  const dataDir = options["dataDir"];
@@ -17,6 +17,7 @@ import { getSessionsFromStart } from "../types/sessions";
17
17
  import { ensureAndClearDir, fetchWithRetry } from "./shared/util";
18
18
  import { isNoiseBlock, scoreSommaireBlockForEvent } from "../utils/scoring";
19
19
  import { parseYYYYMMDD } from "../utils/date";
20
+ import * as git from "../git.js";
20
21
  const optionsDefinitions = [
21
22
  ...commonOptions,
22
23
  {
@@ -204,6 +205,17 @@ export async function retrieveCriXmlDump(dataDir, options = {}) {
204
205
  }
205
206
  }
206
207
  }
208
+ const debatsDir = path.join(dataDir, COMPTES_RENDUS_FOLDER, DATA_TRANSFORMED_FOLDER);
209
+ commitAndPushGit(debatsDir, options);
210
+ }
211
+ function commitAndPushGit(datasetDir, options) {
212
+ let exitCode = 10; // 0: some data changed, 10: no modification
213
+ if (options.commit) {
214
+ const errorCode = git.commitAndPush(datasetDir, "Nouvelle moisson", options.remote);
215
+ if ((exitCode === 10 && errorCode !== 10) || (exitCode === 0 && errorCode !== 0 && errorCode !== 10)) {
216
+ exitCode = errorCode;
217
+ }
218
+ }
207
219
  }
208
220
  async function linkCriEventIntoAgenda(dataDir, yyyymmdd, agendaEventId, crUid, cr, session) {
209
221
  const agendadDir = path.join(dataDir, AGENDA_FOLDER, DATA_TRANSFORMED_FOLDER, session.toString());
@@ -4,7 +4,8 @@ import commandLineArgs from "command-line-args";
4
4
  import fs from "fs-extra";
5
5
  import fsp from "fs/promises";
6
6
  import path from "path";
7
- import { iterLoadSenatAgendas } from "../loaders";
7
+ import * as git from "../git.js";
8
+ import { AGENDA_FOLDER, DATA_TRANSFORMED_FOLDER, iterLoadSenatAgendas } from "../loaders";
8
9
  import { getSessionsFromStart } from "../types/sessions";
9
10
  import { commonOptions } from "./shared/cli_helpers";
10
11
  import { getAgendaSegmentTimecodes, buildSenatVodMasterM3u8FromNvs } from "../utils/nvs-parsing";
@@ -168,6 +169,17 @@ async function processAll(dataDir, sessions) {
168
169
  }
169
170
  }
170
171
  }
172
+ const debatsDir = path.join(dataDir, AGENDA_FOLDER, DATA_TRANSFORMED_FOLDER);
173
+ commitAndPushGit(debatsDir, options);
174
+ }
175
+ function commitAndPushGit(datasetDir, options) {
176
+ let exitCode = 10; // 0: some data changed, 10: no modification
177
+ if (options.commit) {
178
+ const errorCode = git.commitAndPush(datasetDir, "Nouvelle moisson", options.remote);
179
+ if ((exitCode === 10 && errorCode !== 10) || (exitCode === 0 && errorCode !== 0 && errorCode !== 10)) {
180
+ exitCode = errorCode;
181
+ }
182
+ }
171
183
  }
172
184
  async function main() {
173
185
  const dataDir = options["dataDir"];
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,17 @@
1
+ import fs from "fs";
2
+ import os from "os";
3
+ import path from "path";
4
+ import { describe, it, expect } from "vitest";
5
+ import { COMPTES_RENDUS_FOLDER, DATA_TRANSFORMED_FOLDER, iterLoadSenatComptesRendusSeances } from "../src/loaders";
6
+ describe("iterLoadSenatComptesRendusSeances", () => {
7
+ it("loads comptes rendus from transformed/session folder", () => {
8
+ const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "senat-cr-"));
9
+ const session = 2025;
10
+ const targetDir = path.join(tmpDir, COMPTES_RENDUS_FOLDER, DATA_TRANSFORMED_FOLDER, String(session));
11
+ fs.mkdirSync(targetDir, { recursive: true });
12
+ fs.writeFileSync(path.join(targetDir, "cr-1.json"), JSON.stringify({ uid: "cr-1", titre: "CR 1" }), "utf8");
13
+ const results = Array.from(iterLoadSenatComptesRendusSeances(tmpDir, session));
14
+ expect(results).toHaveLength(1);
15
+ expect(results[0].item.uid).toBe("cr-1");
16
+ });
17
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tricoteuses/senat",
3
- "version": "2.22.12",
3
+ "version": "2.22.14",
4
4
  "description": "Handle French Sénat's open data",
5
5
  "keywords": [
6
6
  "France",
@@ -63,7 +63,7 @@
63
63
  "prepare": "npm run build",
64
64
  "prepublishOnly": "npm run build",
65
65
  "prettier": "prettier --write 'src/**/*.ts'",
66
- "test:iter_load": "tsx src/scripts/test_iter_load.ts",
66
+ "test:iter_load": "vitest tests/test_iter_load.test.ts",
67
67
  "type-check": "tsc --noEmit",
68
68
  "type-check:watch": "npm run type-check -- --watch",
69
69
  "test:video-matching": "vitest tests/videoMatching.test.ts"