Created
June 28, 2012 09:32
-
-
Save n1k0/3010212 to your computer and use it in GitHub Desktop.
Finds your daily SublimeText2 package using CasperJS. Yeah, randomly.
This file contains hidden or 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
/** | |
* Finds your daily SublimeText2 package. Yeah, randomly. | |
* | |
* Requires CasperJS: http://casperjs.org/ | |
* | |
* Usage: $ casperjs sublime-day.js | |
*/ | |
var casper = require('casper').create(); | |
var f = require("utils").format; | |
var packages = []; | |
casper.start('http://wbond.net/sublime_packages/community#sort-lastmodified', function() { | |
packages = this.evaluate(function() { | |
function nodeText(node) { | |
return node.textContent.trim().replace(/\s+/g, ' '); | |
} | |
return [].map.call(__utils__.findAll('.package'), function(node) { | |
return { | |
'Name ': nodeText(__utils__.findOne('a', node)), | |
'Link ': __utils__.findOne('a', node).getAttribute('href'), | |
'Last modified': nodeText(__utils__.findOne('span.last_modified', node)), | |
'Description ': nodeText(__utils__.findOne('p', node)), | |
'Version ': nodeText(__utils__.findOne('span.version', node)), | |
'Installs ': nodeText(__utils__.findOne('span.installs', node)) | |
}; | |
}); | |
}); | |
}); | |
casper.run(function() { | |
if (packages.length < 1) { | |
this.die('no package found', 1); | |
} | |
var _package = packages[Math.floor(Math.random() * packages.length)]; | |
this.echo("Found your daily SublimeText2 package:", "INFO_BAR", 80).echo(''); | |
Object.keys(_package).sort(function(a, b) { | |
return a > b; | |
}).forEach(function(key) { | |
casper.echo(f(" %s: %s", key, casper.getColorizer().colorize(_package[key], 'COMMENT'))); | |
}); | |
this.echo().echo('Have a nice day.', 'GREEN_BAR', 80).exit(); | |
}); |
Author
n1k0
commented
Jun 28, 2012
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment