Skip to content

Instantly share code, notes, and snippets.

@silviopaganini
Created July 25, 2013 13:46
Show Gist options
  • Save silviopaganini/6079775 to your computer and use it in GitHub Desktop.
Save silviopaganini/6079775 to your computer and use it in GitHub Desktop.
Download the latest Appliness PDF
var http = require('http'),
fs = require('fs'),
$ = require('jquery');
var issues = [];
function downloadIssue()
{
var lastIndexSlash = issues[0].lastIndexOf('/') + 1;
var filename = issues[0].substring(lastIndexSlash, issues[0].length);
var file = fs.createWriteStream(filename);
var request = http.get(issues[0], function(response) {
response.pipe(file);
response.on('end', function(){console.log('download complete');});
});
}
http.get('http://www.appliness.com/download/', function (res) {
res.setEncoding('utf8');
console.log("reading list of files");
res.on('data', function (chunk) {
a = $(chunk).find("[href$='.pdf']").each(function(index, value){
issues.push($(value).attr('href'));
});
});
res.on('end', function(a){
console.log("started downloading...");
downloadIssue();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment