reddit-user-dump
Advanced tools
Comparing version 0.0.3 to 0.0.4
37
index.js
@@ -20,3 +20,2 @@ var request = ('request'); | ||
function pullJSON(path, callback) { | ||
readStream.emit('api_call'); | ||
request({ | ||
@@ -43,3 +42,3 @@ url: 'http://www.reddit.com/' + path, | ||
} catch (err) { | ||
readStream.emit('error', err); | ||
readStream.emit('error', err, body); | ||
} | ||
@@ -55,18 +54,22 @@ | ||
if (err) return next(e); | ||
last = body.data.after | ||
var count = 0 | ||
body.data.children.forEach(function(item) { | ||
if (item.data.created > lastParsed) { | ||
if (item.kind === 't1') readStream.emit('comment', item); | ||
if (item.kind === 't3') readStream.emit('submission', item); | ||
readStream.push(item); | ||
count++; | ||
} else { | ||
body.data.after = null; | ||
} | ||
}); | ||
readStream.emit('page', last, count); | ||
if (body.data.after) next(); | ||
else readStream.push(null) | ||
try { | ||
last = body.data.after | ||
var count = 0 | ||
body.data.children.forEach(function(item) { | ||
if (item.data.created > lastParsed) { | ||
if (item.kind === 't1') readStream.emit('comment', item); | ||
if (item.kind === 't3') readStream.emit('submission', item); | ||
readStream.push(item); | ||
count++; | ||
} else { | ||
body.data.after = null; | ||
} | ||
}); | ||
readStream.emit('page', last, count); | ||
if (body.data.after) next(); | ||
else readStream.push(null) | ||
} catch (err) { | ||
readStream.emit('error', err, body); | ||
} | ||
}); | ||
@@ -73,0 +76,0 @@ } |
{ | ||
"name": "reddit-user-dump", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "dumps a redditor's history in json", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -40,5 +40,2 @@ reddit-user-dump | ||
}) | ||
.on('metrics', function(metrics) { | ||
console.log(metrics + ' requests per second'); | ||
}) | ||
.on('page', function(after, count) { | ||
@@ -45,0 +42,0 @@ total += count; |
var lastParsed = 0; | ||
var assert = require('assert') | ||
var totalApiCalls = 0; | ||
var totalPages = 0; | ||
var total = 0; | ||
function wrapper(username, callback) { | ||
@@ -9,3 +13,2 @@ var test = require('../index.js') | ||
var commentCount = 0; | ||
var total = 0; | ||
@@ -23,7 +26,9 @@ test(username, lastParsed) | ||
}) | ||
.on('metrics', function(metrics) { | ||
.on('api_call', function(metrics) { | ||
console.log(metrics + ' requests per second'); | ||
totalApiCalls +=1; | ||
}) | ||
.on('page', function(after, count) { | ||
total += count; | ||
totalPages += 1; | ||
console.log('page complete found', | ||
@@ -42,3 +47,4 @@ 'submission: ', submissionCount, 'comment', commentCount, 'total', total); | ||
.on('error', function(err) { | ||
console.log('err', err) | ||
//console.log('err', err) | ||
throw(err) | ||
}); | ||
@@ -48,4 +54,4 @@ } | ||
wrapper('hortinstein', function() { | ||
assert.equal(totalPages, totalApiCalls); | ||
}); | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6818
127
70