Skip to content

Instantly share code, notes, and snippets.

@jpcofr
Forked from thomastraum/download_gists.js
Created August 2, 2017 12:45
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 jpcofr/159cebdca2ac15babd9426c8003b6dfc to your computer and use it in GitHub Desktop.
Save jpcofr/159cebdca2ac15babd9426c8003b6dfc to your computer and use it in GitHub Desktop.
Gist to download all your gists
var request = require('request')
, path = require('path')
, fs = require('fs')
, url = "https://api.github.com/users/thomastraum/gists"
, savepath = './gists';
request(url, function (error, response, body) {
if (!error && response.statusCode == 200) {
gists = JSON.parse( body );
gists.forEach( function(gist) {
console.log( "description: ", gist.description );
var dir = savepath + '/' + gist.description;
fs.mkdir( dir, function(err){
for(var file in gist.files){
var raw_url = gist.files[file].raw_url;
var filename = gist.files[file].filename;
console.log( "downloading... " + filename );
request(raw_url).pipe(fs.createWriteStream( dir + '/' + filename ));
}
});
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment