-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate-sample-csv.ts
More file actions
36 lines (27 loc) · 1.11 KB
/
generate-sample-csv.ts
File metadata and controls
36 lines (27 loc) · 1.11 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
import fs from 'fs';
import { parse } from 'json2csv';
// Configuration
const INPUT_FILE = 'comments-cleaned.json';
const OUTPUT_FILE = 'nick-sample-feedback.csv';
// Read and parse the comments-cleaned.json file
const comments = JSON.parse(fs.readFileSync(INPUT_FILE, 'utf-8'));
// Deduplicate comments based on commentLink
const uniqueComments = Array.from(
new Map(comments.map((comment: any) => [comment.commentLink, comment])).values()
);
console.log(`Original comment count: ${comments.length}`);
console.log(`Unique comment count: ${uniqueComments.length}`);
console.log(`Removed ${comments.length - uniqueComments.length} duplicates`);
// Define the fields for the CSV
const fields = ['repo', 'comment_url', 'feedback_nick'];
// Map the comments to the desired CSV format
const csvData = uniqueComments.map((comment: any) => ({
repo: comment.repo,
comment_url: comment.commentLink,
feedback_nick: '' // Empty feedback nick
}));
// Convert JSON to CSV
const csv = parse(csvData, { fields });
// Write the CSV to a file
fs.writeFileSync(OUTPUT_FILE, csv);
console.log(`CSV file generated: ${OUTPUT_FILE}`);