multi-account-post-schedule.../wip/convert_csv_abonnements.js
2025-01-12 15:03:07 +01:00

38 lines
1.2 KiB
JavaScript

const fs = require('fs');
const csv = require('csv-parser');
const csvFile = 'documents/mastodon_accounts_following.csv';
const jsonFile = 'documents/recommendations_abonnements_tk.json';
fs.createReadStream(csvFile)
.pipe(csv())
.on('data', (row) => {
const account = {
accountAddress: row['Account address'],
showBoosts: row['Show boosts'] === 'true',
notifyOnNewPosts: row['Notify on new posts'] === 'true',
languages: row.Languages.split(','),
};
console.log(account);
})
.on('end', () => {
console.log('Fin de la lecture du fichier CSV');
});
// Pour écrire le résultat en JSON
const jsonData = [];
fs.createReadStream(csvFile)
.pipe(csv())
.on('data', (row) => {
const account = {
accountAddress: row['Account address'],
showBoosts: row['Show boosts'] === 'true',
notifyOnNewPosts: row['Notify on new posts'] === 'true',
languages: row.Languages.split(','),
};
jsonData.push(account);
})
.on('end', () => {
fs.writeFileSync(jsonFile, JSON.stringify(jsonData, null, 2));
console.log('Fichier JSON généré');
});