Skip to content

Instantly share code, notes, and snippets.

@ParkinT
Forked from emad-elsaid/gist-download.rb
Created March 30, 2014 00:57
Show Gist options
  • Select an option

  • Save ParkinT/9865608 to your computer and use it in GitHub Desktop.

Select an option

Save ParkinT/9865608 to your computer and use it in GitHub Desktop.

Revisions

  1. @emad-elsaid emad-elsaid created this gist Mar 14, 2014.
    26 changes: 26 additions & 0 deletions gist-download.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    #!/usr/bin/env ruby
    require 'open-uri'
    require 'json'

    print 'Github Username: '
    username = gets.chomp

    # get gists
    puts 'Downloading gists list'
    gists_str = open("https://api.github.com/users/#{username}/gists").read
    gists = JSON.parse gists_str

    gists.each_with_index do |gist, index|

    puts "#{index+1}/#{gists.length} Downloading #{gist['url']}"
    gist_str = open(gist['url']).read
    gist = JSON.parse gist_str

    dir = gist["id"]
    Dir.mkdir dir unless Dir.exist? dir

    gist["files"].each do |file_name, file_value|
    File.open("#{dir}/#{file_name}", 'w') { |f| f.write file_value['content']}
    end

    end