Skip to content

Commit

Permalink
hello git
Browse files Browse the repository at this point in the history
  • Loading branch information
joelhooks committed Jan 15, 2019
0 parents commit 11aa73d
Show file tree
Hide file tree
Showing 6 changed files with 438 additions and 0 deletions.
Binary file added .DS_Store
Binary file not shown.
2 changes: 2 additions & 0 deletions .gitignore
@@ -0,0 +1,2 @@
*.csv
node_modules
1 change: 1 addition & 0 deletions README.md
@@ -0,0 +1 @@
simple script to read a drip export and convert it to a csv for each tag.
32 changes: 32 additions & 0 deletions index.js
@@ -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`)
})
})
})

0 comments on commit 11aa73d

Please sign in to comment.