@tricoteuses/senat 3.1.7 → 3.1.8
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.
- package/lib/src/server/sens.js +49 -29
- package/package.json +1 -1
- package/lib/src/config.d.ts +0 -43
- package/lib/src/config.js +0 -37
- package/lib/src/conversion_textes.d.ts +0 -11
- package/lib/src/conversion_textes.js +0 -320
- package/lib/src/databases_postgres.d.ts +0 -4
- package/lib/src/databases_postgres.js +0 -23
- package/lib/src/datasets.d.ts +0 -38
- package/lib/src/datasets.js +0 -247
- package/lib/src/git.d.ts +0 -27
- package/lib/src/git.js +0 -251
- package/lib/src/loaders.d.ts +0 -52
- package/lib/src/loaders.js +0 -260
- package/lib/src/model/agenda.d.ts +0 -6
- package/lib/src/model/agenda.js +0 -148
- package/lib/src/model/ameli.d.ts +0 -67
- package/lib/src/model/ameli.js +0 -150
- package/lib/src/model/commission.d.ts +0 -19
- package/lib/src/model/commission.js +0 -269
- package/lib/src/model/debats.d.ts +0 -39
- package/lib/src/model/debats.js +0 -112
- package/lib/src/model/documents.d.ts +0 -32
- package/lib/src/model/documents.js +0 -182
- package/lib/src/model/dosleg.d.ts +0 -144
- package/lib/src/model/dosleg.js +0 -468
- package/lib/src/model/index.d.ts +0 -7
- package/lib/src/model/index.js +0 -7
- package/lib/src/model/questions.d.ts +0 -54
- package/lib/src/model/questions.js +0 -91
- package/lib/src/model/scrutins.d.ts +0 -48
- package/lib/src/model/scrutins.js +0 -121
- package/lib/src/model/seance.d.ts +0 -3
- package/lib/src/model/seance.js +0 -267
- package/lib/src/model/sens.d.ts +0 -112
- package/lib/src/model/sens.js +0 -385
- package/lib/src/model/util.d.ts +0 -1
- package/lib/src/model/util.js +0 -15
- package/lib/src/raw_types/ameli.d.ts +0 -1762
- package/lib/src/raw_types/ameli.js +0 -1074
- package/lib/src/raw_types/debats.d.ts +0 -380
- package/lib/src/raw_types/debats.js +0 -266
- package/lib/src/raw_types/dosleg.d.ts +0 -2954
- package/lib/src/raw_types/dosleg.js +0 -2005
- package/lib/src/raw_types/questions.d.ts +0 -699
- package/lib/src/raw_types/questions.js +0 -493
- package/lib/src/raw_types/sens.d.ts +0 -7843
- package/lib/src/raw_types/sens.js +0 -4691
- package/lib/src/raw_types_schemats/ameli.d.ts +0 -541
- package/lib/src/raw_types_schemats/ameli.js +0 -2
- package/lib/src/raw_types_schemats/debats.d.ts +0 -127
- package/lib/src/raw_types_schemats/debats.js +0 -2
- package/lib/src/raw_types_schemats/dosleg.d.ts +0 -977
- package/lib/src/raw_types_schemats/dosleg.js +0 -2
- package/lib/src/raw_types_schemats/questions.d.ts +0 -237
- package/lib/src/raw_types_schemats/questions.js +0 -2
- package/lib/src/raw_types_schemats/sens.d.ts +0 -2709
- package/lib/src/raw_types_schemats/sens.js +0 -2
- package/lib/src/scripts/debug_dosleg_query.d.ts +0 -6
- package/lib/src/scripts/debug_dosleg_query.js +0 -50
- package/lib/src/types/agenda.d.ts +0 -45
- package/lib/src/types/agenda.js +0 -1
- package/lib/src/types/ameli.d.ts +0 -5
- package/lib/src/types/ameli.js +0 -1
- package/lib/src/types/compte_rendu.d.ts +0 -83
- package/lib/src/types/compte_rendu.js +0 -1
- package/lib/src/types/debats.d.ts +0 -2
- package/lib/src/types/debats.js +0 -1
- package/lib/src/types/dosleg.d.ts +0 -70
- package/lib/src/types/dosleg.js +0 -1
- package/lib/src/types/questions.d.ts +0 -2
- package/lib/src/types/questions.js +0 -1
- package/lib/src/types/sens.d.ts +0 -8
- package/lib/src/types/sens.js +0 -1
- package/lib/src/types/sessions.d.ts +0 -6
- package/lib/src/types/sessions.js +0 -19
- package/lib/src/types/texte.d.ts +0 -72
- package/lib/src/types/texte.js +0 -15
- package/lib/src/validators/config.d.ts +0 -9
- package/lib/src/validators/config.js +0 -10
package/lib/src/loaders.js
DELETED
|
@@ -1,260 +0,0 @@
|
|
|
1
|
-
import fsex from "fs-extra";
|
|
2
|
-
import fs from "fs";
|
|
3
|
-
import path from "path";
|
|
4
|
-
import * as git from "./git.js";
|
|
5
|
-
import { datasets } from "./datasets.js";
|
|
6
|
-
import { UNDEFINED_SESSION } from "./types/sessions.js";
|
|
7
|
-
export { EnabledDatasets } from "./datasets.js";
|
|
8
|
-
export const AGENDA_FOLDER = "agenda";
|
|
9
|
-
export const COMPTES_RENDUS_FOLDER = "seances";
|
|
10
|
-
export const COMMISSION_FOLDER = "commissions";
|
|
11
|
-
export const DOSLEG_DOSSIERS_FOLDER = "dossiers";
|
|
12
|
-
export const ENRICHED_TEXTE_FOLDER = "leg_enrichi";
|
|
13
|
-
export const SCRUTINS_FOLDER = "scrutins";
|
|
14
|
-
export const SENS_CIRCONSCRIPTIONS_FOLDER = "circonscriptions";
|
|
15
|
-
export const SENS_ORGANISMES_FOLDER = "organismes";
|
|
16
|
-
export const SENS_SENATEURS_FOLDER = "senateurs";
|
|
17
|
-
export const TEXTE_FOLDER = "leg";
|
|
18
|
-
export const RAPPORT_FOLDER = "rap";
|
|
19
|
-
export const DATA_ORIGINAL_FOLDER = "original";
|
|
20
|
-
export const DATA_TRANSFORMED_FOLDER = "transformed";
|
|
21
|
-
export const DOCUMENT_METADATA_FILE = "metadata.json";
|
|
22
|
-
export function* iterFilePaths(dirPath) {
|
|
23
|
-
if (dirPath && fs.existsSync(dirPath)) {
|
|
24
|
-
const files = fs.readdirSync(dirPath, {
|
|
25
|
-
withFileTypes: true,
|
|
26
|
-
recursive: true,
|
|
27
|
-
});
|
|
28
|
-
for (const file of files) {
|
|
29
|
-
if (file.isFile()) {
|
|
30
|
-
yield path.join(file.parentPath, file.name);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
function* iterLoadSenatItems(dataDir, dataName, legislatureOrSession, subDir, { log = false, sinceCommit } = {}) {
|
|
36
|
-
let itemsDir = path.join(dataDir, dataName);
|
|
37
|
-
if (subDir) {
|
|
38
|
-
itemsDir = path.join(itemsDir, subDir);
|
|
39
|
-
}
|
|
40
|
-
if (legislatureOrSession) {
|
|
41
|
-
itemsDir = path.join(itemsDir, String(legislatureOrSession));
|
|
42
|
-
}
|
|
43
|
-
// Get changed files if sinceCommit is specified (excluding deleted files)
|
|
44
|
-
const changedFiles = sinceCommit
|
|
45
|
-
? git.getChangedFilesSinceCommit(itemsDir, sinceCommit, {
|
|
46
|
-
diffFilter: "AMR", // Added, Modified, Renamed
|
|
47
|
-
})
|
|
48
|
-
: null;
|
|
49
|
-
if (log && sinceCommit) {
|
|
50
|
-
console.log(`Filtering files changed since commit ${sinceCommit} in ${itemsDir}`);
|
|
51
|
-
console.log(`Found ${changedFiles?.size || 0} changed files (AMR)`);
|
|
52
|
-
}
|
|
53
|
-
for (const filePath of iterFilePaths(itemsDir)) {
|
|
54
|
-
if (!filePath.endsWith(".json")) {
|
|
55
|
-
continue;
|
|
56
|
-
}
|
|
57
|
-
const relativePath = path.relative(path.join(dataDir, dataName), filePath);
|
|
58
|
-
const gitStatus = changedFiles?.get(relativePath);
|
|
59
|
-
// Filter by changed files if sinceCommit is specified
|
|
60
|
-
if (changedFiles && !gitStatus) {
|
|
61
|
-
// Skip files not in the change set
|
|
62
|
-
continue;
|
|
63
|
-
}
|
|
64
|
-
if (log) {
|
|
65
|
-
console.log(`Loading file: ${filePath}…${gitStatus ? ` (${gitStatus})` : ""}`);
|
|
66
|
-
}
|
|
67
|
-
let item;
|
|
68
|
-
try {
|
|
69
|
-
const itemJson = fs.readFileSync(filePath, { encoding: "utf8" });
|
|
70
|
-
item = JSON.parse(itemJson);
|
|
71
|
-
}
|
|
72
|
-
catch (error) {
|
|
73
|
-
const err = error;
|
|
74
|
-
console.warn(`[iterLoadSenatItems] skipped invalid JSON: ${filePath} (${err.message})`);
|
|
75
|
-
continue;
|
|
76
|
-
}
|
|
77
|
-
const filePathFromDataset = filePath.substring(filePath.indexOf(dataName) + dataName.length);
|
|
78
|
-
yield {
|
|
79
|
-
item,
|
|
80
|
-
filePathFromDataset,
|
|
81
|
-
legislature: legislatureOrSession,
|
|
82
|
-
...(gitStatus && { gitStatus }), // Include gitStatus
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
// Yield deleted files at the end if sinceCommit is specified
|
|
86
|
-
if (sinceCommit) {
|
|
87
|
-
const deletedFiles = git.getChangedFilesSinceCommit(itemsDir, sinceCommit, {
|
|
88
|
-
diffFilter: "D", // Deleted
|
|
89
|
-
});
|
|
90
|
-
if (log) {
|
|
91
|
-
console.log(`Found ${deletedFiles.size || 0} deleted files (D)`);
|
|
92
|
-
}
|
|
93
|
-
for (const [relativePath, status] of deletedFiles.entries()) {
|
|
94
|
-
const deletedFilePath = path.join(itemsDir, relativePath);
|
|
95
|
-
if (log) {
|
|
96
|
-
console.log(`Deleted file: ${deletedFilePath}`);
|
|
97
|
-
}
|
|
98
|
-
// Extract UID from filename (remove extension) for the placeholder item
|
|
99
|
-
const fileExtension = path.extname(relativePath) || ".json"; // Assuming files use an extension like .json
|
|
100
|
-
const filename = path.basename(relativePath, fileExtension);
|
|
101
|
-
const fakeItem = { uid: filename }; // Placeholder item using uid constraint
|
|
102
|
-
const filePathFromDataset = deletedFilePath.substring(deletedFilePath.indexOf(dataName) + dataName.length);
|
|
103
|
-
yield {
|
|
104
|
-
item: fakeItem,
|
|
105
|
-
filePathFromDataset,
|
|
106
|
-
legislature: legislatureOrSession,
|
|
107
|
-
gitStatus: status,
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
export function* iterLoadSenatAmendements(dataDir, session, options = {}) {
|
|
113
|
-
for (const amendementItem of iterLoadSenatItems(dataDir, datasets.ameli.database, session, undefined, options)) {
|
|
114
|
-
yield amendementItem;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
export function* iterLoadSenatDebats(dataDir, session, options = {}) {
|
|
118
|
-
for (const debatItem of iterLoadSenatItems(dataDir, datasets.debats.database, session, undefined, options)) {
|
|
119
|
-
yield debatItem;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
export function* iterLoadSenatComptesRendusSeances(dataDir, session, options = {}) {
|
|
123
|
-
for (const compteRenduItem of iterLoadSenatItems(dataDir, COMPTES_RENDUS_FOLDER, session, DATA_TRANSFORMED_FOLDER, options)) {
|
|
124
|
-
yield compteRenduItem;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
export function* iterLoadSenatComptesRendusCommissions(dataDir, session, options = {}) {
|
|
128
|
-
for (const compteRenduItem of iterLoadSenatItems(dataDir, COMMISSION_FOLDER, session, DATA_TRANSFORMED_FOLDER, options)) {
|
|
129
|
-
yield compteRenduItem;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
export function* iterLoadSenatDossiersLegislatifs(dataDir, session, options = {}) {
|
|
133
|
-
for (const dossierLegislatifItem of iterLoadSenatItems(dataDir, datasets.dosleg.database, session, DOSLEG_DOSSIERS_FOLDER, options)) {
|
|
134
|
-
yield dossierLegislatifItem;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
export function* iterLoadSenatRapportUrls(dataDir, session) {
|
|
138
|
-
let itemsDir = path.join(dataDir, RAPPORT_FOLDER, DATA_ORIGINAL_FOLDER);
|
|
139
|
-
if (session) {
|
|
140
|
-
itemsDir = path.join(itemsDir, session.toString());
|
|
141
|
-
}
|
|
142
|
-
for (const filePath of iterFilePaths(itemsDir)) {
|
|
143
|
-
const parsedFilePath = path.parse(filePath);
|
|
144
|
-
if (parsedFilePath.base === DOCUMENT_METADATA_FILE) {
|
|
145
|
-
const itemJson = fs.readFileSync(filePath, { encoding: "utf8" });
|
|
146
|
-
const item = JSON.parse(itemJson);
|
|
147
|
-
yield {
|
|
148
|
-
item,
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
export function* iterLoadSenatTexteUrls(dataDir, session) {
|
|
154
|
-
let itemsDir = path.join(dataDir, TEXTE_FOLDER, DATA_ORIGINAL_FOLDER);
|
|
155
|
-
if (session) {
|
|
156
|
-
itemsDir = path.join(itemsDir, session.toString());
|
|
157
|
-
}
|
|
158
|
-
for (const filePath of iterFilePaths(itemsDir)) {
|
|
159
|
-
const parsedFilePath = path.parse(filePath);
|
|
160
|
-
if (parsedFilePath.base === DOCUMENT_METADATA_FILE) {
|
|
161
|
-
const itemJson = fs.readFileSync(filePath, { encoding: "utf8" });
|
|
162
|
-
const item = JSON.parse(itemJson);
|
|
163
|
-
yield {
|
|
164
|
-
item,
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
export function* iterLoadSenatRapports(dataDir, session, options = {}) {
|
|
170
|
-
for (const iterItem of iterLoadSenatItems(dataDir, RAPPORT_FOLDER, session, "original", options)) {
|
|
171
|
-
if (iterItem.item?.["id"]) {
|
|
172
|
-
yield iterItem;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
export function* iterLoadSenatTextes(dataDir, session, options = {}) {
|
|
177
|
-
for (const iterItem of iterLoadSenatItems(dataDir, TEXTE_FOLDER, session, DATA_ORIGINAL_FOLDER, options)) {
|
|
178
|
-
if (!iterItem.item?.["id"]) {
|
|
179
|
-
continue;
|
|
180
|
-
}
|
|
181
|
-
const texteItem = iterItem;
|
|
182
|
-
const texte = texteItem.item;
|
|
183
|
-
const texteId = texte["id"];
|
|
184
|
-
if (!texteId) {
|
|
185
|
-
continue;
|
|
186
|
-
}
|
|
187
|
-
const { item: texteContent } = loadSenatTexteContent(dataDir, texte["session"], texteId);
|
|
188
|
-
if (texteContent) {
|
|
189
|
-
texteItem.item = { ...texteContent, ...texteItem.item };
|
|
190
|
-
}
|
|
191
|
-
yield texteItem;
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
export function loadSenatTexteContent(dataDir, session, texteId) {
|
|
195
|
-
const fullTextePath = path.join(dataDir, TEXTE_FOLDER, DATA_TRANSFORMED_FOLDER, String(session ?? UNDEFINED_SESSION), texteId, `${texteId}.json`);
|
|
196
|
-
if (!fs.existsSync(fullTextePath)) {
|
|
197
|
-
return { item: null };
|
|
198
|
-
}
|
|
199
|
-
const texteJson = fs.readFileSync(fullTextePath, { encoding: "utf8" });
|
|
200
|
-
return { item: JSON.parse(texteJson) };
|
|
201
|
-
}
|
|
202
|
-
export function loadSenatCompteRenduContent(dataDir, session, debatId) {
|
|
203
|
-
const fullPath = path.join(dataDir, COMPTES_RENDUS_FOLDER, DATA_TRANSFORMED_FOLDER, String(session), `${debatId}.json`);
|
|
204
|
-
if (!fs.existsSync(fullPath)) {
|
|
205
|
-
return { item: null };
|
|
206
|
-
}
|
|
207
|
-
const json = fs.readFileSync(fullPath, { encoding: "utf8" });
|
|
208
|
-
return { item: JSON.parse(json) };
|
|
209
|
-
}
|
|
210
|
-
export function* iterLoadSenatAgendas(dataDir, session) {
|
|
211
|
-
const baseDir = path.join(dataDir, AGENDA_FOLDER, DATA_TRANSFORMED_FOLDER, String(session ?? ""));
|
|
212
|
-
if (!fs.existsSync(baseDir))
|
|
213
|
-
return;
|
|
214
|
-
const files = (fs.readdirSync(baseDir) || []).filter((f) => f.startsWith("RUSN") && f.endsWith(".json")).sort();
|
|
215
|
-
for (const fileName of files) {
|
|
216
|
-
const filePath = path.join(baseDir, fileName);
|
|
217
|
-
let raw;
|
|
218
|
-
try {
|
|
219
|
-
raw = fsex.readJSONSync(filePath);
|
|
220
|
-
}
|
|
221
|
-
catch {
|
|
222
|
-
continue; // JSON invalide
|
|
223
|
-
}
|
|
224
|
-
if (!raw || typeof raw !== "object")
|
|
225
|
-
continue;
|
|
226
|
-
const gr = raw;
|
|
227
|
-
if (!gr.uid || !gr.date || !gr.titre)
|
|
228
|
-
continue;
|
|
229
|
-
const reunion = {
|
|
230
|
-
...gr,
|
|
231
|
-
events: Array.isArray(gr.events) ? gr.events : [],
|
|
232
|
-
};
|
|
233
|
-
yield { item: reunion };
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
export function* iterLoadSenatCirconscriptions(dataDir, options = {}) {
|
|
237
|
-
for (const circonscriptionItem of iterLoadSenatItems(dataDir, datasets.sens.database, undefined, SENS_CIRCONSCRIPTIONS_FOLDER, options)) {
|
|
238
|
-
yield circonscriptionItem;
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
export function* iterLoadSenatOrganismes(dataDir, options = {}) {
|
|
242
|
-
for (const organismeItem of iterLoadSenatItems(dataDir, datasets.sens.database, undefined, SENS_ORGANISMES_FOLDER, options)) {
|
|
243
|
-
yield organismeItem;
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
export function* iterLoadSenatSenateurs(dataDir, options = {}) {
|
|
247
|
-
for (const senateurItem of iterLoadSenatItems(dataDir, datasets.sens.database, undefined, SENS_SENATEURS_FOLDER, options)) {
|
|
248
|
-
yield senateurItem;
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
export function* iterLoadSenatQuestions(dataDir, legislature, options = {}) {
|
|
252
|
-
for (const questionItem of iterLoadSenatItems(dataDir, datasets.questions.database, legislature, undefined, options)) {
|
|
253
|
-
yield questionItem;
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
export function* iterLoadSenatScrutins(dataDir, session, options = {}) {
|
|
257
|
-
for (const scrutinItem of iterLoadSenatItems(dataDir, "scrutins", session, undefined, options)) {
|
|
258
|
-
yield scrutinItem;
|
|
259
|
-
}
|
|
260
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { AgendaEvent } from "../types/agenda.js";
|
|
2
|
-
export declare function getStartAndEndTimes(timeStr: string | null | undefined, dateISO: string): {
|
|
3
|
-
startTime: string | null;
|
|
4
|
-
endTime: string | null;
|
|
5
|
-
};
|
|
6
|
-
export declare function parseAgendaFromFile(htmlFilePath: string): Promise<AgendaEvent[] | null>;
|
package/lib/src/model/agenda.js
DELETED
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
import { JSDOM } from "jsdom";
|
|
2
|
-
import { DateTime } from "luxon";
|
|
3
|
-
import path from "path";
|
|
4
|
-
import { ID_DATE_FORMAT, STANDARD_DATE_FORMAT } from "../scripts/datautil.js";
|
|
5
|
-
const FR_TZ = "Europe/Paris";
|
|
6
|
-
function eventIsSeance(eventElement) {
|
|
7
|
-
return eventElement.classList.contains("evt-seance");
|
|
8
|
-
}
|
|
9
|
-
function getEventType(eventClasses) {
|
|
10
|
-
const typeClass = [...eventClasses].find((className) => className.startsWith("evt-")) || null;
|
|
11
|
-
switch (typeClass) {
|
|
12
|
-
case "evt-seance":
|
|
13
|
-
return "Séance publique";
|
|
14
|
-
case "evt-instanz":
|
|
15
|
-
return "Commissions";
|
|
16
|
-
case "evt-cemi":
|
|
17
|
-
return "Mission de contrôle";
|
|
18
|
-
case "evt-deleg":
|
|
19
|
-
return "Offices et délégations";
|
|
20
|
-
case "evt-bureau":
|
|
21
|
-
return "Instances décisionnelles";
|
|
22
|
-
}
|
|
23
|
-
return null;
|
|
24
|
-
}
|
|
25
|
-
function getUrlDossierSenat(lienElements) {
|
|
26
|
-
const urlElement = [...lienElements].find((lienElement) => lienElement.textContent?.includes("dossier législatif"));
|
|
27
|
-
return urlElement ? urlElement.getAttribute("href") : null;
|
|
28
|
-
}
|
|
29
|
-
function getQuantieme(eventElement, seancesElements) {
|
|
30
|
-
const seanceIndex = seancesElements.indexOf(eventElement);
|
|
31
|
-
if (seancesElements.length === 1 && seanceIndex === 0) {
|
|
32
|
-
return "Unique";
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
switch (seanceIndex) {
|
|
36
|
-
case 0:
|
|
37
|
-
return "Première";
|
|
38
|
-
case 1:
|
|
39
|
-
return "Deuxième";
|
|
40
|
-
case 2:
|
|
41
|
-
return "Troisième";
|
|
42
|
-
case 3:
|
|
43
|
-
return "Quatrième";
|
|
44
|
-
case 4:
|
|
45
|
-
return "Cinquième";
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
return "Non défini";
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Normalize time string to become a simple start time ("H'h'mm") or a duration ("'de 'H'h'mm' à 'H'h'mm").
|
|
52
|
-
*/
|
|
53
|
-
function normalizeTime(timeStr) {
|
|
54
|
-
return timeStr
|
|
55
|
-
?.replace(/^À l'issue de l'espace réservé .* et au plus tard\s/i, "") // Must be processed first
|
|
56
|
-
?.replace(/^(?:le )?matin/i, "10h00") // We chose "matin" to mean 10h00
|
|
57
|
-
?.replace(/^(?:l')?après-midi/i, "16h00") // We chose "après-midi" to mean 16h00
|
|
58
|
-
?.replace(/^(?:le )?soir/i, "20h00") // We chose "soir" to mean 20h00
|
|
59
|
-
?.replace(/^(?:la )?nuit/i, "22h00") // We chose "nuit" to mean 22h00
|
|
60
|
-
?.replace(/^à\s/gi, "")
|
|
61
|
-
?.replace(/heures/gi, "h00")
|
|
62
|
-
?.replace(/\set.*/i, "")
|
|
63
|
-
?.replace(/,.*/, "")
|
|
64
|
-
?.replace(/\s\(hors hémicycle\)/i, "")
|
|
65
|
-
?.replace(/\s*h\s*/gi, "h");
|
|
66
|
-
}
|
|
67
|
-
export function getStartAndEndTimes(timeStr, dateISO) {
|
|
68
|
-
const normalizedTime = normalizeTime(timeStr);
|
|
69
|
-
if (!normalizedTime) {
|
|
70
|
-
return { startTime: null, endTime: null };
|
|
71
|
-
}
|
|
72
|
-
const rangeMatch = normalizedTime.match(/^de (?<start>\d{1,2}h\d{2}) à (?<end>\d{1,2}h\d{2})$/i);
|
|
73
|
-
const toUtcTimeOnly = (value) => {
|
|
74
|
-
if (!value)
|
|
75
|
-
return null;
|
|
76
|
-
const time = DateTime.fromFormat(value, "H'h'mm", { zone: FR_TZ });
|
|
77
|
-
if (!time.isValid)
|
|
78
|
-
return null;
|
|
79
|
-
const local = DateTime.fromISO(dateISO, { zone: FR_TZ }).set({
|
|
80
|
-
hour: time.hour,
|
|
81
|
-
minute: time.minute,
|
|
82
|
-
second: 0,
|
|
83
|
-
millisecond: 0,
|
|
84
|
-
});
|
|
85
|
-
if (!local.isValid)
|
|
86
|
-
return null;
|
|
87
|
-
return local.toUTC().toFormat("HH:mm:ss.SSS'Z'");
|
|
88
|
-
};
|
|
89
|
-
if (rangeMatch?.groups) {
|
|
90
|
-
const { start, end } = rangeMatch.groups;
|
|
91
|
-
return {
|
|
92
|
-
startTime: toUtcTimeOnly(start),
|
|
93
|
-
endTime: toUtcTimeOnly(end),
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
return {
|
|
97
|
-
startTime: toUtcTimeOnly(normalizedTime),
|
|
98
|
-
endTime: null,
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
function transformAgenda(document, fileName) {
|
|
102
|
-
const agendaEvents = [];
|
|
103
|
-
const eventElements = document.querySelectorAll(".evt");
|
|
104
|
-
const seanceElements = Array.from(eventElements).filter((eventElement) => eventIsSeance(eventElement));
|
|
105
|
-
for (const eventElement of eventElements) {
|
|
106
|
-
const id = eventElement.previousElementSibling?.getAttribute("name") || null;
|
|
107
|
-
if (!id) {
|
|
108
|
-
continue;
|
|
109
|
-
}
|
|
110
|
-
const type = getEventType(eventElement.classList);
|
|
111
|
-
const date = DateTime.fromFormat(fileName, ID_DATE_FORMAT).toFormat(STANDARD_DATE_FORMAT);
|
|
112
|
-
const timeOriginal = eventElement.querySelector(".time")?.textContent || null;
|
|
113
|
-
const { startTime, endTime } = getStartAndEndTimes(timeOriginal, date);
|
|
114
|
-
const titre = eventElement.querySelector(".titre")?.textContent?.trim() || "";
|
|
115
|
-
const organe = eventElement.querySelector(".organe")?.textContent?.trim() || null;
|
|
116
|
-
const objet = eventElement.querySelector(".objet")?.textContent?.trim()?.replace(/^- /, "") || null;
|
|
117
|
-
const lieu = eventElement.querySelector(".lieu")?.textContent || null;
|
|
118
|
-
const videoElement = eventElement.querySelector(".video");
|
|
119
|
-
const urlDossierSenat = getUrlDossierSenat(eventElement.querySelectorAll(".lien a"));
|
|
120
|
-
agendaEvents.push({
|
|
121
|
-
id,
|
|
122
|
-
type,
|
|
123
|
-
date,
|
|
124
|
-
startTime,
|
|
125
|
-
endTime,
|
|
126
|
-
timeOriginal,
|
|
127
|
-
titre,
|
|
128
|
-
organe,
|
|
129
|
-
objet,
|
|
130
|
-
lieu,
|
|
131
|
-
captationVideo: videoElement !== null,
|
|
132
|
-
urlDossierSenat: urlDossierSenat,
|
|
133
|
-
quantieme: eventIsSeance(eventElement) ? getQuantieme(eventElement, seanceElements) : null,
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
return agendaEvents;
|
|
137
|
-
}
|
|
138
|
-
export async function parseAgendaFromFile(htmlFilePath) {
|
|
139
|
-
try {
|
|
140
|
-
const { document } = (await JSDOM.fromFile(htmlFilePath, { contentType: "text/html" })).window;
|
|
141
|
-
const fileName = path.parse(htmlFilePath).name;
|
|
142
|
-
return transformAgenda(document, fileName);
|
|
143
|
-
}
|
|
144
|
-
catch (error) {
|
|
145
|
-
console.error(`Could not parse texte with error ${error.message}`);
|
|
146
|
-
}
|
|
147
|
-
return null;
|
|
148
|
-
}
|
package/lib/src/model/ameli.d.ts
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
export interface AmendementAuteurRow {
|
|
2
|
-
group_politique_code: string | null;
|
|
3
|
-
groupe_politique_id: number | null;
|
|
4
|
-
groupe_politique_libelle: string | null;
|
|
5
|
-
groupe_politique_libelle_court: string | null;
|
|
6
|
-
homonyme: string | null;
|
|
7
|
-
matricule: string | null;
|
|
8
|
-
nom: string | null;
|
|
9
|
-
prenom: string | null;
|
|
10
|
-
qualite: string | null;
|
|
11
|
-
rang: string | null;
|
|
12
|
-
}
|
|
13
|
-
export interface AmendementResult {
|
|
14
|
-
accepte_gouvernement: string | null;
|
|
15
|
-
alinea: number | null;
|
|
16
|
-
auteur_est_gouvernement: boolean;
|
|
17
|
-
au_nom_de_commission: string | null;
|
|
18
|
-
au_nom_de_groupe_politique: string | null;
|
|
19
|
-
auteurs: AmendementAuteurRow[];
|
|
20
|
-
avis_commission: string | null;
|
|
21
|
-
avis_gouvernement: string | null;
|
|
22
|
-
code_commission: string | null;
|
|
23
|
-
date_depot: string | null;
|
|
24
|
-
discussion_commune_id: number | null;
|
|
25
|
-
dispositif: string | null;
|
|
26
|
-
etat: string;
|
|
27
|
-
etat_texte: string | null;
|
|
28
|
-
etat_texte_libelle: string | null;
|
|
29
|
-
id: number;
|
|
30
|
-
identique_id: number | null;
|
|
31
|
-
intitule_texte: string | null;
|
|
32
|
-
lecture: string | null;
|
|
33
|
-
motion_libelle: string | null;
|
|
34
|
-
nature: string;
|
|
35
|
-
nature_texte: string | null;
|
|
36
|
-
nature_texte_libelle: string | null;
|
|
37
|
-
numero: string;
|
|
38
|
-
numero_absolu: string | null;
|
|
39
|
-
numero_adoption_texte: string | null;
|
|
40
|
-
numero_texte: string | null;
|
|
41
|
-
objet: string | null;
|
|
42
|
-
observations: string | null;
|
|
43
|
-
observations_additionnelles: string | null;
|
|
44
|
-
ordre: number | null;
|
|
45
|
-
parent_id: number | null;
|
|
46
|
-
revision: string | null;
|
|
47
|
-
session: string;
|
|
48
|
-
session_libelle: string;
|
|
49
|
-
signet_dossier_legislatif: string | null;
|
|
50
|
-
sort: string | null;
|
|
51
|
-
scrutin_num: string | null;
|
|
52
|
-
subdivision_commission_id: number | null;
|
|
53
|
-
subdivision_dupliquee: string | null;
|
|
54
|
-
subdivision_libelle: string | null;
|
|
55
|
-
subdivision_libelle_court: string | null;
|
|
56
|
-
subdivision_mere_id: number | null;
|
|
57
|
-
subdivision_position_discussion: number | null;
|
|
58
|
-
subdivision_position_texte: number | null;
|
|
59
|
-
subdivision_signet: string | null;
|
|
60
|
-
subdivision_type: string | null;
|
|
61
|
-
texte_id: number | null;
|
|
62
|
-
type_rectification: string | null;
|
|
63
|
-
type_session: string | null;
|
|
64
|
-
type_texte: string | null;
|
|
65
|
-
url: string;
|
|
66
|
-
}
|
|
67
|
-
export declare function findAllAmendements(fromSession?: number): AsyncGenerator<AmendementResult, void, unknown>;
|
package/lib/src/model/ameli.js
DELETED
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
import { streamUnsafeQuery } from "../databases_postgres.js";
|
|
2
|
-
function buildFindAllAmendementsQuery(fromSession) {
|
|
3
|
-
const params = [];
|
|
4
|
-
const whereSession = fromSession === undefined ? "" : "where ses.ann >= $1";
|
|
5
|
-
if (fromSession !== undefined) {
|
|
6
|
-
params.push(fromSession);
|
|
7
|
-
}
|
|
8
|
-
return {
|
|
9
|
-
params,
|
|
10
|
-
query: `
|
|
11
|
-
select
|
|
12
|
-
ses.ann::text as session,
|
|
13
|
-
ses.lil as session_libelle,
|
|
14
|
-
typses.lib as type_session,
|
|
15
|
-
txt_ameli.doslegsignet as signet_dossier_legislatif,
|
|
16
|
-
nat.libcourt as nature_texte,
|
|
17
|
-
nat.lib as nature_texte_libelle,
|
|
18
|
-
txt_ameli.numabs as numero_texte,
|
|
19
|
-
txt_ameli.numado as numero_adoption_texte,
|
|
20
|
-
txt_ameli.int as intitule_texte,
|
|
21
|
-
etatxt.lic as etat_texte,
|
|
22
|
-
etatxt.lib as etat_texte_libelle,
|
|
23
|
-
etatxt.txttyp as type_texte,
|
|
24
|
-
lec_ameli.lib as lecture,
|
|
25
|
-
case amd.typ
|
|
26
|
-
when 'A' then 'Amendement'
|
|
27
|
-
when 'M' then 'Motion'
|
|
28
|
-
when 'S' then 'Sous-amendement'
|
|
29
|
-
else ''
|
|
30
|
-
end as nature,
|
|
31
|
-
amd.id,
|
|
32
|
-
amd.amdperid as parent_id,
|
|
33
|
-
amd.ideid as identique_id,
|
|
34
|
-
amd.discomid as discussion_commune_id,
|
|
35
|
-
amd.num as numero,
|
|
36
|
-
amd.numabs as numero_absolu,
|
|
37
|
-
amd.ord as ordre,
|
|
38
|
-
amd.accgou as accepte_gouvernement,
|
|
39
|
-
amd.txtid as texte_id,
|
|
40
|
-
sub.lib as subdivision_libelle,
|
|
41
|
-
sub.lic as subdivision_libelle_court,
|
|
42
|
-
sub.pos as subdivision_position_texte,
|
|
43
|
-
sub.posder as subdivision_position_discussion,
|
|
44
|
-
sub.merid as subdivision_mere_id,
|
|
45
|
-
sub.sig as subdivision_signet,
|
|
46
|
-
sub.comdelid as subdivision_commission_id,
|
|
47
|
-
sub.dupl as subdivision_dupliquee,
|
|
48
|
-
typsub.lib as subdivision_type,
|
|
49
|
-
amd.alinea,
|
|
50
|
-
amd.obs as observations,
|
|
51
|
-
amd.mot as observations_additionnelles,
|
|
52
|
-
to_char(amd.datdep, 'YYYY-MM-DD') as date_depot,
|
|
53
|
-
amd.dis as dispositif,
|
|
54
|
-
amd.obj as objet,
|
|
55
|
-
typrect.lib as type_rectification,
|
|
56
|
-
mot.lib as motion_libelle,
|
|
57
|
-
case amd.etaid
|
|
58
|
-
when 7 then 'Diffusé'
|
|
59
|
-
when 8 then 'Retiré avant réunion ou séance'
|
|
60
|
-
when 9 then 'Examiné en commission ou séance'
|
|
61
|
-
when 10 then 'Irrecevable'
|
|
62
|
-
when 11 then 'Irrecevable'
|
|
63
|
-
else ''
|
|
64
|
-
end as etat,
|
|
65
|
-
avicom.lib as avis_commission,
|
|
66
|
-
avigvt.lib as avis_gouvernement,
|
|
67
|
-
coalesce(sor.lib, irr.libirr) as sort,
|
|
68
|
-
amd.rev as revision,
|
|
69
|
-
(
|
|
70
|
-
case
|
|
71
|
-
when amd.num like '%COM%' then 'https://www.senat.fr/amendements/commissions/'
|
|
72
|
-
else 'https://www.senat.fr/amendements/'
|
|
73
|
-
end ||
|
|
74
|
-
ses.ann::text || '-' ||
|
|
75
|
-
(ses.ann + 1)::text || '/' ||
|
|
76
|
-
txt_ameli.numabs || '/Amdt_' ||
|
|
77
|
-
amd.num || '.html'
|
|
78
|
-
) as url,
|
|
79
|
-
grppol_ameli.lilcou as au_nom_de_groupe_politique,
|
|
80
|
-
rtrim(com_ameli.lil) as au_nom_de_commission,
|
|
81
|
-
rtrim(com_ameli.cod) as code_commission,
|
|
82
|
-
(cab.entid is not null) as auteur_est_gouvernement,
|
|
83
|
-
(
|
|
84
|
-
select amescr.scrnum::text
|
|
85
|
-
from senat.dosleg_amescr as amescr
|
|
86
|
-
left join senat.dosleg_scr as scr
|
|
87
|
-
on amescr.scrnum = scr.scrnum
|
|
88
|
-
and amescr.sesann = scr.sesann
|
|
89
|
-
left join senat.dosleg_date_seance as date_seance on scr.code = date_seance.code
|
|
90
|
-
where amescr.amescrnum = amd.num
|
|
91
|
-
and amescr.sesann = ses.ann
|
|
92
|
-
and date_seance.lecidt = texte.lecassidt
|
|
93
|
-
limit 1
|
|
94
|
-
) as scrutin_num,
|
|
95
|
-
(
|
|
96
|
-
select coalesce(json_agg(author_rows order by author_rows.rang nulls last), '[]'::json)
|
|
97
|
-
from (
|
|
98
|
-
select
|
|
99
|
-
amdsen.prenomuse as prenom,
|
|
100
|
-
amdsen.hom as homonyme,
|
|
101
|
-
amdsen.nomuse as nom,
|
|
102
|
-
amdsen.qua as qualite,
|
|
103
|
-
amdsen.rng::text as rang,
|
|
104
|
-
sen_ameli.mat as matricule,
|
|
105
|
-
amdsen.grpid as groupe_politique_id,
|
|
106
|
-
grppol_ameli.cod as group_politique_code,
|
|
107
|
-
grppol_ameli.libcou as groupe_politique_libelle_court,
|
|
108
|
-
grppol_ameli.lilcou as groupe_politique_libelle
|
|
109
|
-
from senat.ameli_amdsen as amdsen
|
|
110
|
-
left join senat.ameli_sen_ameli as sen_ameli on amdsen.senid = sen_ameli.entid
|
|
111
|
-
left join senat.ameli_grppol_ameli as grppol_ameli on amdsen.grpid = grppol_ameli.entid
|
|
112
|
-
where amdsen.amdid = amd.id
|
|
113
|
-
order by amdsen.rng asc
|
|
114
|
-
) as author_rows
|
|
115
|
-
) as auteurs
|
|
116
|
-
from senat.ameli_amd as amd
|
|
117
|
-
left join senat.ameli_sub as sub on amd.subid = sub.id
|
|
118
|
-
left join senat.ameli_typsub as typsub on sub.typid = typsub.id
|
|
119
|
-
left join senat.ameli_typrect as typrect on amd.typrectid = typrect.id
|
|
120
|
-
left join senat.ameli_txt_ameli as txt_ameli on amd.txtid = txt_ameli.id
|
|
121
|
-
left join senat.ameli_etatxt as etatxt on txt_ameli.txtetaid = etatxt.id
|
|
122
|
-
left join senat.ameli_ses as ses on txt_ameli.sesdepid = ses.id
|
|
123
|
-
left join senat.ameli_typses as typses on typses.id = ses.typid
|
|
124
|
-
left join senat.ameli_nat as nat on txt_ameli.natid = nat.id
|
|
125
|
-
left join senat.ameli_lec_ameli as lec_ameli on txt_ameli.lecid = lec_ameli.id
|
|
126
|
-
left join senat.dosleg_texte as texte
|
|
127
|
-
on ses.ann = texte.sesann
|
|
128
|
-
and txt_ameli.numabs = texte.texnum
|
|
129
|
-
left join senat.dosleg_lecass as lecass on texte.lecassidt = lecass.lecassidt
|
|
130
|
-
left join senat.ameli_mot as mot on amd.motid = mot.id
|
|
131
|
-
left join senat.ameli_avicom as avicom on amd.avcid = avicom.id
|
|
132
|
-
left join senat.ameli_avigvt as avigvt on amd.avgid = avigvt.id
|
|
133
|
-
left join senat.ameli_sor as sor on amd.sorid = sor.id
|
|
134
|
-
left join senat.ameli_irr as irr on amd.irrid = irr.id
|
|
135
|
-
left join senat.ameli_grppol_ameli as grppol_ameli on amd.nomentid = grppol_ameli.entid
|
|
136
|
-
left join senat.ameli_com_ameli as com_ameli on amd.nomentid = com_ameli.entid
|
|
137
|
-
left join senat.ameli_cab as cab on amd.nomentid = cab.entid
|
|
138
|
-
${whereSession}
|
|
139
|
-
`,
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
export async function* findAllAmendements(fromSession) {
|
|
143
|
-
const { query, params } = buildFindAllAmendementsQuery(fromSession);
|
|
144
|
-
for await (const row of streamUnsafeQuery(query, params)) {
|
|
145
|
-
yield {
|
|
146
|
-
...row,
|
|
147
|
-
auteurs: row.auteurs ?? [],
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import * as cheerio from "cheerio";
|
|
2
|
-
import type { AnyNode } from "domhandler";
|
|
3
|
-
import { CompteRendu } from "../types/compte_rendu.js";
|
|
4
|
-
import { Reunion } from "../types/agenda.js";
|
|
5
|
-
export declare function getRemainingTextAfterSpeakerHeader($: cheerio.CheerioAPI, $p: cheerio.Cheerio<AnyNode>): string;
|
|
6
|
-
export type DaySection = {
|
|
7
|
-
title: string;
|
|
8
|
-
$start: cheerio.Cheerio<AnyNode>;
|
|
9
|
-
time?: string;
|
|
10
|
-
};
|
|
11
|
-
export declare function cleanTitle(t: string): string;
|
|
12
|
-
export declare function extractDayH3Sections($: cheerio.CheerioAPI, dateISO: string): DaySection[];
|
|
13
|
-
export declare function parseCommissionCRSectionFromDom($: cheerio.CheerioAPI, htmlFilePath: string, opts: {
|
|
14
|
-
dateISO: string;
|
|
15
|
-
hourShort: string | null;
|
|
16
|
-
organe?: string | null;
|
|
17
|
-
section: DaySection;
|
|
18
|
-
matched?: Reunion;
|
|
19
|
-
}): CompteRendu | null;
|