-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd-uuids.js
More file actions
50 lines (41 loc) · 1.44 KB
/
add-uuids.js
File metadata and controls
50 lines (41 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
const fs = require('fs').promises;
const { parse } = require('csv-parse');
const { stringify } = require('csv-stringify');
const { v4: uuidv4 } = require('uuid');
async function addUUIDsToCSV() {
const inputFile = 'Discord_chat_Mon Oct 14 2024 12_11_33 GMT+0100 (British Summer Time)_Tue Oct 14 2025 00_00_00 GMT+0100 (British Summer Time).csv';
const outputFile = 'discord_messages_with_uuid.csv';
try {
const fileContent = await fs.readFile(inputFile, 'utf8');
const records = await new Promise((resolve, reject) => {
parse(fileContent, {
columns: true,
skip_empty_lines: true,
bom: true
}, (err, output) => {
if (err) reject(err);
else resolve(output);
});
});
const recordsWithUUID = records.map(record => ({
id: uuidv4(),
...record
}));
const output = await new Promise((resolve, reject) => {
stringify(recordsWithUUID, {
header: true,
columns: ['id', 'Date', 'Username', 'User tag', 'Content', 'Mentions', 'link']
}, (err, output) => {
if (err) reject(err);
else resolve(output);
});
});
await fs.writeFile(outputFile, output);
console.log(`✓ Successfully processed ${recordsWithUUID.length} messages`);
console.log(`✓ Output saved to: ${outputFile}`);
} catch (error) {
console.error('Error processing CSV:', error);
process.exit(1);
}
}
addUUIDsToCSV();