Skip to content

Instantly share code, notes, and snippets.

@nauzilus
Last active August 29, 2015 14:13
Show Gist options
  • Save nauzilus/363c7401ccb9e60a5f0f to your computer and use it in GitHub Desktop.
Save nauzilus/363c7401ccb9e60a5f0f to your computer and use it in GitHub Desktop.
Naive web host ranking from whirlpool thread
// https://forums.whirlpool.net.au/forum-replies.cfm?t=65599&p=-2
var results={}; [].slice.call(document.querySelectorAll('.replytext.bodytext p')).forEach(function(v) {
var text = [].slice.call(v.childNodes).map(function(c) {
return (
c.textContent.length === 0 || (
c.classList &&
c.classList.contains("wcrep1")
)) ? "\n" : c.textContent;
}).join("");
var host = (text.match(/Name\s*:\s*(\w[\w ]+)/)|| [,''])[1]
var rating = (text.match(/Rating\s*:\s*(\d+)/)|| [,''])[1]
if ( host.length && rating.length ) {
host = host.toLowerCase().replace(/ /g, "")
results[host] = results[host] || [];
results[host].push(+rating)
}
})
var csv = Object.keys(results).map(function(host) {
var avg = results[host].reduce(function(p,v) { return p + v }, 0) / results[host].length
var str = host + "," + avg + "," + results[host].length + "," + results[host].join("|");
console.log(str)
return str;
}).join("\n")
if (typeof copy !== "undefined") {
copy(csv)
console.log("copied to clipboard")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment