Created
March 2, 2020 14:42
-
-
Save d4rckh/86fde03139f0bcb896c52af303986a17 to your computer and use it in GitHub Desktop.
Script to grab r/cats !
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
const request = require('request') | |
const fs = require('fs') | |
const sr = 'cats' | |
var i = 0 | |
var download = function(uri, filename, callback){ | |
request.head(uri, function(err, res, body){ | |
request(uri).pipe(fs.createWriteStream(filename)).on('close', callback); | |
}); | |
}; | |
request("https://www.reddit.com/r/" + sr + "/top/.json", {}, (e, r, b) => { | |
const cats = JSON.parse(b); | |
cats.data.children.forEach((cat) => { | |
download(cat.data.url, cat.data.id + '.jpg', function(){ | |
i+=1 | |
console.log('Downloaded ' + cat.data.id + " post! Currently downloaded " + i + " posts."); | |
}); | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment