-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ajout du script de recupération des urls de gestion pour les speakers
- Loading branch information
1 parent
06a85a3
commit 32aac8e
Showing
3 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
const fs = require('fs'); | ||
const createCsvWriter = require('csv-writer').createObjectCsvWriter; | ||
|
||
// Fonction principale | ||
async function convertJsonToCsv(inputFilePath, outputFilePath) { | ||
try { | ||
// Lire le fichier JSON | ||
const jsonData = JSON.parse(fs.readFileSync(inputFilePath, 'utf8')); | ||
|
||
// Vérification de la structure attendue | ||
if (!jsonData || !Array.isArray(jsonData)) { | ||
throw new Error("Le fichier JSON n'a pas le format attendu."); | ||
} | ||
// Créer un tableau contenant les données pour le CSV | ||
const csvData = jsonData.filter(item => item.speakersFullNames.length > 0) | ||
.map(item => ({ | ||
talkId: item.talkId, | ||
talkTitle: item.speakersFullNames.join(', '), | ||
registrationUrl: "https://"+item.registrationUrl | ||
})); | ||
|
||
// Configurer le writer CSV | ||
const csvWriter = createCsvWriter({ | ||
path: outputFilePath, | ||
header: [ | ||
{ id: 'talkId', title: 'talkId' }, | ||
{ id: 'talkTitle', title: 'talkTitle' }, | ||
{ id: 'registrationUrl', title: 'registrationUrl' } | ||
] | ||
}); | ||
|
||
// Écrire les données dans le fichier CSV | ||
await csvWriter.writeRecords(csvData); | ||
|
||
console.log(`Fichier CSV généré avec succès : ${outputFilePath}`); | ||
} catch (error) { | ||
console.error(`Erreur : ${error.message}`); | ||
} | ||
} | ||
|
||
// Récupérer les paramètres de la ligne de commande | ||
const args = process.argv.slice(2); | ||
|
||
if (args.length < 1) { | ||
console.error("Usage : node talks-url.cjs <chemin_du_fichier_JSON> [<chemin_du_fichier_CSV>]"); | ||
process.exit(1); | ||
} | ||
|
||
const inputFilePath = args[0]; | ||
const outputFilePath = args.length > 1 ? args[1] : 'talks-url.csv'; | ||
convertJsonToCsv(inputFilePath, outputFilePath); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters