Skip to content

Instantly share code, notes, and snippets.

@whiskers75
Created June 8, 2014 11:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whiskers75/c2f210380565708a7702 to your computer and use it in GitHub Desktop.
Save whiskers75/c2f210380565708a7702 to your computer and use it in GitHub Desktop.
Node.js script to get GHash.io hash %
var request = require('request');
var htmlparser = require('htmlparser');
var $ = require('soupselect').select;
request('https://ghash.io/', function(err, res, body) {
if (err || res.statusCode != 200) {
return console.log('Error.');
}
var handler = new htmlparser.DefaultHandler(function(err, dom) {
if (err) {
throw err;
} else {
var ghashio = Number($(dom, 'div.speed')[0].children[0].data.replace(' Ph/s', '')) * 1000000000000000; // hashes per sec.
request('https://blockchain.info/q/hashrate', function(err2, res2, body2) {
if (err2 || res.statusCode != 200) return console.log('Error.');
var total = Number(body2) * 1000000000;
console.log('It is estimated (from scraping their site) GHash.io control ' + ((ghashio / total) * 100).toFixed(2) + '% of the Bitcoin network.');
});
}
});
var parser = new htmlparser.Parser(handler);
parser.parseComplete(body);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment