Skip to content

Instantly share code, notes, and snippets.

@emre
Created March 1, 2013 16:16
Show Gist options
  • Select an option

  • Save emre/5065711 to your computer and use it in GitHub Desktop.

Select an option

Save emre/5065711 to your computer and use it in GitHub Desktop.
tweet freezer
function TweetFreezer(casper_instance) {
this.casper = casper_instance;
this.tweet_url = false;
this.set_tweet_url = function(tweet_url) {
this.tweet_url = tweet_url;
return this;
};
/* extracts tweet id from the url */
this.find_tweet_id = function() {
var match = this.tweet_url.match("status/([0-9]*)?");
if (match) {
return match[1];
}
return false;
};
this.freeze_tweet = function () {
console.log('freezing.');
console.log(this.tweet_url);
tweet_id = this.find_tweet_id();
casper.start(this.tweet_url, function() {
this.captureSelector( tweet_id+ ".png", '.permalink-tweet-container');
this.echo('{"status": "success"}');
});
casper.run();
};
this.init = function() {
tweet_url = casper.cli.get(0);
if(typeof tweet_url == 'undefined') {
console.log('{"status": "error"}');
casper.exit();
}
this.set_tweet_url(tweet_url);
if(!this.is_tweet_url_valid()) {
console.log({'status': "error"});
casper.exit();
}
this.freeze_tweet();
};
this.is_tweet_url_valid = function() {
var match = this.tweet_url.match("https?://twitter.com/[a-zA-Z_-]+/status/[0-9]+/?");
if(match) {
return true;
}
return false;
}
}
var casper = require("casper").create();
tweet_freezer = new TweetFreezer(casper);
tweet_freezer.init();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment