Permalink
Browse files

add horrible quick n dirty github stars. Closes #2

  • Loading branch information...
1 parent ac7e9b1 commit 92156745d131512d5fed922dddd00c998caa21c0 @tj tj committed Sep 16, 2012
Showing with 24 additions and 5 deletions.
  1. +23 −5 fetch.js
  2. +1 −0 package.json
View
@@ -4,18 +4,21 @@
*/
var wiki = require('component-wiki')
+ , request = require('superagent')
, redis = require('redis')
, db = redis.createClient()
, fs = require('fs');
+// NOTE: quick / horrid code lives here ;D
+
var pending = 0;
+var packages;
db.flushdb();
wiki(function(err, pkgs){
if (err) throw err;
-
- fs.writeFileSync('components.json', JSON.stringify(pkgs));
+ packages = pkgs;
pkgs.forEach(function(pkg){
if (!pkg) return;
@@ -26,13 +29,25 @@ wiki(function(err, pkgs){
words = words.concat(pkg.keywords || []);
++pending;
- db.set('component:' + pkg.repo, JSON.stringify(pkg), done);
+ request
+ .get('https://api.github.com/repos/' + pkg.repo + '/stargazers')
+ .end(function(res){
+ done();
+
+ if (res.ok) {
+ pkg.stars = res.body.length;
+ console.log('%s stars: %d', pkg.repo, pkg.stars);
+ }
+
+ ++pending;
+ db.set('component:' + pkg.repo, JSON.stringify(pkg), done);
+ })
++pending;
db.sadd('components', pkg.repo, done);
words.forEach(function(word){
- console.log(' %s', word);
+ console.log(' "%s"', word);
++pending;
db.sadd('word:' + word, pkg.repo, done);
});
@@ -46,5 +61,8 @@ function parse(str) {
}
function done() {
- --pending || process.exit();
+ --pending || (function(){
+ fs.writeFileSync('components.json', JSON.stringify(packages));
+ process.exit();
+ })();
}
View
@@ -5,6 +5,7 @@
"dependencies": {
"express": "3.x",
"redis": "0.8.1",
+ "superagent": "0.9.1",
"component-wiki": "0.0.1"
}
}

0 comments on commit 9215674

Please sign in to comment.