Created
January 10, 2019 23:58
-
-
Save joelhooks/d46fd96586f132582c1cc22273bffd5e to your computer and use it in GitHub Desktop.
This is a little node app that creates individual csv files for each tag in an exported Drip subscriber (people!) csv
This file contains hidden or 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
const _ = require('lodash') | |
const fs = require('fs') | |
const csv = require('csv-parser') | |
const writer = require('fast-csv') | |
const csvFilePath = 'PATH_TO.csv' | |
const filesToBuild = {} | |
fs.createReadStream(csvFilePath) | |
.pipe(csv()) | |
.on('data', function(row) { | |
const filterFor = 'sent - ' // only looking for tags with a specific string | |
row.tags = _.filter(row.tags.split(','), tag => tag.includes(filterFor)) | |
row.tags.forEach(tag => { | |
const { tags, ...props } = row | |
//each tag will get its own csv output, so add it to the hash | |
filesToBuild[tag] = filesToBuild[tag] || [] | |
filesToBuild[tag].push({ ...props }) | |
}) | |
}) | |
.on('end', function() { | |
_.keys(filesToBuild).forEach(key => { | |
//go through all the filtered tags and write a csv file with the appropriate rows | |
writer.writeToPath(`./${key}.csv`, filesToBuild[key], { headers: true }).on('finish', function() { | |
console.log(`wrote ${key}.csv`) | |
}) | |
}) | |
}) |
This file contains hidden or 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
{ | |
"name": "parse_drip", | |
"version": "1.0.0", | |
"description": "", | |
"main": "drip_to_convertkit.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "", | |
"license": "ISC", | |
"dependencies": { | |
"csv-parser": "^2.1.0", | |
"fast-csv": "^2.4.1", | |
"lodash": "^4.17.11" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment