Skip to content

Commit

Permalink
Merge pull request #66 from anct-cnum/Creation_extract_cras_outil_prefet
Browse files Browse the repository at this point in the history
Création d'export de cras car metabase est limité à 1M de ligne
  • Loading branch information
MorganP-projects authored Sep 15, 2023
2 parents 22c2524 + 7836996 commit 36afd1e
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/tasks/scripts/extract-cras-csv.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env node
'use strict';
const path = require('path');
const fs = require('fs');
const { program } = require('commander');
const { execute } = require('../utils');

require('dotenv').config();

execute(__filename, async ({ logger, dbDatalake }) => {
program.helpOption('-e', 'HELP command');
program.parse(process.argv);

const cursor = await dbDatalake.collection('cras').find();

logger.info(`Generating CSV file...`);
let csvFile = path.join(__dirname, '../../../data/exports', `cras.csv`);
let file = fs.createWriteStream(csvFile, { flags: 'w' });

file.write(`ID;ConseillerId;Cra;CreatedAt;UpdatedAt;PermanenceId;StructureId\n`);
while (await cursor.hasNext()) {
const cra = await cursor.next();
file.write(`${cra._id};${cra.conseillerId};${JSON.stringify(cra.cra)};${cra.createdAt};${cra.updatedAt};${cra.permanenceId};${cra.structureId};\n`);
}

file.close();
});

0 comments on commit 36afd1e

Please sign in to comment.