Skip to content

Commit

Permalink
add empty rows to csv file
Browse files Browse the repository at this point in the history
  • Loading branch information
diversen7 committed Nov 18, 2024
1 parent 4a2a00c commit 25e5098
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions bin/add-rows.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// get first parameter 'url' from the command line
// get second parameter 'num_rows' from the command line
const url = process.argv[2];
const num_rows = process.argv[3];

// if not parameters passed, show error message
if (!url || !num_rows) {
console.log('Please provide URL and number of rows.');
process.exit(1);
}


function generateRandomString() {
return Math.random().toString(36).substr(2, 7);
}

// Add rows to the CSV file in this format
// File,URL
// random-string.html,url
const fs = require('fs');

const rows = [];
for (let i = 0; i < num_rows; i++) {
const randomString = generateRandomString();
const fileName = randomString + '.html';
rows.push(`${fileName},${url}`);
}

fs.appendFileSync('bin/redirects.csv', '\n' + rows.join('\n') );
console.log('Rows have been added successfully.');

0 comments on commit 25e5098

Please sign in to comment.