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
0 parents
commit 11aa73d
Showing
6 changed files
with
438 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
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,2 @@ | ||
*.csv | ||
node_modules |
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 @@ | ||
simple script to read a drip export and convert it to a csv for each tag. |
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,32 @@ | ||
const _ = require('lodash') | ||
const fs = require('fs') | ||
const csv = require('csv-parser') | ||
const writer = require('fast-csv') | ||
|
||
const csvFilePath = './subscribers.csv' | ||
const tagSep = ',' | ||
const filterFor = '' // only looking for tags with a specific string | ||
const filesToBuild = {} | ||
|
||
fs.createReadStream(csvFilePath) | ||
.pipe(csv()) | ||
.on('data', function(row) { | ||
row.tags = _.filter(row.tags.split(tagSep), tag => tag.includes(filterFor)) | ||
row.tags.forEach(tag => { | ||
const {tags, ...props} = row | ||
const trimmedTag = _.trim(tag) | ||
//each tag will get its own csv output, so add it to the hash | ||
filesToBuild[trimmedTag] = filesToBuild[trimmedTag] || [] | ||
filesToBuild[trimmedTag].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`) | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.