-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Khanh Dao
authored and
Khanh Dao
committed
Jun 15, 2021
1 parent
0e2348d
commit 702eb51
Showing
5 changed files
with
657 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
const csv = require('csv-parser') | ||
const fs = require('fs') | ||
|
||
const myArgs = process.argv.slice(2); | ||
console.log('myArgs: ', myArgs); | ||
|
||
const filename = myArgs[0]; | ||
const keyText = myArgs[1] ?? 'key'; | ||
const valueText = myArgs[2] ?? 'value'; | ||
|
||
const results = []; | ||
|
||
fs.createReadStream(filename) | ||
.pipe(csv()) | ||
.on('data', (data) => { | ||
// console.log('>>>> data', data); | ||
results.push({ | ||
id: data['category_id'], | ||
vanity_name: data['Vanity URL']?.replace('https://linkedin.com/products/categories/', ''), | ||
}); | ||
}) | ||
.on('end', () => { | ||
let str = ''; | ||
for (let i = 0; i < results.length; i++) { | ||
const { id, vanity_name } = results[i]; | ||
str += `\u0020\u0020\<entry ${keyText}="${id}" ${valueText}="${vanity_name}"/>\n`; | ||
} | ||
const final_str = `<map>\n${str}</map>`; | ||
if (!!final_str) { | ||
fs.writeFile('result.txt', final_str, (err) => { | ||
// throws an error, you could also catch it here | ||
if (err) throw err; | ||
|
||
// success case, the file was saved | ||
console.log('Line saved!'); | ||
}); | ||
} | ||
}); |
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,6 @@ | ||
{ | ||
"dependencies": { | ||
"csv-parse": "^4.15.4", | ||
"csv-parser": "^3.0.0" | ||
} | ||
} |
Oops, something went wrong.