@tricoteuses/senat 2.22.11 → 2.22.13

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.
Files changed (138) hide show
  1. package/lib/config.d.ts +21 -0
  2. package/lib/config.js +27 -0
  3. package/lib/databases.d.ts +2 -0
  4. package/lib/databases.js +26 -0
  5. package/lib/datasets.d.ts +34 -0
  6. package/lib/datasets.js +233 -0
  7. package/lib/git.d.ts +26 -0
  8. package/lib/git.js +167 -0
  9. package/lib/index.d.ts +13 -0
  10. package/lib/index.js +1 -0
  11. package/lib/loaders.d.ts +58 -0
  12. package/lib/loaders.js +286 -0
  13. package/lib/model/agenda.d.ts +6 -0
  14. package/lib/model/agenda.js +148 -0
  15. package/lib/model/ameli.d.ts +51 -0
  16. package/lib/model/ameli.js +147 -0
  17. package/lib/model/commission.d.ts +18 -0
  18. package/lib/model/commission.js +269 -0
  19. package/lib/model/debats.d.ts +67 -0
  20. package/lib/model/debats.js +95 -0
  21. package/lib/model/documents.d.ts +12 -0
  22. package/lib/model/documents.js +138 -0
  23. package/lib/model/dosleg.d.ts +7 -0
  24. package/lib/model/dosleg.js +326 -0
  25. package/lib/model/index.d.ts +7 -0
  26. package/lib/model/index.js +7 -0
  27. package/lib/model/questions.d.ts +45 -0
  28. package/lib/model/questions.js +89 -0
  29. package/lib/model/scrutins.d.ts +13 -0
  30. package/lib/model/scrutins.js +114 -0
  31. package/lib/model/seance.d.ts +3 -0
  32. package/lib/model/seance.js +267 -0
  33. package/lib/model/sens.d.ts +146 -0
  34. package/lib/model/sens.js +454 -0
  35. package/lib/model/texte.d.ts +7 -0
  36. package/lib/model/texte.js +228 -0
  37. package/lib/model/util.d.ts +9 -0
  38. package/lib/model/util.js +38 -0
  39. package/lib/parsers/texte.d.ts +7 -0
  40. package/lib/parsers/texte.js +228 -0
  41. package/lib/raw_types/ameli.d.ts +914 -0
  42. package/lib/raw_types/ameli.js +5 -0
  43. package/lib/raw_types/debats.d.ts +207 -0
  44. package/lib/raw_types/debats.js +5 -0
  45. package/lib/raw_types/dosleg.d.ts +1619 -0
  46. package/lib/raw_types/dosleg.js +5 -0
  47. package/lib/raw_types/questions.d.ts +423 -0
  48. package/lib/raw_types/questions.js +5 -0
  49. package/lib/raw_types/senat.d.ts +11372 -0
  50. package/lib/raw_types/senat.js +5 -0
  51. package/lib/raw_types/sens.d.ts +8248 -0
  52. package/lib/raw_types/sens.js +5 -0
  53. package/lib/raw_types_schemats/ameli.d.ts +539 -0
  54. package/lib/raw_types_schemats/ameli.js +2 -0
  55. package/lib/raw_types_schemats/debats.d.ts +127 -0
  56. package/lib/raw_types_schemats/debats.js +2 -0
  57. package/lib/raw_types_schemats/dosleg.d.ts +977 -0
  58. package/lib/raw_types_schemats/dosleg.js +2 -0
  59. package/lib/raw_types_schemats/questions.d.ts +237 -0
  60. package/lib/raw_types_schemats/questions.js +2 -0
  61. package/lib/raw_types_schemats/sens.d.ts +6915 -0
  62. package/lib/raw_types_schemats/sens.js +2 -0
  63. package/lib/scripts/convert_data.d.ts +1 -0
  64. package/lib/scripts/convert_data.js +354 -0
  65. package/lib/scripts/data-download.d.ts +1 -0
  66. package/lib/scripts/data-download.js +12 -0
  67. package/lib/scripts/datautil.d.ts +8 -0
  68. package/lib/scripts/datautil.js +34 -0
  69. package/lib/scripts/parse_textes.d.ts +1 -0
  70. package/lib/scripts/parse_textes.js +44 -0
  71. package/lib/scripts/retrieve_agenda.d.ts +1 -0
  72. package/lib/scripts/retrieve_agenda.js +132 -0
  73. package/lib/scripts/retrieve_cr_commission.d.ts +1 -0
  74. package/lib/scripts/retrieve_cr_commission.js +364 -0
  75. package/lib/scripts/retrieve_cr_seance.d.ts +6 -0
  76. package/lib/scripts/retrieve_cr_seance.js +347 -0
  77. package/lib/scripts/retrieve_documents.d.ts +3 -0
  78. package/lib/scripts/retrieve_documents.js +219 -0
  79. package/lib/scripts/retrieve_open_data.d.ts +1 -0
  80. package/lib/scripts/retrieve_open_data.js +316 -0
  81. package/lib/scripts/retrieve_senateurs_photos.d.ts +1 -0
  82. package/lib/scripts/retrieve_senateurs_photos.js +147 -0
  83. package/lib/scripts/retrieve_videos.d.ts +1 -0
  84. package/lib/scripts/retrieve_videos.js +461 -0
  85. package/lib/scripts/shared/cli_helpers.d.ts +95 -0
  86. package/lib/scripts/shared/cli_helpers.js +91 -0
  87. package/lib/scripts/shared/util.d.ts +4 -0
  88. package/lib/scripts/shared/util.js +35 -0
  89. package/lib/scripts/test_iter_load.d.ts +1 -0
  90. package/lib/scripts/test_iter_load.js +12 -0
  91. package/lib/src/model/sens.d.ts +36 -0
  92. package/lib/src/model/sens.js +35 -4
  93. package/lib/src/scripts/retrieve_cr_commission.js +12 -0
  94. package/lib/src/scripts/retrieve_cr_seance.js +12 -0
  95. package/lib/src/scripts/retrieve_videos.js +13 -1
  96. package/lib/src/utils/nvs-timecode.d.ts +17 -0
  97. package/lib/src/utils/nvs-timecode.js +79 -0
  98. package/lib/src/utils/weights_scoring_config.d.ts +2 -0
  99. package/lib/src/utils/weights_scoring_config.js +15 -0
  100. package/lib/strings.d.ts +1 -0
  101. package/lib/strings.js +18 -0
  102. package/lib/types/agenda.d.ts +44 -0
  103. package/lib/types/agenda.js +1 -0
  104. package/lib/types/ameli.d.ts +5 -0
  105. package/lib/types/ameli.js +1 -0
  106. package/lib/types/compte_rendu.d.ts +83 -0
  107. package/lib/types/compte_rendu.js +1 -0
  108. package/lib/types/debats.d.ts +2 -0
  109. package/lib/types/debats.js +1 -0
  110. package/lib/types/dosleg.d.ts +70 -0
  111. package/lib/types/dosleg.js +1 -0
  112. package/lib/types/questions.d.ts +2 -0
  113. package/lib/types/questions.js +1 -0
  114. package/lib/types/sens.d.ts +10 -0
  115. package/lib/types/sens.js +1 -0
  116. package/lib/types/sessions.d.ts +5 -0
  117. package/lib/types/sessions.js +84 -0
  118. package/lib/types/texte.d.ts +74 -0
  119. package/lib/types/texte.js +16 -0
  120. package/lib/utils/cr_spliting.d.ts +28 -0
  121. package/lib/utils/cr_spliting.js +265 -0
  122. package/lib/utils/date.d.ts +10 -0
  123. package/lib/utils/date.js +100 -0
  124. package/lib/utils/nvs-timecode.d.ts +7 -0
  125. package/lib/utils/nvs-timecode.js +79 -0
  126. package/lib/utils/reunion_grouping.d.ts +11 -0
  127. package/lib/utils/reunion_grouping.js +337 -0
  128. package/lib/utils/reunion_odj_building.d.ts +5 -0
  129. package/lib/utils/reunion_odj_building.js +154 -0
  130. package/lib/utils/reunion_parsing.d.ts +23 -0
  131. package/lib/utils/reunion_parsing.js +209 -0
  132. package/lib/utils/scoring.d.ts +14 -0
  133. package/lib/utils/scoring.js +147 -0
  134. package/lib/utils/string_cleaning.d.ts +7 -0
  135. package/lib/utils/string_cleaning.js +57 -0
  136. package/lib/validators/config.d.ts +9 -0
  137. package/lib/validators/config.js +10 -0
  138. package/package.json +1 -1
@@ -0,0 +1,2 @@
1
+ /* tslint:disable */
2
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,354 @@
1
+ import assert from "assert";
2
+ import commandLineArgs from "command-line-args";
3
+ import fs from "fs-extra";
4
+ import path from "path";
5
+ import pLimit from "p-limit";
6
+ import * as git from "../git";
7
+ import { datasets, EnabledDatasets, getEnabledDatasets } from "../datasets";
8
+ import { DATA_ORIGINAL_FOLDER, DATA_TRANSFORMED_FOLDER, DOCUMENT_METADATA_FILE, DOSLEG_DOSSIERS_FOLDER, SCRUTINS_FOLDER, RAPPORT_FOLDER, SENS_CIRCONSCRIPTIONS_FOLDER, SENS_ORGANISMES_FOLDER, SENS_SENATEURS_FOLDER, TEXTE_FOLDER, } from "../loaders";
9
+ import { findAllAmendements, findAllCirconscriptions, findAllDebats, findAllDossiers, findAllScrutins, findAllOrganismes, findAllQuestions, findAllSens, findAllTextes, findAllRapports, } from "../model";
10
+ import { processRapport, processTexte } from "./retrieve_documents";
11
+ import { buildActesLegislatifs } from "../model/dosleg";
12
+ import { UNDEFINED_SESSION } from "../types/sessions";
13
+ import { getSessionFromDate, getSessionFromSignet } from "./datautil";
14
+ import { commonOptions } from "./shared/cli_helpers";
15
+ import { ensureAndClearDir } from "./shared/util";
16
+ const optionsDefinitions = [...commonOptions];
17
+ const options = commandLineArgs(optionsDefinitions);
18
+ const SENAT_TEXTE_XML_BASE_URL = "https://www.senat.fr/akomantoso/";
19
+ const SENAT_TEXTE_BASE_URL = "https://www.senat.fr/leg/";
20
+ const SENAT_EXPOSE_DES_MOTIFS_BASE_URL = "https://www.senat.fr/leg/exposes-des-motifs/";
21
+ const SENAT_RAPPORT_BASE_URL = "https://www.senat.fr/rap/";
22
+ function commitGit(datasetDir, options, exitCode) {
23
+ if (options.commit) {
24
+ const errorCode = git.commitAndPush(datasetDir, "Nouvelle moisson", options.remote);
25
+ if ((exitCode === 10 && errorCode !== 10) || (exitCode === 0 && errorCode !== 0 && errorCode !== 10)) {
26
+ exitCode = errorCode;
27
+ }
28
+ }
29
+ return exitCode;
30
+ }
31
+ async function convertData() {
32
+ const dataDir = options["dataDir"];
33
+ assert(dataDir, "Missing argument: data directory");
34
+ const enabledDatasets = getEnabledDatasets(options["categories"]);
35
+ console.time("data transformation time");
36
+ let exitCode = 0;
37
+ if (enabledDatasets & EnabledDatasets.Ameli) {
38
+ try {
39
+ await convertDatasetAmeli(dataDir, options);
40
+ const ameliDir = path.join(dataDir, datasets.ameli.database);
41
+ exitCode = commitGit(ameliDir, options, exitCode);
42
+ }
43
+ catch (error) {
44
+ console.error(`Error converting Ameli dataset:`, error);
45
+ }
46
+ }
47
+ if (enabledDatasets & EnabledDatasets.Debats) {
48
+ try {
49
+ await convertDatasetDebats(dataDir, options);
50
+ const debatsDir = path.join(dataDir, datasets.debats.database);
51
+ exitCode = commitGit(debatsDir, options, exitCode);
52
+ }
53
+ catch (error) {
54
+ console.error(`Error converting Debats dataset:`, error);
55
+ }
56
+ }
57
+ if (enabledDatasets & EnabledDatasets.DosLeg) {
58
+ try {
59
+ await convertDatasetDosLeg(dataDir, options);
60
+ const doslegDir = path.join(dataDir, datasets.dosleg.database);
61
+ exitCode = commitGit(doslegDir, options, exitCode);
62
+ }
63
+ catch (error) {
64
+ console.error(`Error converting DosLeg dataset:`, error);
65
+ }
66
+ try {
67
+ await convertDatasetScrutins(dataDir, options);
68
+ const scrutinsDir = path.join(dataDir, SCRUTINS_FOLDER);
69
+ exitCode = commitGit(scrutinsDir, options, exitCode);
70
+ }
71
+ catch (error) {
72
+ console.error(`Error converting Scrutins dataset:`, error);
73
+ }
74
+ }
75
+ if (enabledDatasets & EnabledDatasets.Questions) {
76
+ try {
77
+ await convertDatasetQuestions(dataDir, options);
78
+ const questionsDir = path.join(dataDir, datasets.questions.database);
79
+ exitCode = commitGit(questionsDir, options, exitCode);
80
+ }
81
+ catch (error) {
82
+ console.error(`Error converting Questions dataset:`, error);
83
+ }
84
+ }
85
+ if (enabledDatasets & EnabledDatasets.Sens) {
86
+ try {
87
+ await convertDatasetSens(dataDir, options);
88
+ const sensDir = path.join(dataDir, datasets.sens.database);
89
+ exitCode = commitGit(sensDir, options, exitCode);
90
+ }
91
+ catch (error) {
92
+ console.error(`Error converting Sens dataset:`, error);
93
+ }
94
+ }
95
+ if (!options["silent"]) {
96
+ console.timeEnd("data transformation time");
97
+ }
98
+ return exitCode;
99
+ }
100
+ async function convertDatasetAmeli(dataDir, options) {
101
+ const dataset = datasets.ameli;
102
+ if (!options["silent"]) {
103
+ console.log(`Converting database ${dataset.database} data into files…`);
104
+ }
105
+ const ameliReorganizedRootDir = path.join(dataDir, dataset.database);
106
+ if (!options.keepDir) {
107
+ ensureAndClearDir(ameliReorganizedRootDir);
108
+ }
109
+ for await (const amendement of findAllAmendements(options["fromSession"])) {
110
+ if (options["verbose"]) {
111
+ console.log(`Converting ${amendement["numero"]} file…`);
112
+ }
113
+ const session = String(amendement["session"]) || UNDEFINED_SESSION;
114
+ const signetDossierLegislatif = amendement["signet_dossier_legislatif"] ||
115
+ `${amendement["nature_texte"]}-${amendement["numero_texte"]}`.toLowerCase();
116
+ const amendementFileName = `${amendement["numero"]}.json`;
117
+ const filePath = path.join(ameliReorganizedRootDir, String(session), signetDossierLegislatif, amendementFileName);
118
+ await fs.outputJSON(filePath, amendement, { spaces: 2 });
119
+ }
120
+ }
121
+ async function convertDatasetDebats(dataDir, options) {
122
+ const dataset = datasets.debats;
123
+ if (!options["silent"]) {
124
+ console.log(`Converting database ${dataset.database} data into files…`);
125
+ }
126
+ const debatsReorganizedRootDir = path.join(dataDir, dataset.database);
127
+ if (!options.keepDir) {
128
+ ensureAndClearDir(debatsReorganizedRootDir);
129
+ }
130
+ for await (const debat of findAllDebats()) {
131
+ if (options["verbose"]) {
132
+ console.log(`Converting ${debat.id} file…`);
133
+ }
134
+ const session = getSessionFromDate(debat.date_seance);
135
+ if (options["fromSession"] && session < options["fromSession"]) {
136
+ continue;
137
+ }
138
+ const debatFileName = `${debat.id}.json`;
139
+ const filePath = path.join(debatsReorganizedRootDir, String(session), debatFileName);
140
+ await fs.outputJSON(filePath, debat, { spaces: 2 });
141
+ }
142
+ }
143
+ async function convertDatasetDosLeg(dataDir, options) {
144
+ const dataset = datasets.dosleg;
145
+ if (!options["silent"]) {
146
+ console.log(`Converting database ${dataset.database} data into files…`);
147
+ }
148
+ const doslegReorganizedRootDir = path.join(dataDir, dataset.database);
149
+ const dossiersReorganizedDir = path.join(doslegReorganizedRootDir, DOSLEG_DOSSIERS_FOLDER);
150
+ if (!options.keepDir) {
151
+ ensureAndClearDir(doslegReorganizedRootDir);
152
+ ensureAndClearDir(dossiersReorganizedDir);
153
+ }
154
+ for await (const dossier of findAllDossiers()) {
155
+ if (options["verbose"]) {
156
+ console.log(`Converting ${dossier["signet"]} file…`);
157
+ }
158
+ let dossierReorganizedDir = path.join(dossiersReorganizedDir, String(UNDEFINED_SESSION));
159
+ const session = getSessionFromSignet(dossier["signet"]) || UNDEFINED_SESSION;
160
+ if (options["fromSession"] && session < options["fromSession"]) {
161
+ continue;
162
+ }
163
+ dossierReorganizedDir = path.join(dossiersReorganizedDir, String(session));
164
+ const actesBrutsNormalises = buildActesLegislatifs(dossier);
165
+ const dossierWithActes = {
166
+ ...dossier,
167
+ actes_legislatifs: actesBrutsNormalises,
168
+ };
169
+ const dossierFile = `${dossier["signet"]}.json`;
170
+ await fs.outputJSON(path.join(dossierReorganizedDir, dossierFile), dossierWithActes, { spaces: 2 });
171
+ }
172
+ await convertTextes(dataDir, options);
173
+ await convertRapports(dataDir, options);
174
+ }
175
+ async function convertDatasetScrutins(dataDir, options) {
176
+ const dataset = datasets.dosleg;
177
+ if (!options["silent"]) {
178
+ console.log(`Converting database scrutins (${dataset.database}) data into files…`);
179
+ }
180
+ const scrutinsReorganizedDir = path.join(dataDir, SCRUTINS_FOLDER);
181
+ if (!options.keepDir) {
182
+ ensureAndClearDir(scrutinsReorganizedDir);
183
+ }
184
+ for await (const scrutin of findAllScrutins(options["fromSession"])) {
185
+ if (options["verbose"]) {
186
+ console.log(`Converting ${scrutin["numero"]} file…`);
187
+ }
188
+ let scrutinReorganizedDir = path.join(scrutinsReorganizedDir, String(UNDEFINED_SESSION));
189
+ const session = scrutin["session"] || UNDEFINED_SESSION;
190
+ scrutinReorganizedDir = path.join(scrutinsReorganizedDir, String(session));
191
+ const scrutinFileName = `${scrutin["numero"]}.json`;
192
+ await fs.outputJSON(path.join(scrutinReorganizedDir, scrutinFileName), scrutin, {
193
+ spaces: 2,
194
+ });
195
+ }
196
+ }
197
+ async function convertDatasetQuestions(dataDir, options) {
198
+ const dataset = datasets.questions;
199
+ if (!options["silent"]) {
200
+ console.log(`Converting database ${dataset.database} data into files…`);
201
+ }
202
+ const questionsReorganizedRootDir = path.join(dataDir, dataset.database);
203
+ if (!options.keepDir) {
204
+ ensureAndClearDir(questionsReorganizedRootDir);
205
+ }
206
+ const limit = pLimit(10);
207
+ const tasks = [];
208
+ for await (const question of findAllQuestions()) {
209
+ tasks.push(limit(async () => {
210
+ if (options["verbose"]) {
211
+ console.log(`Converting ${question["reference"]} file…`);
212
+ }
213
+ const legislature = question["legislature"] ? question["legislature"] : 0;
214
+ const questionFileName = `${question["reference"]}.json`;
215
+ await fs.outputJSON(path.join(questionsReorganizedRootDir, String(legislature), questionFileName), question, {
216
+ spaces: 2,
217
+ });
218
+ }));
219
+ }
220
+ await Promise.all(tasks);
221
+ }
222
+ async function convertTextes(dataDir, options) {
223
+ const originalTextesDir = path.join(dataDir, TEXTE_FOLDER, DATA_ORIGINAL_FOLDER);
224
+ const transformedTextesDir = path.join(dataDir, TEXTE_FOLDER, DATA_TRANSFORMED_FOLDER);
225
+ if (!options["silent"]) {
226
+ console.log(`Converting database textes data into files…`);
227
+ }
228
+ for await (const texte of findAllTextes()) {
229
+ const session = texte["session"] ?? UNDEFINED_SESSION;
230
+ if (options["fromSession"] && session < options["fromSession"]) {
231
+ continue;
232
+ }
233
+ if (!texte["url"]) {
234
+ continue;
235
+ }
236
+ const texteName = path.parse(texte["url"]).name;
237
+ const texteDir = path.join(originalTextesDir, `${session}`, texteName);
238
+ // oritxtcod = 1 corresponds to "Texte de loi déposé au Sénat"
239
+ const hasExposeDesMotifs = texte["origine"] === "Sénat" && texte["ordre_origine"] === "1";
240
+ const metadata = {
241
+ name: texteName,
242
+ session: texte["session"],
243
+ date: texte["date"],
244
+ url_expose_des_motifs: hasExposeDesMotifs
245
+ ? new URL(`${texteName}-expose.html`, SENAT_EXPOSE_DES_MOTIFS_BASE_URL)
246
+ : undefined,
247
+ url_xml: new URL(`${texteName}.akn.xml`, SENAT_TEXTE_XML_BASE_URL),
248
+ url_html: new URL(`${texteName}.html`, SENAT_TEXTE_BASE_URL),
249
+ url_pdf: new URL(`${texteName}.pdf`, SENAT_TEXTE_BASE_URL),
250
+ };
251
+ fs.outputJSONSync(path.join(texteDir, `${texteName}.json`), texte, {
252
+ spaces: 2,
253
+ });
254
+ fs.outputJSONSync(path.join(texteDir, DOCUMENT_METADATA_FILE), metadata, {
255
+ spaces: 2,
256
+ });
257
+ if (options.fetchDocuments) {
258
+ await processTexte(metadata, originalTextesDir, transformedTextesDir, options);
259
+ }
260
+ }
261
+ }
262
+ async function convertRapports(dataDir, options) {
263
+ const originalRapportsDir = path.join(dataDir, RAPPORT_FOLDER, DATA_ORIGINAL_FOLDER);
264
+ if (!options["silent"]) {
265
+ console.log(`Converting database rapports data into files…`);
266
+ }
267
+ for await (const rapport of findAllRapports()) {
268
+ const session = rapport["session"] ?? UNDEFINED_SESSION;
269
+ if (options["fromSession"] && session < options["fromSession"]) {
270
+ continue;
271
+ }
272
+ if (!rapport["url"]) {
273
+ continue;
274
+ }
275
+ const parsedRapportUrl = path.parse(rapport["url"]);
276
+ const rapportName = parsedRapportUrl.name;
277
+ const rapportDir = path.join(originalRapportsDir, `${session}`, rapportName);
278
+ const rapportHtmlUrlBase = `${rapportName}_mono.html`;
279
+ const rapportHtmlUrl = path.format({
280
+ dir: parsedRapportUrl.dir,
281
+ base: rapportHtmlUrlBase,
282
+ });
283
+ const rapportPdfUrlBase = `${rapportName}1.pdf`;
284
+ const rapportPdfUrl = path.format({
285
+ dir: parsedRapportUrl.dir,
286
+ base: rapportPdfUrlBase,
287
+ });
288
+ const metadata = {
289
+ name: rapportName,
290
+ session: rapport["session"],
291
+ date: rapport["date"],
292
+ url_html: new URL(rapportHtmlUrl, SENAT_RAPPORT_BASE_URL),
293
+ url_pdf: new URL(rapportPdfUrl, SENAT_RAPPORT_BASE_URL),
294
+ };
295
+ fs.outputJSONSync(path.join(rapportDir, `${rapportName}.json`), rapport, {
296
+ spaces: 2,
297
+ });
298
+ fs.outputJSONSync(path.join(rapportDir, DOCUMENT_METADATA_FILE), metadata, {
299
+ spaces: 2,
300
+ });
301
+ if (options.fetchDocuments) {
302
+ await processRapport(metadata, originalRapportsDir, options);
303
+ }
304
+ }
305
+ }
306
+ async function convertDatasetSens(dataDir, options) {
307
+ const dataset = datasets.sens;
308
+ if (!options["silent"]) {
309
+ console.log(`Converting database ${dataset.database} data into files…`);
310
+ }
311
+ const sensReorganizedRootDir = path.join(dataDir, dataset.database);
312
+ const senateursReorganizedDir = path.join(sensReorganizedRootDir, SENS_SENATEURS_FOLDER);
313
+ const circonscriptionsReorganizedDir = path.join(sensReorganizedRootDir, SENS_CIRCONSCRIPTIONS_FOLDER);
314
+ const organismesReorganizedDir = path.join(sensReorganizedRootDir, SENS_ORGANISMES_FOLDER);
315
+ if (!options.keepDir) {
316
+ ensureAndClearDir(sensReorganizedRootDir);
317
+ ensureAndClearDir(senateursReorganizedDir);
318
+ ensureAndClearDir(circonscriptionsReorganizedDir);
319
+ ensureAndClearDir(organismesReorganizedDir);
320
+ }
321
+ for await (const sen of findAllSens()) {
322
+ if (options["verbose"]) {
323
+ console.log(`Converting ${sen["matricule"]} file…`);
324
+ }
325
+ const senFileName = `${sen["matricule"]}.json`;
326
+ fs.outputJSONSync(path.join(senateursReorganizedDir, senFileName), sen, {
327
+ spaces: 2,
328
+ });
329
+ }
330
+ for await (const circonscription of findAllCirconscriptions()) {
331
+ if (options["verbose"]) {
332
+ console.log(`Converting ${circonscription["identifiant"]} file…`);
333
+ }
334
+ const circonscriptionFileName = `${circonscription["identifiant"]}.json`;
335
+ fs.outputJSONSync(path.join(circonscriptionsReorganizedDir, circonscriptionFileName), circonscription, {
336
+ spaces: 2,
337
+ });
338
+ }
339
+ for await (const organisme of findAllOrganismes()) {
340
+ if (options["verbose"]) {
341
+ console.log(`Converting ${organisme["code"]} file…`);
342
+ }
343
+ const organismeFileName = `${organisme["code"]}.json`;
344
+ fs.outputJSONSync(path.join(organismesReorganizedDir, organisme["type_code"], organismeFileName), organisme, {
345
+ spaces: 2,
346
+ });
347
+ }
348
+ }
349
+ convertData()
350
+ .then((exitCode) => process.exit(exitCode || 0))
351
+ .catch((error) => {
352
+ console.log(error);
353
+ process.exit(1);
354
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,12 @@
1
+ import { execSync } from "child_process";
2
+ const args = process.argv.slice(2).join(" ");
3
+ try {
4
+ execSync(`tsx src/scripts/retrieve_open_data.ts --all ${args}`, { stdio: "inherit" });
5
+ execSync(`tsx src/scripts/convert_data.ts ${args}`, { stdio: "inherit" });
6
+ }
7
+ catch (error) {
8
+ if (error.status !== 10) {
9
+ console.error("Error during data retrieval:", error);
10
+ process.exit(error.status || 1);
11
+ }
12
+ }
@@ -0,0 +1,8 @@
1
+ import { Session } from "../types/sessions";
2
+ export declare const STANDARD_DATE_FORMAT = "yyyy-MM-dd";
3
+ export declare const ID_DATE_FORMAT = "yyyyMMdd";
4
+ export declare const AKN_IDENTIFICATION_STRUCTURE_REGEXP: RegExp;
5
+ export declare const AKN_WORKFLOW_IDENTIFICATION_STRUCTURE_REGEXP: RegExp;
6
+ export declare const SIGNET_STRUCTURE_REGEXP: RegExp;
7
+ export declare function getSessionFromSignet(signet: string): Session | null;
8
+ export declare function getSessionFromDate(date: string, format?: string): Session;
@@ -0,0 +1,34 @@
1
+ import { DateTime, Settings } from "luxon";
2
+ Settings.twoDigitCutoffYear = 50;
3
+ export const STANDARD_DATE_FORMAT = "yyyy-MM-dd";
4
+ export const ID_DATE_FORMAT = "yyyyMMdd";
5
+ export const AKN_IDENTIFICATION_STRUCTURE_REGEXP = /^\/akn\/fr\/(?<type>[a-z]+)\/(?<session>\d{4}-\d{4})\/?(?<numTexte>\d+)\/fr@(?<version>\b(?:RECT|RECT_BIS|RECT_TER|RECT_QUATER|RECT_QUINQUIES)\b)?/;
6
+ export const AKN_WORKFLOW_IDENTIFICATION_STRUCTURE_REGEXP = /^\/akn\/fr\/(?<type>[a-z]+)\/(?<session>\d{2,4})\/?(?<numTexte>[a-zA-Z0-9]+)\/fr@(?<version>\b(?:RECT|RECT_BIS|RECT_TER|RECT_QUATER|RECT_QUINQUIES)\b)?/;
7
+ export const SIGNET_STRUCTURE_REGEXP = /^(?<type>[a-z]+)(?<session>\d{2,4})-?(?<numTexte>\d+)?/;
8
+ export function getSessionFromSignet(signet) {
9
+ const signetParts = SIGNET_STRUCTURE_REGEXP.exec(signet)?.groups;
10
+ if (signetParts && "session" in signetParts) {
11
+ const { session } = signetParts;
12
+ return formatToFourDigitSession(session);
13
+ }
14
+ return null;
15
+ }
16
+ function formatToFourDigitSession(session) {
17
+ if (session.length >= 2) {
18
+ const sessionFirstTwoDigits = session.substring(0, 2);
19
+ const sessionLastTwoDigits = session.substring(session.length - 2);
20
+ const twoDigitSession = parseInt(sessionFirstTwoDigits) === parseInt(sessionLastTwoDigits) - 1
21
+ ? sessionFirstTwoDigits
22
+ : sessionLastTwoDigits;
23
+ return parseInt(DateTime.fromFormat(String(twoDigitSession), "yy").toFormat("yyyy"));
24
+ }
25
+ return null;
26
+ }
27
+ export function getSessionFromDate(date, format = STANDARD_DATE_FORMAT) {
28
+ const parsedDate = DateTime.fromFormat(date, format);
29
+ const endSessionDate = DateTime.fromObject({ year: parsedDate.year, month: 9, day: 30 });
30
+ if (parsedDate < endSessionDate) {
31
+ return (parsedDate.year - 1);
32
+ }
33
+ return parsedDate.year;
34
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,44 @@
1
+ import assert from "assert";
2
+ import commandLineArgs from "command-line-args";
3
+ import fs from "fs-extra";
4
+ import path from "path";
5
+ import { iterFilePaths, TEXTE_FOLDER, DATA_ORIGINAL_FOLDER, DATA_TRANSFORMED_FOLDER } from "../loaders";
6
+ import { parseExposeDesMotifsFromFile, parseTexteFromFile } from "../model/texte";
7
+ import { commonOptions } from "./shared/cli_helpers";
8
+ import { ensureAndClearDir } from "./shared/util";
9
+ const optionsDefinitions = [...commonOptions];
10
+ const options = commandLineArgs(optionsDefinitions);
11
+ async function main() {
12
+ const dataDir = options["dataDir"];
13
+ assert(dataDir, "Missing argument: data directory");
14
+ const transformedTextesDir = path.join(options["dataDir"], TEXTE_FOLDER, DATA_TRANSFORMED_FOLDER);
15
+ ensureAndClearDir(transformedTextesDir);
16
+ for (const filePath of iterFilePaths(path.join(dataDir, TEXTE_FOLDER, DATA_ORIGINAL_FOLDER))) {
17
+ const parsedFilePath = path.parse(filePath);
18
+ if (parsedFilePath.ext !== ".xml") {
19
+ continue;
20
+ }
21
+ const texteDirFromOriginal = parsedFilePath.dir.substring(filePath.indexOf(DATA_ORIGINAL_FOLDER) + DATA_ORIGINAL_FOLDER.length);
22
+ const transformedTexteDir = path.join(transformedTextesDir, texteDirFromOriginal);
23
+ fs.ensureDirSync(transformedTexteDir);
24
+ if (!options["silent"]) {
25
+ console.log(`Parsing texte ${parsedFilePath.name}.xml…`);
26
+ }
27
+ const parsedTexte = await parseTexteFromFile(filePath);
28
+ const exposeDesMotifsFileName = `${parsedFilePath.name}-expose`;
29
+ const exposeDesMotifsFilePath = path.join(parsedFilePath.dir, `${exposeDesMotifsFileName}.html`);
30
+ if (parsedTexte && fs.existsSync(exposeDesMotifsFilePath)) {
31
+ if (!options["silent"]) {
32
+ console.log(`Parsing exposé des motifs ${exposeDesMotifsFileName}.html…`);
33
+ }
34
+ parsedTexte.exposeDesMotifs = await parseExposeDesMotifsFromFile(exposeDesMotifsFilePath);
35
+ }
36
+ fs.writeJSONSync(path.join(transformedTexteDir, `${parsedFilePath.name}.json`), parsedTexte, { spaces: 2 });
37
+ }
38
+ }
39
+ main()
40
+ .then(() => process.exit(0))
41
+ .catch((error) => {
42
+ console.log(error);
43
+ process.exit(1);
44
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,132 @@
1
+ import assert from "assert";
2
+ import commandLineArgs from "command-line-args";
3
+ import fs from "fs-extra";
4
+ import { DateTime } from "luxon";
5
+ import path from "path";
6
+ import { AGENDA_FOLDER, DATA_ORIGINAL_FOLDER, DATA_TRANSFORMED_FOLDER } from "../loaders";
7
+ import { parseAgendaFromFile } from "../model/agenda";
8
+ import { getSessionsFromStart } from "../types/sessions";
9
+ import { ID_DATE_FORMAT } from "./datautil";
10
+ import { commonOptions } from "./shared/cli_helpers";
11
+ import { fetchWithRetry } from "./shared/util";
12
+ import { buildReunionsByBucket } from "../utils/reunion_parsing";
13
+ import { buildSenatDossierIndex } from "../utils/reunion_odj_building";
14
+ const optionsDefinitions = [
15
+ ...commonOptions,
16
+ {
17
+ help: "parse and convert agenda events into JSON",
18
+ name: "parseAgenda",
19
+ type: Boolean,
20
+ },
21
+ ];
22
+ const options = commandLineArgs(optionsDefinitions);
23
+ const SENAT_GLOBAL_AGENDA_URL_ROOT = "https://www.senat.fr/aglae/Global";
24
+ const EVENT_DATE_FORMAT = "ddMMyyyy";
25
+ class AgendaError extends Error {
26
+ constructor(message, agendaName) {
27
+ super(`An error occurred while retrieving Agenda ${agendaName}: ${message}`);
28
+ }
29
+ }
30
+ async function retrieveAgendas(options, sessions) {
31
+ console.log(`[AGENDA] Retrieving agendas for sessions ${sessions.join(", ")}`);
32
+ const agendaRootDir = path.join(options["dataDir"], AGENDA_FOLDER);
33
+ fs.ensureDirSync(agendaRootDir);
34
+ const originalAgendaDir = path.join(agendaRootDir, DATA_ORIGINAL_FOLDER);
35
+ fs.ensureDirSync(originalAgendaDir);
36
+ const transformedAgendaDir = path.join(agendaRootDir, DATA_TRANSFORMED_FOLDER);
37
+ if (options["parseAgenda"]) {
38
+ fs.ensureDirSync(transformedAgendaDir);
39
+ }
40
+ let dossierIndex = {};
41
+ dossierIndex = buildSenatDossierIndex(options);
42
+ for (const session of sessions) {
43
+ const originalAgendaSessionDir = path.join(originalAgendaDir, `${session}`);
44
+ fs.ensureDirSync(originalAgendaSessionDir);
45
+ if (!options["keepDir"])
46
+ fs.emptyDirSync(originalAgendaSessionDir);
47
+ const transformedAgendaSessionDir = path.join(transformedAgendaDir, `${session}`);
48
+ if (options["parseAgenda"]) {
49
+ fs.ensureDirSync(transformedAgendaSessionDir);
50
+ if (!options["keepDir"])
51
+ fs.emptyDirSync(transformedAgendaSessionDir);
52
+ }
53
+ const fifteenDaysFromNow = new Date();
54
+ fifteenDaysFromNow.setDate(fifteenDaysFromNow.getDate() + 15); // Don't download agendas more than 15 days in the future
55
+ for (const date = new Date(session, 9, 1); date <= new Date(session + 1, 8, 30) && date <= fifteenDaysFromNow; date.setDate(date.getDate() + 1)) {
56
+ const agendaName = DateTime.fromJSDate(date).toFormat(EVENT_DATE_FORMAT);
57
+ const agendaFileName = DateTime.fromJSDate(date).toFormat(ID_DATE_FORMAT);
58
+ const agendaPath = path.join(originalAgendaSessionDir, `${agendaFileName}.html`);
59
+ try {
60
+ await downloadAgenda(agendaName, agendaPath);
61
+ if (options["parseAgenda"]) {
62
+ await parseAgenda(transformedAgendaSessionDir, agendaFileName, agendaPath, dossierIndex);
63
+ }
64
+ }
65
+ catch (error) {
66
+ console.error(error);
67
+ }
68
+ }
69
+ }
70
+ }
71
+ async function downloadAgenda(agendaName, agendaPath) {
72
+ const agendaUrl = `${SENAT_GLOBAL_AGENDA_URL_ROOT}/agl${agendaName}.html`;
73
+ if (!options["silent"]) {
74
+ console.log(`Downloading Agenda ${agendaUrl}…`);
75
+ }
76
+ const response = await fetchWithRetry(agendaUrl);
77
+ if (!response.ok) {
78
+ if (response.status === 404) {
79
+ console.warn(`Agenda ${agendaUrl} not found`);
80
+ }
81
+ else {
82
+ throw new AgendaError(String(response.status), agendaName);
83
+ }
84
+ return;
85
+ }
86
+ const agendaContent = await response.arrayBuffer();
87
+ if (!agendaContent) {
88
+ return;
89
+ }
90
+ fs.writeFileSync(agendaPath, Buffer.from(agendaContent));
91
+ }
92
+ function writeGroupsAsFiles(dir, groups) {
93
+ for (const g of groups) {
94
+ const outPath = path.join(dir, `${g.uid}.json`);
95
+ fs.writeJSONSync(outPath, g, { spaces: 2 });
96
+ }
97
+ }
98
+ async function parseAgenda(transformedAgendaSessionDir, agendaFileName, agendaPath, dossierBySenatUrl) {
99
+ if (!options["silent"])
100
+ console.log(`Parsing Agenda ${agendaPath}…`);
101
+ const parsedAgendaEvents = await parseAgendaFromFile(agendaPath);
102
+ if (!parsedAgendaEvents?.length)
103
+ return;
104
+ const flatPath = path.join(transformedAgendaSessionDir, `${agendaFileName}.json`);
105
+ fs.writeJSONSync(flatPath, parsedAgendaEvents, { spaces: 2 });
106
+ const byBucket = buildReunionsByBucket(parsedAgendaEvents, dossierBySenatUrl);
107
+ // SP
108
+ if (byBucket.IDS.length > 0) {
109
+ writeGroupsAsFiles(transformedAgendaSessionDir, byBucket.IDS);
110
+ }
111
+ // NON-SP
112
+ for (const suffix of ["IDC", "IDM", "IDO", "IDI"]) {
113
+ const groups = byBucket[suffix];
114
+ if (groups.length > 0) {
115
+ writeGroupsAsFiles(transformedAgendaSessionDir, groups);
116
+ }
117
+ }
118
+ }
119
+ async function main() {
120
+ const dataDir = options["dataDir"];
121
+ assert(dataDir, "Missing argument: data directory");
122
+ const sessions = getSessionsFromStart(options["fromSession"]);
123
+ console.time("agenda processing time");
124
+ await retrieveAgendas(options, sessions);
125
+ console.timeEnd("agenda processing time");
126
+ }
127
+ main()
128
+ .then(() => process.exit(0))
129
+ .catch((error) => {
130
+ console.log(error);
131
+ process.exit(1);
132
+ });
@@ -0,0 +1 @@
1
+ export {};