@tricoteuses/senat 2.16.4 → 2.16.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.
- package/lib/model/debats.d.ts +26 -2
- package/lib/model/debats.js +65 -57
- package/lib/model/dosleg.d.ts +0 -13
- package/lib/model/dosleg.js +0 -13
- package/lib/model/index.d.ts +1 -1
- package/lib/model/index.js +1 -1
- package/lib/scripts/convert_data.js +50 -56
- package/lib/scripts/retrieve_open_data.js +2 -6
- package/package.json +2 -1
package/lib/model/debats.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { InferResult } from "kysely";
|
|
2
2
|
export type DebatResult = InferResult<typeof findAllQuery>[0];
|
|
3
|
-
declare const findAllQuery: import("kysely").SelectQueryBuilder<any, "debats", {
|
|
3
|
+
declare const findAllQuery: import("kysely").SelectQueryBuilder<any, "debats.debats", {
|
|
4
4
|
[x: string]: any;
|
|
5
5
|
id: string;
|
|
6
6
|
date_seance: string;
|
|
@@ -8,19 +8,31 @@ declare const findAllQuery: import("kysely").SelectQueryBuilder<any, "debats", {
|
|
|
8
8
|
[x: string]: any;
|
|
9
9
|
interventions: {
|
|
10
10
|
[x: string]: any;
|
|
11
|
+
auteur: {
|
|
12
|
+
code: any;
|
|
13
|
+
nom: any;
|
|
14
|
+
prenom: any;
|
|
15
|
+
matricule: any;
|
|
16
|
+
};
|
|
11
17
|
}[];
|
|
12
18
|
}[];
|
|
13
19
|
sections_divers: {
|
|
14
20
|
[x: string]: any;
|
|
15
21
|
interventions: {
|
|
16
22
|
[x: string]: any;
|
|
23
|
+
auteur: {
|
|
24
|
+
code: any;
|
|
25
|
+
nom: any;
|
|
26
|
+
prenom: any;
|
|
27
|
+
matricule: any;
|
|
28
|
+
};
|
|
17
29
|
}[];
|
|
18
30
|
}[];
|
|
19
31
|
lectures: {
|
|
20
32
|
id: any;
|
|
21
33
|
}[];
|
|
22
34
|
}>;
|
|
23
|
-
export declare function findAll(): AsyncIterableIterator<{
|
|
35
|
+
export declare function findAll(fromSession?: number): AsyncIterableIterator<{
|
|
24
36
|
[x: string]: any;
|
|
25
37
|
id: string;
|
|
26
38
|
date_seance: string;
|
|
@@ -28,12 +40,24 @@ export declare function findAll(): AsyncIterableIterator<{
|
|
|
28
40
|
[x: string]: any;
|
|
29
41
|
interventions: {
|
|
30
42
|
[x: string]: any;
|
|
43
|
+
auteur: {
|
|
44
|
+
code: any;
|
|
45
|
+
nom: any;
|
|
46
|
+
prenom: any;
|
|
47
|
+
matricule: any;
|
|
48
|
+
};
|
|
31
49
|
}[];
|
|
32
50
|
}[];
|
|
33
51
|
sections_divers: {
|
|
34
52
|
[x: string]: any;
|
|
35
53
|
interventions: {
|
|
36
54
|
[x: string]: any;
|
|
55
|
+
auteur: {
|
|
56
|
+
code: any;
|
|
57
|
+
nom: any;
|
|
58
|
+
prenom: any;
|
|
59
|
+
matricule: any;
|
|
60
|
+
};
|
|
37
61
|
}[];
|
|
38
62
|
}[];
|
|
39
63
|
lectures: {
|
package/lib/model/debats.js
CHANGED
|
@@ -1,87 +1,95 @@
|
|
|
1
|
-
import { jsonArrayFrom } from "kysely/helpers/postgres";
|
|
1
|
+
import { jsonArrayFrom, jsonBuildObject } from "kysely/helpers/postgres";
|
|
2
2
|
import { dbSenat } from "../databases";
|
|
3
3
|
import { ID_DATE_FORMAT } from "../scripts/datautil";
|
|
4
4
|
import { toDateString } from "./util";
|
|
5
5
|
function sectionsLegislatives(dateSeance) {
|
|
6
6
|
return jsonArrayFrom(dbSenat
|
|
7
|
-
.
|
|
8
|
-
.
|
|
9
|
-
.
|
|
10
|
-
.where("secdis.datsea", "=", dateSeance)
|
|
7
|
+
.selectFrom("debats.secdis")
|
|
8
|
+
.leftJoin("debats.typsec", "debats.secdis.typseccod", "debats.typsec.typseccod")
|
|
9
|
+
.where("debats.secdis.datsea", "=", dateSeance)
|
|
11
10
|
.select(({ ref }) => [
|
|
12
|
-
"secdis.secdisordid as id",
|
|
13
|
-
"secdis.secdisnum as numero",
|
|
14
|
-
"secdis.secdisobj as objet",
|
|
15
|
-
"secdis.secdisurl as url",
|
|
16
|
-
"typsec.typseclib as type",
|
|
17
|
-
"typsec.typseccat as categorie",
|
|
18
|
-
interventionsLegislatives(ref("secdis.secdiscle")).as("interventions"),
|
|
19
|
-
"secdis.lecassidt as lecture_id"
|
|
11
|
+
"debats.secdis.secdisordid as id",
|
|
12
|
+
"debats.secdis.secdisnum as numero",
|
|
13
|
+
"debats.secdis.secdisobj as objet",
|
|
14
|
+
"debats.secdis.secdisurl as url",
|
|
15
|
+
"debats.typsec.typseclib as type",
|
|
16
|
+
"debats.typsec.typseccat as categorie",
|
|
17
|
+
interventionsLegislatives(ref("debats.secdis.secdiscle")).as("interventions"),
|
|
18
|
+
"debats.secdis.lecassidt as lecture_id"
|
|
20
19
|
])
|
|
21
|
-
.orderBy("secdis.secdisordid asc"));
|
|
20
|
+
.orderBy("debats.secdis.secdisordid asc"));
|
|
22
21
|
}
|
|
23
22
|
function interventionsLegislatives(sectionId) {
|
|
24
23
|
return jsonArrayFrom(dbSenat
|
|
25
|
-
.
|
|
26
|
-
.
|
|
27
|
-
.where("intpjl.secdiscle", "=", sectionId)
|
|
28
|
-
.select(({ ref, val }) => [
|
|
29
|
-
"intpjl.intordid as id",
|
|
30
|
-
"intpjl.autcod as auteur_code",
|
|
31
|
-
"intpjl.intfon as fonction_intervenant",
|
|
32
|
-
"intpjl.inturl as url",
|
|
33
|
-
"intpjl.intana as analyse",
|
|
24
|
+
.selectFrom("debats.intpjl")
|
|
25
|
+
.leftJoin("dosleg.auteur", "debats.intpjl.autcod", "dosleg.auteur.autcod")
|
|
26
|
+
.where("debats.intpjl.secdiscle", "=", sectionId)
|
|
27
|
+
.select(({ ref, val, fn }) => [
|
|
28
|
+
"debats.intpjl.intordid as id",
|
|
29
|
+
"debats.intpjl.autcod as auteur_code",
|
|
30
|
+
"debats.intpjl.intfon as fonction_intervenant",
|
|
31
|
+
"debats.intpjl.inturl as url",
|
|
32
|
+
"debats.intpjl.intana as analyse",
|
|
33
|
+
jsonBuildObject({
|
|
34
|
+
code: ref("dosleg.auteur.autcod"),
|
|
35
|
+
nom: ref("dosleg.auteur.nomuse"),
|
|
36
|
+
prenom: ref("dosleg.auteur.prenom"),
|
|
37
|
+
matricule: ref("dosleg.auteur.autmat")
|
|
38
|
+
}).as("auteur")
|
|
34
39
|
])
|
|
35
|
-
.orderBy("intpjl.intordid asc"));
|
|
40
|
+
.orderBy("debats.intpjl.intordid asc"));
|
|
36
41
|
}
|
|
37
42
|
function sectionsNonLegislatives(dateSeance) {
|
|
38
43
|
return jsonArrayFrom(dbSenat
|
|
39
|
-
.
|
|
40
|
-
.
|
|
41
|
-
.
|
|
42
|
-
.where("secdivers.datsea", "=", dateSeance)
|
|
44
|
+
.selectFrom("debats.secdivers")
|
|
45
|
+
.leftJoin("debats.typsec", "debats.secdivers.typseccod", "debats.typsec.typseccod")
|
|
46
|
+
.where("debats.secdivers.datsea", "=", dateSeance)
|
|
43
47
|
.select(({ ref }) => [
|
|
44
|
-
"secdivers.secdiverslibelle as libelle",
|
|
45
|
-
"secdivers.secdiversobj as objet",
|
|
46
|
-
"typsec.typseclib as type",
|
|
47
|
-
"typsec.typseccat as categorie",
|
|
48
|
-
interventionsNonLegislatives(ref("secdivers.secdiverscle")).as("interventions"),
|
|
48
|
+
"debats.secdivers.secdiverslibelle as libelle",
|
|
49
|
+
"debats.secdivers.secdiversobj as objet",
|
|
50
|
+
"debats.typsec.typseclib as type",
|
|
51
|
+
"debats.typsec.typseccat as categorie",
|
|
52
|
+
interventionsNonLegislatives(ref("debats.secdivers.secdiverscle")).as("interventions"),
|
|
49
53
|
]));
|
|
50
54
|
}
|
|
51
55
|
function interventionsNonLegislatives(sectionId) {
|
|
52
56
|
return jsonArrayFrom(dbSenat
|
|
53
|
-
.
|
|
54
|
-
.
|
|
55
|
-
.where("intdivers.intdiverscle", "=", sectionId)
|
|
57
|
+
.selectFrom("debats.intdivers")
|
|
58
|
+
.leftJoin("dosleg.auteur", "debats.intdivers.autcod", "dosleg.auteur.autcod")
|
|
59
|
+
.where("debats.intdivers.intdiverscle", "=", sectionId)
|
|
56
60
|
.select(({ ref, val }) => [
|
|
57
|
-
"intdivers.intdiversordid as id",
|
|
58
|
-
"intdivers.autcod as auteur_code",
|
|
59
|
-
"intdivers.intfon as fonction_intervenant",
|
|
60
|
-
"intdivers.inturl as url",
|
|
61
|
-
"intdivers.intana as analyse",
|
|
61
|
+
"debats.intdivers.intdiversordid as id",
|
|
62
|
+
"debats.intdivers.autcod as auteur_code",
|
|
63
|
+
"debats.intdivers.intfon as fonction_intervenant",
|
|
64
|
+
"debats.intdivers.inturl as url",
|
|
65
|
+
"debats.intdivers.intana as analyse",
|
|
66
|
+
jsonBuildObject({
|
|
67
|
+
code: ref("dosleg.auteur.autcod"),
|
|
68
|
+
nom: ref("dosleg.auteur.nomuse"),
|
|
69
|
+
prenom: ref("dosleg.auteur.prenom"),
|
|
70
|
+
matricule: ref("dosleg.auteur.autmat")
|
|
71
|
+
}).as("auteur")
|
|
62
72
|
])
|
|
63
|
-
.orderBy("intdivers.intdiversordid asc"));
|
|
73
|
+
.orderBy("debats.intdivers.intdiversordid asc"));
|
|
64
74
|
}
|
|
65
75
|
function lecturesAssemblee(dateSeance) {
|
|
66
76
|
return jsonArrayFrom(dbSenat
|
|
67
|
-
.
|
|
68
|
-
.
|
|
69
|
-
.
|
|
70
|
-
.select("lecassdeb.lecassidt as id"));
|
|
77
|
+
.selectFrom("debats.lecassdeb")
|
|
78
|
+
.where("debats.lecassdeb.datsea", "=", dateSeance)
|
|
79
|
+
.select("debats.lecassdeb.lecassidt as id"));
|
|
71
80
|
}
|
|
72
81
|
const findAllQuery = dbSenat
|
|
73
|
-
.
|
|
74
|
-
.selectFrom("debats")
|
|
82
|
+
.selectFrom("debats.debats")
|
|
75
83
|
.select(({ ref, val }) => [
|
|
76
|
-
toDateString(ref("debats.datsea"), val(ID_DATE_FORMAT)).as("id"),
|
|
77
|
-
toDateString(ref("debats.datsea")).as("date_seance"),
|
|
78
|
-
"debats.numero as numero",
|
|
79
|
-
"debats.deburl as url",
|
|
80
|
-
"debats.debsyn as etat_synchronisation",
|
|
81
|
-
sectionsLegislatives(ref("debats.datsea")).as("sections"),
|
|
82
|
-
sectionsNonLegislatives(ref("debats.datsea")).as("sections_divers"),
|
|
83
|
-
lecturesAssemblee(ref("debats.datsea")).as("lectures"),
|
|
84
|
+
toDateString(ref("debats.debats.datsea"), val(ID_DATE_FORMAT)).as("id"),
|
|
85
|
+
toDateString(ref("debats.debats.datsea")).as("date_seance"),
|
|
86
|
+
"debats.debats.numero as numero",
|
|
87
|
+
"debats.debats.deburl as url",
|
|
88
|
+
"debats.debats.debsyn as etat_synchronisation",
|
|
89
|
+
sectionsLegislatives(ref("debats.debats.datsea")).as("sections"),
|
|
90
|
+
sectionsNonLegislatives(ref("debats.debats.datsea")).as("sections_divers"),
|
|
91
|
+
lecturesAssemblee(ref("debats.debats.datsea")).as("lectures"),
|
|
84
92
|
]);
|
|
85
|
-
export function findAll() {
|
|
93
|
+
export function findAll(fromSession) {
|
|
86
94
|
return findAllQuery.stream();
|
|
87
95
|
}
|
package/lib/model/dosleg.d.ts
CHANGED
|
@@ -1,21 +1,8 @@
|
|
|
1
1
|
import { InferResult, SelectQueryBuilder } from "kysely";
|
|
2
2
|
declare const findAllDossiersQuery: SelectQueryBuilder<any, any, any>;
|
|
3
3
|
export declare function findAllDossiers(): AsyncIterableIterator<DossierLegislatifResult>;
|
|
4
|
-
declare const findAuteursQuery: SelectQueryBuilder<any, "dosleg.auteur", {
|
|
5
|
-
code: any;
|
|
6
|
-
nom: any;
|
|
7
|
-
prenom: any;
|
|
8
|
-
matricule: any;
|
|
9
|
-
}>;
|
|
10
|
-
export declare function findAuteurs(): Promise<{
|
|
11
|
-
code: any;
|
|
12
|
-
nom: any;
|
|
13
|
-
prenom: any;
|
|
14
|
-
matricule: any;
|
|
15
|
-
}[]>;
|
|
16
4
|
export declare function createActesLegislatifs(dossier: DossierLegislatifResult): any;
|
|
17
5
|
export declare function getCodeActeLecture(codeNatureDossier: string, typeLecture: string, assemblee: string): string | null;
|
|
18
6
|
export declare function getCodeActeTexte(codeParent: string | null, texteOrigine: string): string | null;
|
|
19
7
|
export type DossierLegislatifResult = InferResult<typeof findAllDossiersQuery>[0];
|
|
20
|
-
export type AuteurResult = InferResult<typeof findAuteursQuery>[0];
|
|
21
8
|
export {};
|
package/lib/model/dosleg.js
CHANGED
|
@@ -222,19 +222,6 @@ const findAllDossiersQuery = dbSenat
|
|
|
222
222
|
export function findAllDossiers() {
|
|
223
223
|
return findAllDossiersQuery.stream();
|
|
224
224
|
}
|
|
225
|
-
const findAuteursQuery = dbSenat
|
|
226
|
-
.withSchema("dosleg")
|
|
227
|
-
.selectFrom("dosleg.auteur")
|
|
228
|
-
.select([
|
|
229
|
-
"autcod as code",
|
|
230
|
-
"nomuse as nom",
|
|
231
|
-
"prenom as prenom",
|
|
232
|
-
"autmat as matricule",
|
|
233
|
-
]);
|
|
234
|
-
export async function findAuteurs() {
|
|
235
|
-
return findAuteursQuery
|
|
236
|
-
.execute();
|
|
237
|
-
}
|
|
238
225
|
export function createActesLegislatifs(dossier) {
|
|
239
226
|
const actesLegislatifs = (dossier["lectures"] || []).map((lecture) => {
|
|
240
227
|
const lecturesAssemblee = (lecture["lectures_assemblee"] || []).map((lectureAss) => {
|
package/lib/model/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { findAllAmendements } from "./ameli";
|
|
2
2
|
export { findAll as findAllDebats } from "./debats";
|
|
3
|
-
export { findAllDossiers,
|
|
3
|
+
export { findAllDossiers, } from "./dosleg";
|
|
4
4
|
export { findSenatTexteUrls, findSenatRapportUrls } from "./documents";
|
|
5
5
|
export { findAllScrutins } from "./scrutins";
|
|
6
6
|
export { findAll as findAllQuestions } from "./questions";
|
package/lib/model/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { findAllAmendements } from "./ameli";
|
|
2
2
|
export { findAll as findAllDebats } from "./debats";
|
|
3
|
-
export { findAllDossiers,
|
|
3
|
+
export { findAllDossiers, } from "./dosleg";
|
|
4
4
|
export { findSenatTexteUrls, findSenatRapportUrls } from "./documents";
|
|
5
5
|
export { findAllScrutins } from "./scrutins";
|
|
6
6
|
export { findAll as findAllQuestions } from "./questions";
|
|
@@ -2,14 +2,15 @@ import assert from "assert";
|
|
|
2
2
|
import commandLineArgs from "command-line-args";
|
|
3
3
|
import fs from "fs-extra";
|
|
4
4
|
import path from "path";
|
|
5
|
+
import pLimit from "p-limit";
|
|
5
6
|
import { datasets, EnabledDatasets, getEnabledDatasets } from "../datasets";
|
|
6
7
|
import { DATA_ORIGINAL_FOLDER, DOCUMENT_METADATA_FILE, DOSLEG_DOSSIERS_FOLDER, SCRUTINS_FOLDER, RAPPORT_FOLDER, SENS_CIRCONSCRIPTIONS_FOLDER, SENS_ORGANISMES_FOLDER, SENS_SENATEURS_FOLDER, TEXTE_FOLDER, } from "../loaders";
|
|
7
|
-
import { findAllAmendements, findAllCirconscriptions, findAllDebats, findAllDossiers, findAllScrutins, findAllOrganismes, findAllQuestions, findAllSens,
|
|
8
|
+
import { findAllAmendements, findAllCirconscriptions, findAllDebats, findAllDossiers, findAllScrutins, findAllOrganismes, findAllQuestions, findAllSens, findSenatRapportUrls, findSenatTexteUrls, } from "../model";
|
|
8
9
|
import { createActesLegislatifs } from "../model/dosleg";
|
|
9
10
|
import { UNDEFINED_SESSION } from "../types/sessions";
|
|
10
11
|
import { getSessionFromDate, getSessionFromSignet } from "./datautil";
|
|
11
12
|
import { commonOptions } from "./shared/cli_helpers";
|
|
12
|
-
import { ensureAndClearDir
|
|
13
|
+
import { ensureAndClearDir } from "./shared/util";
|
|
13
14
|
const optionsDefinitions = [...commonOptions];
|
|
14
15
|
const options = commandLineArgs(optionsDefinitions);
|
|
15
16
|
const SENAT_TEXTE_XML_BASE_URL = "https://www.senat.fr/akomantoso/";
|
|
@@ -47,19 +48,24 @@ async function convertDatasetAmeli(dataDir, options) {
|
|
|
47
48
|
console.log(`Converting database ${dataset.database} data into files…`);
|
|
48
49
|
}
|
|
49
50
|
const ameliReorganizedRootDir = path.join(dataDir, dataset.database);
|
|
50
|
-
|
|
51
|
+
await fs.ensureDir(ameliReorganizedRootDir);
|
|
52
|
+
const limit = pLimit(10);
|
|
53
|
+
const tasks = [];
|
|
51
54
|
for await (const amendement of findAllAmendements(options["fromSession"])) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
55
|
+
tasks.push(limit(async () => {
|
|
56
|
+
if (options["verbose"]) {
|
|
57
|
+
console.log(`Converting ${amendement["numero"]} file…`);
|
|
58
|
+
}
|
|
59
|
+
const session = String(amendement["session"]) || UNDEFINED_SESSION;
|
|
60
|
+
const signetDossierLegislatif = amendement["signet_dossier_legislatif"] ||
|
|
61
|
+
`${amendement["nature_texte"]}-${amendement["numero_texte"]}`.toLowerCase();
|
|
62
|
+
const ameliReorganizedDir = path.join(ameliReorganizedRootDir, String(session), signetDossierLegislatif);
|
|
63
|
+
await fs.ensureDir(ameliReorganizedDir);
|
|
64
|
+
const amendementFileName = `${amendement["numero"]}.json`;
|
|
65
|
+
await fs.writeJSON(path.join(ameliReorganizedDir, amendementFileName), amendement, { spaces: 2 });
|
|
66
|
+
}));
|
|
62
67
|
}
|
|
68
|
+
await Promise.all(tasks);
|
|
63
69
|
}
|
|
64
70
|
async function convertDatasetDebats(dataDir, options) {
|
|
65
71
|
const dataset = datasets.debats;
|
|
@@ -68,40 +74,19 @@ async function convertDatasetDebats(dataDir, options) {
|
|
|
68
74
|
}
|
|
69
75
|
const debatsReorganizedRootDir = path.join(dataDir, dataset.database);
|
|
70
76
|
ensureAndClearDir(debatsReorganizedRootDir);
|
|
71
|
-
const allAuteurs = await findAuteurs();
|
|
72
77
|
for await (const debat of findAllDebats()) {
|
|
73
78
|
if (options["verbose"]) {
|
|
74
79
|
console.log(`Converting ${debat.id} file…`);
|
|
75
80
|
}
|
|
76
|
-
const
|
|
77
|
-
const session = getSessionFromDate(enrichedDebat.date_seance);
|
|
81
|
+
const session = getSessionFromDate(debat.date_seance);
|
|
78
82
|
if (options["fromSession"] && session < options["fromSession"]) {
|
|
79
83
|
continue;
|
|
80
84
|
}
|
|
81
85
|
const debatsReorganizedDir = path.join(debatsReorganizedRootDir, String(session));
|
|
82
86
|
fs.ensureDirSync(debatsReorganizedDir);
|
|
83
|
-
const debatFileName = `${
|
|
84
|
-
fs.writeJSONSync(path.join(debatsReorganizedDir, debatFileName),
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
async function enrichDebat(debat, auteurs) {
|
|
88
|
-
const enrichedDebat = { ...debat };
|
|
89
|
-
for (const section of enrichedDebat.sections) {
|
|
90
|
-
for (const intervention of section.interventions) {
|
|
91
|
-
;
|
|
92
|
-
intervention.auteur = findAuteur(intervention["auteur_code"], auteurs);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
for (const section of enrichedDebat.sections_divers) {
|
|
96
|
-
for (const intervention of section.interventions) {
|
|
97
|
-
;
|
|
98
|
-
intervention.auteur = findAuteur(intervention["auteur_code"], auteurs);
|
|
99
|
-
}
|
|
87
|
+
const debatFileName = `${debat.id}.json`;
|
|
88
|
+
fs.writeJSONSync(path.join(debatsReorganizedDir, debatFileName), debat, { spaces: 2 });
|
|
100
89
|
}
|
|
101
|
-
return enrichedDebat;
|
|
102
|
-
}
|
|
103
|
-
function findAuteur(auteurCode, auteurs) {
|
|
104
|
-
return auteurs.find((auteur) => auteur.code === auteurCode);
|
|
105
90
|
}
|
|
106
91
|
async function convertDatasetDosLeg(dataDir, options) {
|
|
107
92
|
const dataset = datasets.dosleg;
|
|
@@ -141,18 +126,22 @@ async function convertDatasetScrutins(dataDir, options) {
|
|
|
141
126
|
}
|
|
142
127
|
const scrutinsReorganizedDir = path.join(dataDir, SCRUTINS_FOLDER);
|
|
143
128
|
ensureAndClearDir(scrutinsReorganizedDir);
|
|
129
|
+
const limit = pLimit(10);
|
|
130
|
+
const tasks = [];
|
|
144
131
|
for await (const scrutin of findAllScrutins(options["fromSession"])) {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
132
|
+
tasks.push(limit(async () => {
|
|
133
|
+
if (options["verbose"]) {
|
|
134
|
+
console.log(`Converting ${scrutin["numero"]} file…`);
|
|
135
|
+
}
|
|
136
|
+
let scrutinReorganizedDir = path.join(scrutinsReorganizedDir, String(UNDEFINED_SESSION));
|
|
137
|
+
const session = scrutin["session"] || UNDEFINED_SESSION;
|
|
138
|
+
scrutinReorganizedDir = path.join(scrutinsReorganizedDir, String(session));
|
|
139
|
+
await fs.ensureDir(scrutinReorganizedDir);
|
|
140
|
+
const scrutinFileName = `${scrutin["numero"]}.json`;
|
|
141
|
+
await fs.writeJSON(path.join(scrutinReorganizedDir, scrutinFileName), scrutin, {
|
|
142
|
+
spaces: 2,
|
|
143
|
+
});
|
|
144
|
+
}));
|
|
156
145
|
}
|
|
157
146
|
}
|
|
158
147
|
async function convertDatasetQuestions(dataDir) {
|
|
@@ -162,16 +151,21 @@ async function convertDatasetQuestions(dataDir) {
|
|
|
162
151
|
}
|
|
163
152
|
const questionsReorganizedRootDir = path.join(dataDir, dataset.database);
|
|
164
153
|
ensureAndClearDir(questionsReorganizedRootDir);
|
|
154
|
+
const limit = pLimit(10);
|
|
155
|
+
const tasks = [];
|
|
165
156
|
for await (const question of findAllQuestions()) {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
157
|
+
tasks.push(limit(async () => {
|
|
158
|
+
if (options["verbose"]) {
|
|
159
|
+
console.log(`Converting ${question["reference"]} file…`);
|
|
160
|
+
}
|
|
161
|
+
const legislature = question["legislature"] ? question["legislature"] : 0;
|
|
162
|
+
const questionReorganizedDir = path.join(questionsReorganizedRootDir, String(legislature));
|
|
163
|
+
await fs.ensureDir(questionReorganizedDir);
|
|
164
|
+
const questionFileName = `${question["reference"]}.json`;
|
|
165
|
+
await fs.writeJSON(path.join(questionReorganizedDir, questionFileName), question, { spaces: 2 });
|
|
166
|
+
}));
|
|
174
167
|
}
|
|
168
|
+
await Promise.all(tasks);
|
|
175
169
|
}
|
|
176
170
|
async function convertTexteUrls(dataDir) {
|
|
177
171
|
const textesDir = path.join(dataDir, TEXTE_FOLDER);
|
|
@@ -96,6 +96,7 @@ async function copyToSenat(dataset, dataDir, options) {
|
|
|
96
96
|
stdio: ["pipe", "ignore", "pipe"],
|
|
97
97
|
env: process.env,
|
|
98
98
|
});
|
|
99
|
+
psql.stdin.write(`DROP SCHEMA IF EXISTS ${dataset.database} CASCADE;\n`);
|
|
99
100
|
psql.stdin.write(`CREATE SCHEMA IF NOT EXISTS ${dataset.database};\n`);
|
|
100
101
|
let buffer = '';
|
|
101
102
|
const combinedTransform = new Transform({
|
|
@@ -273,12 +274,7 @@ async function retrieveOpenData() {
|
|
|
273
274
|
process.env["PGUSER"] &&
|
|
274
275
|
process.env["PGPASSWORD"], "Missing database configuration: environment variables PGHOST, PGPORT, PGUSER and PGPASSWORD or TRICOTEUSES_SENAT_DB_* in .env file");
|
|
275
276
|
console.time("data extraction time");
|
|
276
|
-
execSync(`${options["sudo"] ? `sudo -u ${options["sudo"]} ` : ""}psql --quiet -c "
|
|
277
|
-
cwd: dataDir,
|
|
278
|
-
env: process.env,
|
|
279
|
-
encoding: "utf-8",
|
|
280
|
-
});
|
|
281
|
-
execSync(`${options["sudo"] ? `sudo -u ${options["sudo"]} ` : ""}psql --quiet -c "CREATE DATABASE senat WITH OWNER opendata"`, {
|
|
277
|
+
execSync(`${options["sudo"] ? `sudo -u ${options["sudo"]} ` : ""}psql --quiet -c "CREATE DATABASE senat WITH OWNER opendata" || true`, {
|
|
282
278
|
cwd: dataDir,
|
|
283
279
|
env: process.env,
|
|
284
280
|
encoding: "utf-8",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tricoteuses/senat",
|
|
3
|
-
"version": "2.16.
|
|
3
|
+
"version": "2.16.5",
|
|
4
4
|
"description": "Handle French Sénat's open data",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"France",
|
|
@@ -72,6 +72,7 @@
|
|
|
72
72
|
"node-stream-zip": "^1.8.2",
|
|
73
73
|
"pg": "^8.13.1",
|
|
74
74
|
"pg-cursor": "^2.12.1",
|
|
75
|
+
"p-limit": "^7.2.0",
|
|
75
76
|
"slug": "^11.0.0",
|
|
76
77
|
"tsx": "^4.20.6",
|
|
77
78
|
"windows-1252": "^1.0.0"
|