Skip to content

Instantly share code, notes, and snippets.

@n1k0
Created June 28, 2012 09:32
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save n1k0/3010212 to your computer and use it in GitHub Desktop.
Save n1k0/3010212 to your computer and use it in GitHub Desktop.
Finds your daily SublimeText2 package using CasperJS. Yeah, randomly.
/**
* 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();
});
@n1k0
Copy link
Author

n1k0 commented Jun 28, 2012

Capture

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment