Skip to content

Instantly share code, notes, and snippets.

@d4rckh
Created March 2, 2020 14:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save d4rckh/86fde03139f0bcb896c52af303986a17 to your computer and use it in GitHub Desktop.
Save d4rckh/86fde03139f0bcb896c52af303986a17 to your computer and use it in GitHub Desktop.
Script to grab r/cats !
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