Skip to content

Instantly share code, notes, and snippets.

@richsoni
Created April 30, 2015 19:31
Show Gist options
  • Save richsoni/3c7bfb1791cd2f6e51d6 to your computer and use it in GitHub Desktop.
Save richsoni/3c7bfb1791cd2f6e51d6 to your computer and use it in GitHub Desktop.
github points
#! /usr/local/bin/node
var request = require('sync-request');
var fs = require('fs');
var path = require('path');
var nameObj = {};
for (var i = 2; i < process.argv.length; i++) {
var name = process.argv[i];
var fileExist = fs.existsSync('./' + name + '.json');
if (fileExist) {
var output = fs.readFileSync(name + '.json').toString();
}
else {
var response = request('GET','https://api.github.com/users/' + process.argv[i], {
headers: {
'User-Agent': 'request'
}
})
var output = response.body.toString()
fs.writeFile(name + '.json',output)
}
output = JSON.parse(output)
nameObj[process.argv[i]] = output.followers;
}
var sortable = [];
for (var key in nameObj) {
var arr = [];
arr[0] = key,
arr[1] = nameObj[key];
sortable.push(arr);
}
sortable.sort(function(a, b) {return b[1] - a[1]})
var winner = sortable.shift();
console.log(winner[0] + ' wins with a score of ' + winner[1])
sortable.forEach(function(el) {
console.log(el[0] + ' has a score of ' + el[1])
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment