Ajoute un script pour extraire les données du fichier NomenclatureGuichet

pull/2524/head
Johan Girod 2023-02-09 18:15:50 +01:00 committed by Jérémy Rialland
parent a31a584425
commit e8296a2e68
6 changed files with 1110 additions and 1 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,48 @@
import parseCsv from 'csv-parser'
import fs from 'fs'
import { join } from 'path'
import { fileURLToPath } from 'url'
const FILENAME = 'NomenclatureGuichet_v1_26resana.csv'
const __dirname = fileURLToPath(new URL('.', import.meta.url))
const results = [] as Array<Activity>
fs.createReadStream(join(__dirname, FILENAME))
.pipe(
parseCsv({
separator: ';',
skipLines: 1,
mapHeaders: ({ header }) =>
(header.match(/.+?(?=\n)/)?.[0] ?? header).trim(),
mapValues: ({ header, value }) =>
(header === 'Codes APE compatibles' && value.split(' ; ')) || value,
})
)
.on('data', (data) => results.push(data))
.on('end', () => {
fs.writeFileSync(
join(__dirname, 'raw_output.json'),
JSON.stringify(results)
)
fs.writeFileSync(
join(__dirname, 'ape_tags.json'),
JSON.stringify(computeAPETag(results))
)
})
type CodeAPE = string
type Activity = {
'Niv. 1': string
'Niv. 2': string
'Niv. 3': string
'Niv. 4': string
'Codes APE compatibles': Array<CodeAPE>
}
function computeAPETag(
results: Array<Activity>
): Record<CodeAPE, Array<string>> {
return {}
}

File diff suppressed because one or more lines are too long

View File

@ -12,6 +12,7 @@
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start:données-NAF-CPF-APE": "ts-node-esm ./données-NAF-CPF-APE/convert-pdf.ts",
"start:données-NomenclatureGuichet": "ts-node-esm ./données-NomenclatureGuichet/convert.ts",
"start:nombre-etablissements-par-code-ape-et-departement": "ts-node-esm ./nombre-etablissements-par-code-ape-et-departement/convert-json.ts",
"start:données-code-APE": "ts-node-esm ./données-code-APE/reduce-json.ts",
"start:watch:données-NAF-CPF-APE": "nodemon -x 'yarn start:données-NAF-CPF-APE' -e 'ts'",
@ -20,6 +21,8 @@
},
"dependencies": {
"@types/stream-json": "^1.7.2",
"csv": "^6.2.7",
"csv-parser": "^3.0.0",
"got": "^12.5.3",
"pdfdataextract": "^3.2.0",
"stream-json": "^1.7.5",

View File

@ -35,7 +35,8 @@
"include": [
"données-code-APE/reduce-json.ts",
"données-NAF-CPF-APE/convert.ts",
"nombre-etablissements-par-code-ape-et-departement/convert-json.ts"
"nombre-etablissements-par-code-ape-et-departement/convert-json.ts",
"données-NomenclatureGuichet/convert.ts"
],
"exclude": ["**/node_modules"]
}

View File

@ -12820,6 +12820,8 @@ __metadata:
resolution: "converters@workspace:converters"
dependencies:
"@types/stream-json": ^1.7.2
csv: ^6.2.7
csv-parser: ^3.0.0
got: ^12.5.3
nodemon: ^2.0.20
pdfdataextract: ^3.2.0
@ -13297,6 +13299,50 @@ __metadata:
languageName: node
linkType: hard
"csv-generate@npm:^4.2.2":
version: 4.2.2
resolution: "csv-generate@npm:4.2.2"
checksum: f262698c92376261c928779335850c583f5d6ea9f2e476ba476ece7c9fb70bdafe634a4f3024721d44e46b7c50d2135d5932fa383f4fbe48dcaa642635052b2f
languageName: node
linkType: hard
"csv-parse@npm:^5.3.5":
version: 5.3.5
resolution: "csv-parse@npm:5.3.5"
checksum: 077e010db2ebbc9db708b719f2f650577c5ec8d176cd4363235d6644c36c642811d05ef1b6907390dd7466bde20a8dbb0f34994bc0e101521eb09e6691a02206
languageName: node
linkType: hard
"csv-parser@npm:^3.0.0":
version: 3.0.0
resolution: "csv-parser@npm:3.0.0"
dependencies:
minimist: ^1.2.0
bin:
csv-parser: bin/csv-parser
checksum: adc9d67d9f185249825570778c24d13004625301655330f6b735a052b9fdfbe1a239a014afb1f89939e0626ee573718f71f9f14164db7c17e4bcb2f38d6a162b
languageName: node
linkType: hard
"csv-stringify@npm:^6.2.4":
version: 6.2.4
resolution: "csv-stringify@npm:6.2.4"
checksum: 12d8ab299735ad6c1ca90b37d900d66ef0fcc4289f565df7c67cbeed33f2de56daeae19094a215aa7d3bde8877c0a105f1aeb531e4f582d7561f213b0680c99d
languageName: node
linkType: hard
"csv@npm:^6.2.7":
version: 6.2.7
resolution: "csv@npm:6.2.7"
dependencies:
csv-generate: ^4.2.2
csv-parse: ^5.3.5
csv-stringify: ^6.2.4
stream-transform: ^3.2.2
checksum: 0c8a310ddbe79ad78ff82ceeca72f2bc1090e876803c00fa43886c87a0bf5bd2ec5a51977dafe533acdec9da410ce84e70b66c756b47abe56b215c1379eaf92f
languageName: node
linkType: hard
"currently-unhandled@npm:^0.4.1":
version: 0.4.1
resolution: "currently-unhandled@npm:0.4.1"
@ -26975,6 +27021,13 @@ __metadata:
languageName: node
linkType: hard
"stream-transform@npm:^3.2.2":
version: 3.2.2
resolution: "stream-transform@npm:3.2.2"
checksum: bc368a623b65f91d4d7faff90c46b740401fddedd79a4b325e5f9319d227894a84aca0e459d92177a679d5006d7ada3f46ebb514a1712da60b2e8beca54111c4
languageName: node
linkType: hard
"streamx@npm:^2.12.5":
version: 2.12.5
resolution: "streamx@npm:2.12.5"