-
-
Save jb55/0ea6aba86e269f1e526b to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env node | |
var argv = require('minimist')(process.argv.slice(2)); | |
var scrape = require('sbscrape').stats; | |
var csv = require('csv-parse'); | |
var stringify = require('JSONStream').stringify; | |
var ytParse = require('parse-youtube-user'); | |
var queue = require('concurrent-map-stream'); | |
var through = require('through'); | |
var concurrency = argv.j || 10; | |
process.stdin | |
.pipe(csv()) | |
.pipe(through(function(row){ | |
var user = row[0].trim(); | |
this.push(ytParse(user)) | |
})) | |
.pipe(queue(worker, concurrency)) | |
.pipe(stringify(false)) | |
.pipe(process.stdout) | |
function worker(user, done) { | |
user = user.trim(); | |
if (!user) return done(null, { error: "empty user" }) | |
scrape(user, function(err, scraped){ | |
if (err) return done(null, { error: err }); | |
scraped = scraped || {}; | |
scraped.user = user; | |
done(null, scraped); | |
}); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment