Created
April 6, 2015 17:53
-
-
Save azdle/2e6ca63973896f14f599 to your computer and use it in GitHub Desktop.
Minnebar Vanity Script
This file contains hidden or 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
var _ = require('underscore'), | |
async = require('async'), | |
page = require('webpage').create(), | |
system = require('system'); | |
if (system.args.length !== 3) { | |
console.log('Usage: count.js <min_id> <max_id>'); | |
phantom.exit(); | |
} | |
var min_id = parseInt(system.args[1]); | |
var max_id = parseInt(system.args[2]); | |
var id_range = _.range(min_id, max_id); | |
async.mapSeries(id_range, | |
function(item, callback) { | |
page.open('http://sessions.minnestar.org/sessions/' + item, function(status) { | |
if (status !== "success") { | |
console.log(status); | |
callback(status, null); | |
return; | |
} | |
var title = page.evaluate(function() { | |
return document.title; | |
}); | |
if (title === "The page you were looking for doesn't exist (404)") { | |
callback(null, {count: 0, title: null}); | |
return; | |
} | |
var count = page.evaluate(function() { | |
return document.getElementById('participants').children.length; | |
}); | |
callback(null, {count: count, title: title}); | |
}); | |
}, | |
function(err, results) { | |
results = results.filter(function(element){ return element.title !== null }); | |
results.sort(function(a, b) {return a.count - b.count}); | |
for (var i = 0; i < results.length; i++) { | |
console.log("" + results[i].count + " people are intrested in '" + results[i].title + "'."); | |
}; | |
phantom.exit(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment