@tricoteuses/senat 2.22.16 → 2.23.0
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/README.md +168 -0
- package/lib/aggregates.d.ts +52 -0
- package/lib/aggregates.js +930 -0
- package/lib/aggregates.mjs +713 -0
- package/lib/aggregates.ts +833 -0
- package/lib/config.d.ts +10 -0
- package/lib/config.js +16 -0
- package/lib/config.mjs +16 -0
- package/lib/config.ts +26 -0
- package/lib/databases.d.ts +2 -0
- package/lib/databases.js +26 -0
- package/lib/databases.mjs +57 -0
- package/lib/databases.ts +71 -0
- package/lib/datasets.d.ts +34 -0
- package/lib/datasets.js +233 -0
- package/lib/datasets.mjs +78 -0
- package/lib/datasets.ts +118 -0
- package/lib/fields.d.ts +10 -0
- package/lib/fields.js +68 -0
- package/lib/fields.mjs +22 -0
- package/lib/fields.ts +29 -0
- package/lib/git.d.ts +26 -0
- package/lib/git.js +167 -0
- package/lib/index.d.ts +13 -0
- package/lib/index.js +1 -0
- package/lib/index.mjs +7 -0
- package/lib/index.ts +64 -0
- package/lib/inserters.d.ts +98 -0
- package/lib/inserters.js +500 -0
- package/lib/inserters.mjs +360 -0
- package/lib/inserters.ts +521 -0
- package/lib/legislatures.json +38 -0
- package/lib/loaders.d.ts +58 -0
- package/lib/loaders.js +286 -0
- package/lib/loaders.mjs +158 -0
- package/lib/loaders.ts +271 -0
- package/lib/model/agenda.d.ts +6 -0
- package/lib/model/agenda.js +148 -0
- package/lib/model/ameli.d.ts +51 -0
- package/lib/model/ameli.js +149 -0
- package/lib/model/ameli.mjs +84 -0
- package/lib/model/ameli.ts +100 -0
- package/lib/model/commission.d.ts +18 -0
- package/lib/model/commission.js +269 -0
- package/lib/model/debats.d.ts +67 -0
- package/lib/model/debats.js +95 -0
- package/lib/model/debats.mjs +43 -0
- package/lib/model/debats.ts +68 -0
- package/lib/model/documents.d.ts +12 -0
- package/lib/model/documents.js +151 -0
- package/lib/model/dosleg.d.ts +7 -0
- package/lib/model/dosleg.js +326 -0
- package/lib/model/dosleg.mjs +196 -0
- package/lib/model/dosleg.ts +240 -0
- package/lib/model/index.d.ts +7 -0
- package/lib/model/index.js +7 -0
- package/lib/model/index.mjs +5 -0
- package/lib/model/index.ts +15 -0
- package/lib/model/questions.d.ts +45 -0
- package/lib/model/questions.js +89 -0
- package/lib/model/questions.mjs +71 -0
- package/lib/model/questions.ts +93 -0
- package/lib/model/scrutins.d.ts +13 -0
- package/lib/model/scrutins.js +114 -0
- package/lib/model/seance.d.ts +3 -0
- package/lib/model/seance.js +267 -0
- package/lib/model/sens.d.ts +146 -0
- package/lib/model/sens.js +454 -0
- package/lib/model/sens.mjs +415 -0
- package/lib/model/sens.ts +516 -0
- package/lib/model/texte.d.ts +7 -0
- package/lib/model/texte.js +256 -0
- package/lib/model/texte.mjs +208 -0
- package/lib/model/texte.ts +229 -0
- package/lib/model/util.d.ts +9 -0
- package/lib/model/util.js +38 -0
- package/lib/model/util.mjs +19 -0
- package/lib/model/util.ts +32 -0
- package/lib/parsers/texte.d.ts +7 -0
- package/lib/parsers/texte.js +228 -0
- package/lib/raw_types/ameli.d.ts +914 -0
- package/lib/raw_types/ameli.js +5 -0
- package/lib/raw_types/ameli.mjs +163 -0
- package/lib/raw_types/debats.d.ts +207 -0
- package/lib/raw_types/debats.js +5 -0
- package/lib/raw_types/debats.mjs +58 -0
- package/lib/raw_types/dosleg.d.ts +1619 -0
- package/lib/raw_types/dosleg.js +5 -0
- package/lib/raw_types/dosleg.mjs +438 -0
- package/lib/raw_types/questions.d.ts +419 -0
- package/lib/raw_types/questions.js +5 -0
- package/lib/raw_types/questions.mjs +11 -0
- package/lib/raw_types/senat.d.ts +11368 -0
- package/lib/raw_types/senat.js +5 -0
- package/lib/raw_types/sens.d.ts +8248 -0
- package/lib/raw_types/sens.js +5 -0
- package/lib/raw_types/sens.mjs +508 -0
- package/lib/raw_types_kysely/ameli.d.ts +915 -0
- package/lib/raw_types_kysely/ameli.js +7 -0
- package/lib/raw_types_kysely/ameli.mjs +5 -0
- package/lib/raw_types_kysely/ameli.ts +951 -0
- package/lib/raw_types_kysely/debats.d.ts +207 -0
- package/lib/raw_types_kysely/debats.js +7 -0
- package/lib/raw_types_kysely/debats.mjs +5 -0
- package/lib/raw_types_kysely/debats.ts +222 -0
- package/lib/raw_types_kysely/dosleg.d.ts +3532 -0
- package/lib/raw_types_kysely/dosleg.js +7 -0
- package/lib/raw_types_kysely/dosleg.mjs +5 -0
- package/lib/raw_types_kysely/dosleg.ts +3621 -0
- package/lib/raw_types_kysely/questions.d.ts +414 -0
- package/lib/raw_types_kysely/questions.js +7 -0
- package/lib/raw_types_kysely/questions.mjs +5 -0
- package/lib/raw_types_kysely/questions.ts +426 -0
- package/lib/raw_types_kysely/sens.d.ts +4394 -0
- package/lib/raw_types_kysely/sens.js +7 -0
- package/lib/raw_types_kysely/sens.mjs +5 -0
- package/lib/raw_types_kysely/sens.ts +4499 -0
- package/lib/raw_types_schemats/ameli.d.ts +539 -0
- package/lib/raw_types_schemats/ameli.js +2 -0
- package/lib/raw_types_schemats/ameli.mjs +2 -0
- package/lib/raw_types_schemats/ameli.ts +601 -0
- package/lib/raw_types_schemats/debats.d.ts +127 -0
- package/lib/raw_types_schemats/debats.js +2 -0
- package/lib/raw_types_schemats/debats.mjs +2 -0
- package/lib/raw_types_schemats/debats.ts +145 -0
- package/lib/raw_types_schemats/dosleg.d.ts +977 -0
- package/lib/raw_types_schemats/dosleg.js +2 -0
- package/lib/raw_types_schemats/dosleg.mjs +2 -0
- package/lib/raw_types_schemats/dosleg.ts +2193 -0
- package/lib/raw_types_schemats/questions.d.ts +235 -0
- package/lib/raw_types_schemats/questions.js +2 -0
- package/lib/raw_types_schemats/questions.mjs +2 -0
- package/lib/raw_types_schemats/questions.ts +249 -0
- package/lib/raw_types_schemats/sens.d.ts +6915 -0
- package/lib/raw_types_schemats/sens.js +2 -0
- package/lib/raw_types_schemats/sens.mjs +2 -0
- package/lib/raw_types_schemats/sens.ts +2907 -0
- package/lib/scripts/convert_data.d.ts +1 -0
- package/lib/scripts/convert_data.js +354 -0
- package/lib/scripts/convert_data.mjs +181 -0
- package/lib/scripts/convert_data.ts +243 -0
- package/lib/scripts/data-download.d.ts +1 -0
- package/lib/scripts/data-download.js +12 -0
- package/lib/scripts/datautil.d.ts +8 -0
- package/lib/scripts/datautil.js +34 -0
- package/lib/scripts/datautil.mjs +16 -0
- package/lib/scripts/datautil.ts +19 -0
- package/lib/scripts/images/transparent_150x192.jpg +0 -0
- package/lib/scripts/images/transparent_155x225.jpg +0 -0
- package/lib/scripts/parse_textes.d.ts +1 -0
- package/lib/scripts/parse_textes.js +44 -0
- package/lib/scripts/parse_textes.mjs +46 -0
- package/lib/scripts/parse_textes.ts +65 -0
- package/lib/scripts/retrieve_agenda.d.ts +1 -0
- package/lib/scripts/retrieve_agenda.js +132 -0
- package/lib/scripts/retrieve_cr_commission.d.ts +1 -0
- package/lib/scripts/retrieve_cr_commission.js +364 -0
- package/lib/scripts/retrieve_cr_seance.d.ts +6 -0
- package/lib/scripts/retrieve_cr_seance.js +347 -0
- package/lib/scripts/retrieve_documents.d.ts +3 -0
- package/lib/scripts/retrieve_documents.js +219 -0
- package/lib/scripts/retrieve_documents.mjs +249 -0
- package/lib/scripts/retrieve_documents.ts +298 -0
- package/lib/scripts/retrieve_open_data.d.ts +1 -0
- package/lib/scripts/retrieve_open_data.js +315 -0
- package/lib/scripts/retrieve_open_data.mjs +217 -0
- package/lib/scripts/retrieve_open_data.ts +268 -0
- package/lib/scripts/retrieve_senateurs_photos.d.ts +1 -0
- package/lib/scripts/retrieve_senateurs_photos.js +147 -0
- package/lib/scripts/retrieve_senateurs_photos.mjs +147 -0
- package/lib/scripts/retrieve_senateurs_photos.ts +177 -0
- package/lib/scripts/retrieve_videos.d.ts +1 -0
- package/lib/scripts/retrieve_videos.js +461 -0
- package/lib/scripts/shared/cli_helpers.d.ts +95 -0
- package/lib/scripts/shared/cli_helpers.js +91 -0
- package/lib/scripts/shared/cli_helpers.ts +36 -0
- package/lib/scripts/shared/util.d.ts +4 -0
- package/lib/scripts/shared/util.js +35 -0
- package/lib/scripts/shared/util.ts +33 -0
- package/lib/scripts/test_iter_load.d.ts +1 -0
- package/lib/scripts/test_iter_load.js +12 -0
- package/lib/src/config.d.ts +22 -0
- package/lib/src/config.js +17 -7
- package/lib/src/conversion_textes.js +5 -1
- package/lib/src/databases.d.ts +2 -1
- package/lib/src/databases_postgres.d.ts +4 -0
- package/lib/src/databases_postgres.js +23 -0
- package/lib/src/datasets.d.ts +4 -0
- package/lib/src/datasets.js +16 -2
- package/lib/src/git.d.ts +1 -0
- package/lib/src/git.js +45 -11
- package/lib/src/loaders.js +10 -4
- package/lib/src/model/agenda.js +2 -2
- package/lib/src/model/ameli.d.ts +64 -52
- package/lib/src/model/ameli.js +147 -145
- package/lib/src/model/ameli_postgres.d.ts +67 -0
- package/lib/src/model/ameli_postgres.js +150 -0
- package/lib/src/model/commission.d.ts +3 -2
- package/lib/src/model/commission.js +2 -2
- package/lib/src/model/debats.d.ts +38 -66
- package/lib/src/model/debats.js +110 -93
- package/lib/src/model/documents.d.ts +32 -12
- package/lib/src/model/documents.js +171 -130
- package/lib/src/model/dosleg.d.ts +142 -5
- package/lib/src/model/dosleg.js +298 -156
- package/lib/src/model/questions.d.ts +54 -45
- package/lib/src/model/questions.js +89 -87
- package/lib/src/model/scrutins.d.ts +48 -13
- package/lib/src/model/scrutins.js +118 -111
- package/lib/src/model/seance.js +3 -3
- package/lib/src/model/sens.d.ts +109 -179
- package/lib/src/model/sens.js +384 -484
- package/lib/src/model/util.d.ts +0 -8
- package/lib/src/model/util.js +0 -23
- package/lib/src/parsers/texte.js +7 -7
- package/lib/src/raw_types_schemats/ameli.d.ts +4 -2
- package/lib/src/raw_types_schemats/debats.d.ts +2 -2
- package/lib/src/raw_types_schemats/dosleg.d.ts +2 -2
- package/lib/src/raw_types_schemats/questions.d.ts +2 -2
- package/lib/src/raw_types_schemats/sens.d.ts +10 -4216
- package/lib/src/scripts/convert_data.js +7 -6
- package/lib/src/scripts/convert_xml_to_html.js +2 -2
- package/lib/src/scripts/data-download.js +3 -2
- package/lib/src/scripts/retrieve_agenda.js +21 -9
- package/lib/src/scripts/retrieve_cr_commission.js +17 -17
- package/lib/src/scripts/retrieve_cr_seance.d.ts +14 -1
- package/lib/src/scripts/retrieve_cr_seance.js +10 -11
- package/lib/src/scripts/retrieve_documents.d.ts +11 -2
- package/lib/src/scripts/retrieve_documents.js +25 -14
- package/lib/src/scripts/retrieve_open_data.js +400 -145
- package/lib/src/scripts/retrieve_senateurs_photos.js +25 -11
- package/lib/src/scripts/retrieve_videos.js +12 -11
- package/lib/src/scripts/shared/cli_helpers.d.ts +1 -6
- package/lib/src/scripts/shared/cli_helpers.js +9 -8
- package/lib/src/scripts/shared/incremental_import_sql.d.ts +2 -0
- package/lib/src/scripts/shared/incremental_import_sql.js +894 -0
- package/lib/src/scripts/shared/prefixed_tables.d.ts +7 -0
- package/lib/src/scripts/shared/prefixed_tables.js +30 -0
- package/lib/src/scripts/shared/schema_version.d.ts +3 -0
- package/lib/src/scripts/shared/schema_version.js +97 -0
- package/lib/src/scripts/shared/staging_import.d.ts +3 -0
- package/lib/src/scripts/shared/staging_import.js +80 -0
- package/lib/src/scripts/shared/staging_metadata_sql.d.ts +1 -0
- package/lib/src/scripts/shared/staging_metadata_sql.js +221 -0
- package/lib/src/scripts/validate_prefixed_tables.d.ts +1 -0
- package/lib/src/scripts/validate_prefixed_tables.js +102 -0
- package/lib/src/types/texte.d.ts +1 -1
- package/lib/src/utils/cr_spliting.d.ts +9 -6
- package/lib/src/utils/cr_spliting.js +6 -101
- package/lib/src/utils/reunion_odj_building.d.ts +7 -3
- package/lib/src/utils/reunion_parsing.d.ts +2 -1
- package/lib/src/utils/reunion_parsing.js +2 -2
- package/lib/src/videos/match.js +8 -5
- package/lib/src/videos/pipeline.d.ts +6 -2
- package/lib/src/videos/pipeline.js +21 -8
- package/lib/src/videos/search.js +6 -2
- package/lib/strings.d.ts +1 -0
- package/lib/strings.js +18 -0
- package/lib/strings.mjs +18 -0
- package/lib/strings.ts +26 -0
- package/lib/tests/incrementalImportSql.test.d.ts +1 -0
- package/lib/tests/incrementalImportSql.test.js +155 -0
- package/lib/tests/prefixedTables.test.d.ts +1 -0
- package/lib/tests/prefixedTables.test.js +29 -0
- package/lib/tests/schemaVersion.test.d.ts +1 -0
- package/lib/tests/schemaVersion.test.js +23 -0
- package/lib/tests/validatePrefixedTables.test.d.ts +1 -0
- package/lib/tests/validatePrefixedTables.test.js +14 -0
- package/lib/types/agenda.d.ts +44 -0
- package/lib/types/agenda.js +1 -0
- package/lib/types/ameli.d.ts +5 -0
- package/lib/types/ameli.js +1 -0
- package/lib/types/ameli.mjs +13 -0
- package/lib/types/ameli.ts +21 -0
- package/lib/types/compte_rendu.d.ts +83 -0
- package/lib/types/compte_rendu.js +1 -0
- package/lib/types/debats.d.ts +2 -0
- package/lib/types/debats.js +1 -0
- package/lib/types/debats.mjs +2 -0
- package/lib/types/debats.ts +6 -0
- package/lib/types/dosleg.d.ts +70 -0
- package/lib/types/dosleg.js +1 -0
- package/lib/types/dosleg.mjs +151 -0
- package/lib/types/dosleg.ts +284 -0
- package/lib/types/questions.d.ts +2 -0
- package/lib/types/questions.js +1 -0
- package/lib/types/questions.mjs +1 -0
- package/lib/types/questions.ts +3 -0
- package/lib/types/sens.d.ts +10 -0
- package/lib/types/sens.js +1 -0
- package/lib/types/sens.mjs +1 -0
- package/lib/types/sens.ts +12 -0
- package/lib/types/sessions.d.ts +5 -0
- package/lib/types/sessions.js +84 -0
- package/lib/types/sessions.mjs +43 -0
- package/lib/types/sessions.ts +42 -0
- package/lib/types/texte.d.ts +74 -0
- package/lib/types/texte.js +16 -0
- package/lib/types/texte.mjs +16 -0
- package/lib/types/texte.ts +76 -0
- package/lib/typings/windows-1252.d.js +2 -0
- package/lib/typings/windows-1252.d.mjs +2 -0
- package/lib/typings/windows-1252.d.ts +11 -0
- package/lib/utils/cr_spliting.d.ts +28 -0
- package/lib/utils/cr_spliting.js +265 -0
- package/lib/utils/date.d.ts +10 -0
- package/lib/utils/date.js +100 -0
- package/lib/utils/nvs-timecode.d.ts +7 -0
- package/lib/utils/nvs-timecode.js +79 -0
- package/lib/utils/reunion_grouping.d.ts +9 -0
- package/lib/utils/reunion_grouping.js +361 -0
- package/lib/utils/reunion_odj_building.d.ts +5 -0
- package/lib/utils/reunion_odj_building.js +154 -0
- package/lib/utils/reunion_parsing.d.ts +23 -0
- package/lib/utils/reunion_parsing.js +209 -0
- package/lib/utils/scoring.d.ts +14 -0
- package/lib/utils/scoring.js +147 -0
- package/lib/utils/string_cleaning.d.ts +7 -0
- package/lib/utils/string_cleaning.js +57 -0
- package/lib/validators/config.d.ts +9 -0
- package/lib/validators/config.js +10 -0
- package/lib/validators/config.mjs +54 -0
- package/lib/validators/config.ts +79 -0
- package/lib/validators/senat.d.ts +0 -0
- package/lib/validators/senat.js +28 -0
- package/lib/validators/senat.mjs +24 -0
- package/lib/validators/senat.ts +26 -0
- package/package.json +6 -10
package/lib/config.d.ts
ADDED
package/lib/config.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import "dotenv/config";
|
|
2
|
+
import { configSchema } from "./validators/config";
|
|
3
|
+
const config = {
|
|
4
|
+
db: {
|
|
5
|
+
host: process.env["TRICOTEUSES_SENAT_DB_HOST"] || "localhost",
|
|
6
|
+
password: process.env["TRICOTEUSES_SENAT_DB_PASSWORD"] || "opendata",
|
|
7
|
+
port: process.env["TRICOTEUSES_SENAT_DB_PORT"] || 5432,
|
|
8
|
+
user: process.env["TRICOTEUSES_SENAT_DB_USER"] || "opendata",
|
|
9
|
+
},
|
|
10
|
+
};
|
|
11
|
+
const result = configSchema.safeParse(config);
|
|
12
|
+
if (!result.success) {
|
|
13
|
+
console.error(`Error in configuration:\n${JSON.stringify(config, null, 2)}\nError:\n${JSON.stringify(result.error.issues, null, 2)}`);
|
|
14
|
+
process.exit(-1);
|
|
15
|
+
}
|
|
16
|
+
export default result.data;
|
package/lib/config.mjs
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
require("dotenv").config();
|
|
2
|
+
import { validateConfig } from "./validators/config";
|
|
3
|
+
const config = {
|
|
4
|
+
db: {
|
|
5
|
+
host: process.env.TRICOTEUSES_SENAT_DB_HOST || "localhost",
|
|
6
|
+
password: process.env.TRICOTEUSES_SENAT_DB_PASSWORD || "opendata",
|
|
7
|
+
port: process.env.TRICOTEUSES_SENAT_DB_PORT || 5432,
|
|
8
|
+
user: process.env.TRICOTEUSES_SENAT_DB_USER || "opendata",
|
|
9
|
+
},
|
|
10
|
+
};
|
|
11
|
+
const [validConfig, error] = validateConfig(config);
|
|
12
|
+
if (error !== null) {
|
|
13
|
+
console.error(`Error in configuration:\n${JSON.stringify(validConfig, null, 2)}\nError:\n${JSON.stringify(error, null, 2)}`);
|
|
14
|
+
process.exit(-1);
|
|
15
|
+
}
|
|
16
|
+
export default validConfig;
|
package/lib/config.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
require("dotenv").config()
|
|
2
|
+
|
|
3
|
+
import { validateConfig } from "./validators/config"
|
|
4
|
+
|
|
5
|
+
const config = {
|
|
6
|
+
db: {
|
|
7
|
+
host: process.env.TRICOTEUSES_SENAT_DB_HOST || "localhost",
|
|
8
|
+
password: process.env.TRICOTEUSES_SENAT_DB_PASSWORD || "opendata",
|
|
9
|
+
port: process.env.TRICOTEUSES_SENAT_DB_PORT || 5432,
|
|
10
|
+
user: process.env.TRICOTEUSES_SENAT_DB_USER || "opendata",
|
|
11
|
+
},
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const [validConfig, error] = validateConfig(config)
|
|
15
|
+
if (error !== null) {
|
|
16
|
+
console.error(
|
|
17
|
+
`Error in configuration:\n${JSON.stringify(
|
|
18
|
+
validConfig,
|
|
19
|
+
null,
|
|
20
|
+
2,
|
|
21
|
+
)}\nError:\n${JSON.stringify(error, null, 2)}`,
|
|
22
|
+
)
|
|
23
|
+
process.exit(-1)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export default validConfig
|
package/lib/databases.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Kysely, PostgresDialect } from "kysely";
|
|
2
|
+
import * as pg from "pg";
|
|
3
|
+
import { types } from "pg";
|
|
4
|
+
import Cursor from "pg-cursor";
|
|
5
|
+
import config from "./config";
|
|
6
|
+
// Map int8 to number instead of string
|
|
7
|
+
// https://github.com/brianc/node-pg-types#use
|
|
8
|
+
pg.types.setTypeParser(types.builtins.INT8, (val) => {
|
|
9
|
+
return parseInt(val, 10);
|
|
10
|
+
});
|
|
11
|
+
const senatPool = new pg.Pool({
|
|
12
|
+
database: "senat",
|
|
13
|
+
host: config.db.host,
|
|
14
|
+
user: config.db.user,
|
|
15
|
+
password: config.db.password,
|
|
16
|
+
port: config.db.port,
|
|
17
|
+
max: 10,
|
|
18
|
+
});
|
|
19
|
+
const senatDialect = new PostgresDialect({
|
|
20
|
+
pool: senatPool,
|
|
21
|
+
cursor: Cursor,
|
|
22
|
+
});
|
|
23
|
+
export const dbSenat = new Kysely({
|
|
24
|
+
log: ["error"],
|
|
25
|
+
dialect: senatDialect,
|
|
26
|
+
});
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Kysely, PostgresDialect } from "kysely";
|
|
2
|
+
import * as pg from "pg";
|
|
3
|
+
import { types } from "pg";
|
|
4
|
+
import Cursor from "pg-cursor";
|
|
5
|
+
import PgPromise from "pg-promise";
|
|
6
|
+
import config from "./config";
|
|
7
|
+
import { datasets } from "./datasets";
|
|
8
|
+
// Map int8 to number instead of string
|
|
9
|
+
// https://github.com/brianc/node-pg-types#use
|
|
10
|
+
pg.types.setTypeParser(types.builtins.INT8, (val) => {
|
|
11
|
+
return parseInt(val, 10);
|
|
12
|
+
});
|
|
13
|
+
export const pgPromise = PgPromise();
|
|
14
|
+
export const dbNames = ["ameli", "debats", "dosleg"];
|
|
15
|
+
export const dbByName = {};
|
|
16
|
+
for (const name of dbNames) {
|
|
17
|
+
dbByName[name] = pgPromise({
|
|
18
|
+
database: name,
|
|
19
|
+
host: config.db.host,
|
|
20
|
+
password: config.db.password,
|
|
21
|
+
port: config.db.port,
|
|
22
|
+
user: config.db.user,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
function createDb(database, schema) {
|
|
26
|
+
const dialect = new PostgresDialect({
|
|
27
|
+
pool: new pg.Pool({
|
|
28
|
+
database: database,
|
|
29
|
+
host: config.db.host,
|
|
30
|
+
user: config.db.user,
|
|
31
|
+
password: config.db.password,
|
|
32
|
+
port: config.db.port,
|
|
33
|
+
max: 10,
|
|
34
|
+
}),
|
|
35
|
+
cursor: Cursor,
|
|
36
|
+
});
|
|
37
|
+
return new Kysely({
|
|
38
|
+
log: ["error"],
|
|
39
|
+
dialect: dialect,
|
|
40
|
+
}).withSchema(schema);
|
|
41
|
+
}
|
|
42
|
+
export const dbAmeli = createDb(datasets.ameli.database, datasets.ameli.schema);
|
|
43
|
+
export const dbDosleg = createDb(datasets.dosleg.database, datasets.dosleg.schema);
|
|
44
|
+
export const dbQuestions = createDb(datasets.questions.database, datasets.questions.schema);
|
|
45
|
+
export const dbSens = createDb(datasets.sens.database, datasets.sens.schema);
|
|
46
|
+
export let dbSharedConnectionObjectByName = {};
|
|
47
|
+
export async function checkDatabase(name) {
|
|
48
|
+
// Check that database exists.
|
|
49
|
+
const db = dbByName[name];
|
|
50
|
+
dbSharedConnectionObjectByName[name] = await db.connect();
|
|
51
|
+
return db;
|
|
52
|
+
}
|
|
53
|
+
export async function checkDatabases() {
|
|
54
|
+
for (const name of dbNames) {
|
|
55
|
+
await checkDatabase(name);
|
|
56
|
+
}
|
|
57
|
+
}
|
package/lib/databases.ts
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { Kysely, PostgresDialect } from "kysely"
|
|
2
|
+
import * as pg from "pg"
|
|
3
|
+
import { types } from "pg"
|
|
4
|
+
import Cursor from "pg-cursor"
|
|
5
|
+
import PgPromise from "pg-promise"
|
|
6
|
+
|
|
7
|
+
import config from "./config"
|
|
8
|
+
import { datasets } from "./datasets"
|
|
9
|
+
import { DB as AmeliDatabase } from "./raw_types_kysely/ameli"
|
|
10
|
+
import { DB as DoslegDatabase } from "./raw_types_kysely/dosleg"
|
|
11
|
+
import { DB as QuestionsDatabase } from "./raw_types_kysely/questions"
|
|
12
|
+
import { DB as SensDatabase } from "./raw_types_kysely/sens"
|
|
13
|
+
|
|
14
|
+
// Map int8 to number instead of string
|
|
15
|
+
// https://github.com/brianc/node-pg-types#use
|
|
16
|
+
pg.types.setTypeParser(types.builtins.INT8, (val) => {
|
|
17
|
+
return parseInt(val, 10)
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
export const pgPromise = PgPromise()
|
|
21
|
+
export const dbNames = ["ameli", "debats", "dosleg"]
|
|
22
|
+
export const dbByName: { [name: string]: any } = {}
|
|
23
|
+
for (const name of dbNames) {
|
|
24
|
+
dbByName[name] = pgPromise({
|
|
25
|
+
database: name,
|
|
26
|
+
host: config.db.host,
|
|
27
|
+
password: config.db.password,
|
|
28
|
+
port: config.db.port,
|
|
29
|
+
user: config.db.user,
|
|
30
|
+
})
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function createDb<T> (database: string, schema: string) {
|
|
34
|
+
const dialect = new PostgresDialect({
|
|
35
|
+
pool: new pg.Pool({
|
|
36
|
+
database: database,
|
|
37
|
+
host: config.db.host,
|
|
38
|
+
user: config.db.user,
|
|
39
|
+
password: config.db.password,
|
|
40
|
+
port: config.db.port,
|
|
41
|
+
max: 10,
|
|
42
|
+
}),
|
|
43
|
+
cursor: Cursor,
|
|
44
|
+
})
|
|
45
|
+
return new Kysely<T>({
|
|
46
|
+
log: ["error"],
|
|
47
|
+
dialect: dialect,
|
|
48
|
+
}).withSchema(schema)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export const dbAmeli = createDb<AmeliDatabase>(datasets.ameli.database, datasets.ameli.schema)
|
|
52
|
+
export const dbDosleg = createDb<DoslegDatabase>(datasets.dosleg.database, datasets.dosleg.schema)
|
|
53
|
+
export const dbQuestions = createDb<QuestionsDatabase>(datasets.questions.database, datasets.questions.schema)
|
|
54
|
+
export const dbSens = createDb<SensDatabase>(datasets.sens.database, datasets.sens.schema)
|
|
55
|
+
|
|
56
|
+
export let dbSharedConnectionObjectByName: {
|
|
57
|
+
[name: string]: PgPromise.IConnected<unknown, any>
|
|
58
|
+
} = {}
|
|
59
|
+
|
|
60
|
+
export async function checkDatabase(name: string) {
|
|
61
|
+
// Check that database exists.
|
|
62
|
+
const db = dbByName[name]
|
|
63
|
+
dbSharedConnectionObjectByName[name] = await db.connect()
|
|
64
|
+
return db
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export async function checkDatabases() {
|
|
68
|
+
for (const name of dbNames) {
|
|
69
|
+
await checkDatabase(name)
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export interface Dataset {
|
|
2
|
+
database: string;
|
|
3
|
+
repairEncoding: boolean;
|
|
4
|
+
repairZip?: (dataset: Dataset, dataDir: string) => void;
|
|
5
|
+
title: string;
|
|
6
|
+
url: string;
|
|
7
|
+
indexes?: {
|
|
8
|
+
[table: string]: Array<{
|
|
9
|
+
name: string;
|
|
10
|
+
columns: string[];
|
|
11
|
+
}>;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export interface Datasets {
|
|
15
|
+
ameli: Dataset;
|
|
16
|
+
debats: Dataset;
|
|
17
|
+
dosleg: Dataset;
|
|
18
|
+
questions: Dataset;
|
|
19
|
+
sens: Dataset;
|
|
20
|
+
}
|
|
21
|
+
export declare enum EnabledDatasets {
|
|
22
|
+
None = 0,
|
|
23
|
+
Ameli = 1,
|
|
24
|
+
Debats = 2,
|
|
25
|
+
DosLeg = 4,
|
|
26
|
+
Questions = 8,
|
|
27
|
+
Sens = 16,
|
|
28
|
+
PhotosSenateurs = 32,
|
|
29
|
+
Agenda = 64,
|
|
30
|
+
All = 127
|
|
31
|
+
}
|
|
32
|
+
export declare const datasets: Datasets;
|
|
33
|
+
export declare function getEnabledDatasets(categories: string[]): EnabledDatasets;
|
|
34
|
+
export declare function getChosenDatasets(enabledDatasets: EnabledDatasets): Dataset[];
|
package/lib/datasets.js
ADDED
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import fs from "fs-extra";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import assert from "assert";
|
|
4
|
+
export var EnabledDatasets;
|
|
5
|
+
(function (EnabledDatasets) {
|
|
6
|
+
EnabledDatasets[EnabledDatasets["None"] = 0] = "None";
|
|
7
|
+
EnabledDatasets[EnabledDatasets["Ameli"] = 1] = "Ameli";
|
|
8
|
+
EnabledDatasets[EnabledDatasets["Debats"] = 2] = "Debats";
|
|
9
|
+
EnabledDatasets[EnabledDatasets["DosLeg"] = 4] = "DosLeg";
|
|
10
|
+
EnabledDatasets[EnabledDatasets["Questions"] = 8] = "Questions";
|
|
11
|
+
EnabledDatasets[EnabledDatasets["Sens"] = 16] = "Sens";
|
|
12
|
+
EnabledDatasets[EnabledDatasets["PhotosSenateurs"] = 32] = "PhotosSenateurs";
|
|
13
|
+
EnabledDatasets[EnabledDatasets["Agenda"] = 64] = "Agenda";
|
|
14
|
+
EnabledDatasets[EnabledDatasets["All"] = 127] = "All";
|
|
15
|
+
})(EnabledDatasets || (EnabledDatasets = {}));
|
|
16
|
+
export const datasets = {
|
|
17
|
+
ameli: {
|
|
18
|
+
database: "ameli",
|
|
19
|
+
repairEncoding: true,
|
|
20
|
+
repairZip: (dataset, dataDir) => {
|
|
21
|
+
const sqlFilename = `${dataset.database}.sql`;
|
|
22
|
+
const sqlFilePath = path.join(dataDir, sqlFilename);
|
|
23
|
+
fs.removeSync(sqlFilePath);
|
|
24
|
+
fs.moveSync(path.join(dataDir, "var", "opt", "opendata", sqlFilename), sqlFilePath);
|
|
25
|
+
},
|
|
26
|
+
title: "Amendements",
|
|
27
|
+
url: "https://data.senat.fr/data/ameli/ameli.zip",
|
|
28
|
+
indexes: {
|
|
29
|
+
amdsen: [
|
|
30
|
+
{ name: "idx_amdid", columns: ["amdid"] },
|
|
31
|
+
{ name: "idx_senid", columns: ["senid"] },
|
|
32
|
+
{ name: "idx_grpid", columns: ["grpid"] },
|
|
33
|
+
],
|
|
34
|
+
sen_ameli: [{ name: "idx_entid", columns: ["entid"] }],
|
|
35
|
+
grppol_ameli: [{ name: "idx_entid", columns: ["entid"] }],
|
|
36
|
+
sub: [
|
|
37
|
+
{ name: "idx_id", columns: ["id"] },
|
|
38
|
+
{ name: "idx_typid", columns: ["typid"] },
|
|
39
|
+
{ name: "idx_merid", columns: ["merid"] },
|
|
40
|
+
{ name: "idx_comdelid", columns: ["comdelid"] },
|
|
41
|
+
],
|
|
42
|
+
typsub: [{ name: "idx_id", columns: ["id"] }],
|
|
43
|
+
typrect: [{ name: "idx_id", columns: ["id"] }],
|
|
44
|
+
txt_ameli: [
|
|
45
|
+
{ name: "idx_id", columns: ["id"] },
|
|
46
|
+
{ name: "idx_txtetaid", columns: ["txtetaid"] },
|
|
47
|
+
{ name: "idx_sesdepid", columns: ["sesdepid"] },
|
|
48
|
+
{ name: "idx_natid", columns: ["natid"] },
|
|
49
|
+
{ name: "idx_lecid", columns: ["lecid"] },
|
|
50
|
+
],
|
|
51
|
+
etatxt: [{ name: "idx_id", columns: ["id"] }],
|
|
52
|
+
ses: [
|
|
53
|
+
{ name: "idx_id", columns: ["id"] },
|
|
54
|
+
{ name: "idx_typid", columns: ["typid"] },
|
|
55
|
+
{ name: "idx_ann", columns: ["ann"] },
|
|
56
|
+
],
|
|
57
|
+
typses: [{ name: "idx_id", columns: ["id"] }],
|
|
58
|
+
nat: [{ name: "idx_id", columns: ["id"] }],
|
|
59
|
+
lec_ameli: [{ name: "idx_id", columns: ["id"] }],
|
|
60
|
+
mot: [{ name: "idx_id", columns: ["id"] }],
|
|
61
|
+
avicom: [{ name: "idx_id", columns: ["id"] }],
|
|
62
|
+
avigvt: [{ name: "idx_id", columns: ["id"] }],
|
|
63
|
+
sor: [{ name: "idx_id", columns: ["id"] }],
|
|
64
|
+
irr: [{ name: "idx_id", columns: ["id"] }],
|
|
65
|
+
com_ameli: [{ name: "idx_entid", columns: ["entid"] }],
|
|
66
|
+
cab: [{ name: "idx_entid", columns: ["entid"] }],
|
|
67
|
+
amd: [
|
|
68
|
+
{ name: "idx_subid", columns: ["subid"] },
|
|
69
|
+
{ name: "idx_typrectid", columns: ["typrectid"] },
|
|
70
|
+
{ name: "idx_txtid", columns: ["txtid"] },
|
|
71
|
+
{ name: "idx_motid", columns: ["motid"] },
|
|
72
|
+
{ name: "idx_avcid", columns: ["avcid"] },
|
|
73
|
+
{ name: "idx_avgid", columns: ["avgid"] },
|
|
74
|
+
{ name: "idx_sorid", columns: ["sorid"] },
|
|
75
|
+
{ name: "idx_irrid", columns: ["irrid"] },
|
|
76
|
+
{ name: "idx_nomentid", columns: ["nomentid"] },
|
|
77
|
+
],
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
debats: {
|
|
81
|
+
database: "debats",
|
|
82
|
+
repairEncoding: false,
|
|
83
|
+
title: "Informations relatives aux comptes rendus intégraux de la séance publique",
|
|
84
|
+
url: "https://data.senat.fr/data/debats/debats.zip",
|
|
85
|
+
indexes: {
|
|
86
|
+
secdis: [
|
|
87
|
+
{ name: "idx_datsea", columns: ["datsea"] },
|
|
88
|
+
{ name: "idx_typseccod", columns: ["typseccod"] },
|
|
89
|
+
],
|
|
90
|
+
intpjl: [{ name: "idx_secdiscle", columns: ["secdiscle"] }],
|
|
91
|
+
secdivers: [
|
|
92
|
+
{ name: "idx_datsea", columns: ["datsea"] },
|
|
93
|
+
{ name: "idx_typseccod", columns: ["typseccod"] },
|
|
94
|
+
],
|
|
95
|
+
intdivers: [{ name: "idx_intdiverscle", columns: ["intdiverscle"] }],
|
|
96
|
+
lecassdeb: [{ name: "idx_datsea", columns: ["datsea"] }],
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
dosleg: {
|
|
100
|
+
database: "dosleg",
|
|
101
|
+
repairEncoding: false,
|
|
102
|
+
title: "Dossiers législatifs",
|
|
103
|
+
url: "https://data.senat.fr/data/dosleg/dosleg.zip",
|
|
104
|
+
indexes: {
|
|
105
|
+
amescr: [{ name: "idx_scrnum", columns: ["scrnum"] }],
|
|
106
|
+
auteur: [{ name: "idx_autcod", columns: ["autcod"] }],
|
|
107
|
+
corscr: [{ name: "idx_scrnum", columns: ["scrnum"] }],
|
|
108
|
+
date_seance: [
|
|
109
|
+
{ name: "idx_code", columns: ["code"] },
|
|
110
|
+
{ name: "idx_lecidt", columns: ["lecidt"] },
|
|
111
|
+
],
|
|
112
|
+
deccoc: [{ name: "idx_deccoccod", columns: ["deccoccod"] }],
|
|
113
|
+
etaloi: [{ name: "idx_etaloicod", columns: ["etaloicod"] }],
|
|
114
|
+
lecass: [
|
|
115
|
+
{ name: "idx_lecidt", columns: ["lecidt"] },
|
|
116
|
+
{ name: "idx_codass", columns: ["codass"] },
|
|
117
|
+
{ name: "idx_orgcod", columns: ["orgcod"] },
|
|
118
|
+
{ name: "idx_orippr", columns: ["orippr"] },
|
|
119
|
+
],
|
|
120
|
+
lecassrap: [
|
|
121
|
+
{ name: "idx_rapcod", columns: ["rapcod"] },
|
|
122
|
+
{ name: "idx_lecassidt", columns: ["lecassidt"] },
|
|
123
|
+
],
|
|
124
|
+
lecture: [
|
|
125
|
+
{ name: "idx_loicod", columns: ["loicod"] },
|
|
126
|
+
{ name: "idx_typleccod", columns: ["typleccod"] },
|
|
127
|
+
{ name: "idx_lecidt", columns: ["lecidt"] },
|
|
128
|
+
],
|
|
129
|
+
loi: [
|
|
130
|
+
{ name: "idx_typloicod", columns: ["typloicod"] },
|
|
131
|
+
{ name: "idx_etaloicod", columns: ["etaloicod"] },
|
|
132
|
+
{ name: "idx_deccoccod", columns: ["deccoccod"] },
|
|
133
|
+
{ name: "idx_loicod", columns: ["loicod"] },
|
|
134
|
+
],
|
|
135
|
+
loithe: [
|
|
136
|
+
{ name: "idx_thecle", columns: ["thecle"] },
|
|
137
|
+
{ name: "idx_loicod", columns: ["loicod"] },
|
|
138
|
+
],
|
|
139
|
+
posvot: [{ name: "idx_posvotcod", columns: ["posvotcod"] }],
|
|
140
|
+
rap: [
|
|
141
|
+
{ name: "idx_rapcod", columns: ["rapcod"] },
|
|
142
|
+
{ name: "idx_coddenrap", columns: ["coddenrap"] },
|
|
143
|
+
],
|
|
144
|
+
rolsig: [{ name: "idx_signataire", columns: ["signataire"] }],
|
|
145
|
+
scr: [
|
|
146
|
+
{ name: "idx_code", columns: ["code"] },
|
|
147
|
+
{ name: "idx_scrnum", columns: ["scrnum"] },
|
|
148
|
+
{ name: "idx_sesann", columns: ["sesann"] },
|
|
149
|
+
],
|
|
150
|
+
stavot: [{ name: "idx_stavotidt", columns: ["stavotidt"] }],
|
|
151
|
+
texte: [
|
|
152
|
+
{ name: "idx_lecassidt", columns: ["lecassidt"] },
|
|
153
|
+
{ name: "idx_oritxtcod", columns: ["oritxtcod"] },
|
|
154
|
+
{ name: "idx_typtxtcod", columns: ["typtxtcod"] },
|
|
155
|
+
{ name: "idx_texcod", columns: ["texcod"] },
|
|
156
|
+
],
|
|
157
|
+
the: [{ name: "idx_thecle", columns: ["thecle"] }],
|
|
158
|
+
titsen: [{ name: "idx_titsencod", columns: ["titsencod"] }],
|
|
159
|
+
typloi: [{ name: "idx_typloicod", columns: ["typloicod"] }],
|
|
160
|
+
typtxt: [{ name: "idx_typtxtcod", columns: ["typtxtcod"] }],
|
|
161
|
+
votsen: [
|
|
162
|
+
{ name: "idx_scrnum", columns: ["scrnum"] },
|
|
163
|
+
{ name: "idx_sesann", columns: ["sesann"] },
|
|
164
|
+
{ name: "idx_titsencod", columns: ["titsencod"] },
|
|
165
|
+
{ name: "idx_stavotidt", columns: ["stavotidt"] },
|
|
166
|
+
{ name: "idx_posvotcod", columns: ["posvotcod"] },
|
|
167
|
+
{ name: "idx_senmat", columns: ["senmat"] },
|
|
168
|
+
],
|
|
169
|
+
},
|
|
170
|
+
},
|
|
171
|
+
questions: {
|
|
172
|
+
database: "questions",
|
|
173
|
+
repairEncoding: false,
|
|
174
|
+
title: "Questions écrites et orales posées par les sénateurs au Gouvernement",
|
|
175
|
+
url: "https://data.senat.fr/data/questions/questions.zip",
|
|
176
|
+
indexes: {
|
|
177
|
+
tam_reponses: [{ name: "idx_idque", columns: ["idque"] }],
|
|
178
|
+
tam_questions: [
|
|
179
|
+
{ name: "idx_sorquecod", columns: ["sorquecod"] },
|
|
180
|
+
{ name: "idx_etaquecod", columns: ["etaquecod"] },
|
|
181
|
+
],
|
|
182
|
+
the: [{ name: "idx_thenouidt", columns: ["thenouidt"] }],
|
|
183
|
+
sortquestion: [{ name: "idx_sorquecod", columns: ["sorquecod"] }],
|
|
184
|
+
etatquestion: [{ name: "idx_etaquecod", columns: ["etaquecod"] }],
|
|
185
|
+
},
|
|
186
|
+
},
|
|
187
|
+
sens: {
|
|
188
|
+
database: "sens",
|
|
189
|
+
repairEncoding: false,
|
|
190
|
+
repairZip: (dataset, dataDir) => {
|
|
191
|
+
const sqlFilename = `${dataset.database}.sql`;
|
|
192
|
+
const sqlFilePath = path.join(dataDir, sqlFilename);
|
|
193
|
+
fs.removeSync(sqlFilePath);
|
|
194
|
+
fs.moveSync(path.join(dataDir, "export_sens.sql"), sqlFilePath);
|
|
195
|
+
},
|
|
196
|
+
title: "Sénateurs (y compris organes et présence)",
|
|
197
|
+
url: "https://data.senat.fr/data/senateurs/export_sens.zip",
|
|
198
|
+
indexes: {
|
|
199
|
+
dpt: [
|
|
200
|
+
{ name: "idx_dptnum", columns: ["dptnum"] },
|
|
201
|
+
{ name: "idx_regcod", columns: ["regcod"] },
|
|
202
|
+
],
|
|
203
|
+
activite_loi: [{ name: "idx_actid", columns: ["actid"] }],
|
|
204
|
+
activite_delegation: [{ name: "idx_actid", columns: ["actid"] }],
|
|
205
|
+
activite_participant: [{ name: "idx_senmat", columns: ["senmat"] }],
|
|
206
|
+
activite_senateur: [{ name: "idx_senmat", columns: ["senmat"] }],
|
|
207
|
+
senbur: [
|
|
208
|
+
{ name: "idx_senmat", columns: ["senmat"] },
|
|
209
|
+
{ name: "idx_burcod", columns: ["burcod"] },
|
|
210
|
+
],
|
|
211
|
+
elucan: [
|
|
212
|
+
{ name: "idx_senmat", columns: ["senmat"] },
|
|
213
|
+
{ name: "idx_typmancod", columns: ["typmancod"] },
|
|
214
|
+
],
|
|
215
|
+
},
|
|
216
|
+
},
|
|
217
|
+
};
|
|
218
|
+
export function getEnabledDatasets(categories) {
|
|
219
|
+
categories.map((datasetName) => assert.notStrictEqual(EnabledDatasets[datasetName], undefined, `Unknown name of dataset: ${datasetName}`));
|
|
220
|
+
return categories.reduce((enabledDatasets, datasetName) => {
|
|
221
|
+
const enabledDataset = EnabledDatasets[datasetName];
|
|
222
|
+
return enabledDatasets | (enabledDataset || EnabledDatasets.None);
|
|
223
|
+
}, EnabledDatasets.None);
|
|
224
|
+
}
|
|
225
|
+
export function getChosenDatasets(enabledDatasets) {
|
|
226
|
+
return [
|
|
227
|
+
enabledDatasets & EnabledDatasets.Ameli ? datasets.ameli : null,
|
|
228
|
+
enabledDatasets & EnabledDatasets.Debats ? datasets.debats : null,
|
|
229
|
+
enabledDatasets & EnabledDatasets.DosLeg ? datasets.dosleg : null,
|
|
230
|
+
enabledDatasets & EnabledDatasets.Questions ? datasets.questions : null,
|
|
231
|
+
enabledDatasets & EnabledDatasets.Sens ? datasets.sens : null,
|
|
232
|
+
].filter((dataset) => dataset !== null);
|
|
233
|
+
}
|
package/lib/datasets.mjs
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import fs from "fs-extra";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import assert from "assert";
|
|
4
|
+
export var EnabledDatasets;
|
|
5
|
+
(function (EnabledDatasets) {
|
|
6
|
+
EnabledDatasets[EnabledDatasets["None"] = 0] = "None";
|
|
7
|
+
EnabledDatasets[EnabledDatasets["Ameli"] = 1] = "Ameli";
|
|
8
|
+
EnabledDatasets[EnabledDatasets["Debats"] = 2] = "Debats";
|
|
9
|
+
EnabledDatasets[EnabledDatasets["DosLeg"] = 4] = "DosLeg";
|
|
10
|
+
EnabledDatasets[EnabledDatasets["Questions"] = 8] = "Questions";
|
|
11
|
+
EnabledDatasets[EnabledDatasets["Sens"] = 16] = "Sens";
|
|
12
|
+
EnabledDatasets[EnabledDatasets["PhotosSenateurs"] = 32] = "PhotosSenateurs";
|
|
13
|
+
EnabledDatasets[EnabledDatasets["All"] = 63] = "All";
|
|
14
|
+
})(EnabledDatasets || (EnabledDatasets = {}));
|
|
15
|
+
export const datasets = {
|
|
16
|
+
ameli: {
|
|
17
|
+
database: "ameli",
|
|
18
|
+
repairEncoding: false,
|
|
19
|
+
repairZip: (dataset, dataDir) => {
|
|
20
|
+
const sqlFilename = `${dataset.database}.sql`;
|
|
21
|
+
const sqlFilePath = path.join(dataDir, sqlFilename);
|
|
22
|
+
fs.removeSync(sqlFilePath);
|
|
23
|
+
fs.moveSync(path.join(dataDir, "var", "opt", "opendata", sqlFilename), sqlFilePath);
|
|
24
|
+
},
|
|
25
|
+
schema: "public",
|
|
26
|
+
title: "Amendements",
|
|
27
|
+
url: "https://data.senat.fr/data/ameli/ameli.zip",
|
|
28
|
+
},
|
|
29
|
+
debats: {
|
|
30
|
+
database: "debats",
|
|
31
|
+
repairEncoding: true,
|
|
32
|
+
schema: "public",
|
|
33
|
+
title: "Informations relatives aux comptes rendus intégraux de la séance publique",
|
|
34
|
+
url: "https://data.senat.fr/data/debats/debats.zip",
|
|
35
|
+
},
|
|
36
|
+
dosleg: {
|
|
37
|
+
database: "dosleg",
|
|
38
|
+
repairEncoding: true,
|
|
39
|
+
schema: "public",
|
|
40
|
+
title: "Dossiers législatifs",
|
|
41
|
+
url: "https://data.senat.fr/data/dosleg/dosleg.zip",
|
|
42
|
+
},
|
|
43
|
+
questions: {
|
|
44
|
+
database: "questions",
|
|
45
|
+
repairEncoding: true,
|
|
46
|
+
schema: "questions",
|
|
47
|
+
title: "Questions écrites et orales posées par les sénateurs au Gouvernement",
|
|
48
|
+
url: "https://data.senat.fr/data/questions/questions.zip",
|
|
49
|
+
},
|
|
50
|
+
sens: {
|
|
51
|
+
database: "sens",
|
|
52
|
+
repairEncoding: true,
|
|
53
|
+
repairZip: (dataset, dataDir) => {
|
|
54
|
+
const sqlFilename = `${dataset.database}.sql`;
|
|
55
|
+
const sqlFilePath = path.join(dataDir, sqlFilename);
|
|
56
|
+
fs.removeSync(sqlFilePath);
|
|
57
|
+
fs.moveSync(path.join(dataDir, "export_sens.sql"), sqlFilePath);
|
|
58
|
+
},
|
|
59
|
+
schema: "public",
|
|
60
|
+
title: "Sénateurs (y compris organes et présence)",
|
|
61
|
+
url: "https://data.senat.fr/data/senateurs/export_sens.zip",
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
export function getEnabledDatasets(categories) {
|
|
65
|
+
categories.map((datasetName) => assert.notStrictEqual(EnabledDatasets[datasetName], undefined, `Unknown name of dataset: ${datasetName}`));
|
|
66
|
+
return categories.reduce((enabledDatasets, datasetName) => enabledDatasets |
|
|
67
|
+
EnabledDatasets[datasetName], EnabledDatasets.None);
|
|
68
|
+
}
|
|
69
|
+
export function getChosenFromEnabledDatasets(categories) {
|
|
70
|
+
const enabledDatasets = getEnabledDatasets(categories);
|
|
71
|
+
return [
|
|
72
|
+
enabledDatasets & EnabledDatasets.Ameli ? datasets.ameli : null,
|
|
73
|
+
enabledDatasets & EnabledDatasets.Debats ? datasets.debats : null,
|
|
74
|
+
enabledDatasets & EnabledDatasets.DosLeg ? datasets.dosleg : null,
|
|
75
|
+
enabledDatasets & EnabledDatasets.Questions ? datasets.questions : null,
|
|
76
|
+
enabledDatasets & EnabledDatasets.Sens ? datasets.sens : null,
|
|
77
|
+
].filter((dataset) => dataset !== null);
|
|
78
|
+
}
|