Created
July 25, 2013 13:46
-
-
Save silviopaganini/6079775 to your computer and use it in GitHub Desktop.
Download the latest Appliness PDF
This file contains 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
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