reddit-user-dump
Advanced tools
Comparing version 0.0.5 to 0.0.6
21
index.js
@@ -9,3 +9,12 @@ var request = ('request'); | ||
var qs = require('querystring') | ||
var redditStats = require('measured').createCollection(); | ||
var requests_per_second = function() { | ||
try { | ||
var reqsPerSec = redditStats.toJSON().requestsPerSecond.mean; | ||
} catch (err) { | ||
var reqsPerSec = 0; | ||
} | ||
return reqsPerSec; | ||
} | ||
@@ -21,2 +30,3 @@ module.exports = function(username, lastParsed) { | ||
function pullJSON(path, callback) { | ||
redditStats.meter('requestsPerSecond').mark(); | ||
request({ | ||
@@ -31,4 +41,4 @@ url: 'http://www.reddit.com/' + path, | ||
pullJSON(username_path, function(error, res, user_data) { | ||
if (error) { | ||
callback(error, null); | ||
if (error || user_data.error) { | ||
readStream.emit('user', userObj); | ||
} else { | ||
@@ -44,3 +54,3 @@ try { | ||
} catch (err) { | ||
readStream.emit('error', err, user_data); | ||
} | ||
@@ -55,3 +65,3 @@ | ||
pullJSON(path, function(err, res, body) { | ||
if (err) return next(e); | ||
if (err || body.error) return next; | ||
try { | ||
@@ -79,2 +89,5 @@ last = body.data.after | ||
} | ||
setTimeout(function() { | ||
readStream.emit('metrics', requests_per_second()); | ||
}, 5 * 1000); | ||
@@ -81,0 +94,0 @@ function loop() { |
{ | ||
"name": "reddit-user-dump", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"description": "dumps a redditor's history in json", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -7,2 +7,3 @@ var lastParsed = 0; | ||
var total = 0; | ||
function wrapper(username, callback) { | ||
@@ -28,3 +29,3 @@ var test = require('../index.js') | ||
console.log(metrics + ' requests per second'); | ||
totalApiCalls +=1; | ||
totalApiCalls += 1; | ||
}) | ||
@@ -48,9 +49,14 @@ .on('page', function(after, count) { | ||
//console.log('err', err) | ||
throw(err) | ||
throw (err) | ||
}); | ||
} | ||
wrapper('hortinstein', function(e, r) { | ||
// wrapper('hortinstein', function() { | ||
// assert.equal(totalPages, totalApiCalls); | ||
// }); | ||
}); | ||
wrapper('nina1987', function(e, r) { | ||
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
7322
143