Created
June 8, 2014 11:19
-
-
Save whiskers75/c2f210380565708a7702 to your computer and use it in GitHub Desktop.
Node.js script to get GHash.io hash %
This file contains 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 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