Skip to content

Instantly share code, notes, and snippets.

@adamcooke
Created January 11, 2013 15:45
Show Gist options
  • Select an option

  • Save adamcooke/4511658 to your computer and use it in GitHub Desktop.

Select an option

Save adamcooke/4511658 to your computer and use it in GitHub Desktop.

Revisions

  1. Adam Cooke revised this gist Jan 11, 2013. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions cloudapp-export.rb
    Original file line number Diff line number Diff line change
    @@ -4,6 +4,7 @@
    # To run this just run the script passing your e-mail & password
    # to the script, for example:
    #
    # gem install cloudapp_api
    # ruby cloudapp-export.rb [email protected] mypassword
    #

  2. Adam Cooke created this gist Jan 11, 2013.
    39 changes: 39 additions & 0 deletions cloudapp-export.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,39 @@
    #!/usr/bin/env ruby

    # A quick script to download all your files from CloudApp.
    # To run this just run the script passing your e-mail & password
    # to the script, for example:
    #
    # ruby cloudapp-export.rb [email protected] mypassword
    #

    EMAIL_ADDRESS = ARGV[0]
    PASSWORD = ARGV[1]
    ROOT = File.expand_path('../cloudapp-export', __FILE__)
    PER_PAGE = 50

    require 'fileutils'
    require 'cloudapp_api'

    CloudApp.authenticate(EMAIL_ADDRESS, PASSWORD)
    FileUtils.mkdir_p(ROOT)
    returned_drops = nil
    page = 1
    until returned_drops && returned_drops < PER_PAGE
    drops = CloudApp::Drop.all(:per_page => PER_PAGE, :page => page)
    puts "Getting Page: #{page}"
    for drop in drops
    time = Time.parse(drop.created_at)
    directory = File.join(ROOT, time.year.to_s, time.month.to_s, time.day.to_s)
    FileUtils.mkdir_p(directory)
    path = File.join(directory, drop.name)
    if File.exist?(path)
    puts " -> Skipping #{drop.name} (it already exists)"
    else
    puts " -> Downloading #{drop.name}"
    File.open(path, 'w') { |f| f.write(drop.raw) }
    end
    end
    page += 1
    returned_drops = drops.size
    end