Skip to content

Instantly share code, notes, and snippets.

@marekmierzwa
Forked from adamcooke/cloudapp-export.rb
Last active May 3, 2022 13:32
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save marekmierzwa/b0094df1bddf658c7e25 to your computer and use it in GitHub Desktop.
Save marekmierzwa/b0094df1bddf658c7e25 to your computer and use it in GitHub Desktop.
#!/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:
#
# sudo gem install cloudapp_api
# ruby cloudapp-export.rb adam@atechmedia.com mypassword
#
EMAIL_ADDRESS = ARGV[0]
PASSWORD = ARGV[1]
ROOT = File.expand_path('../cloudapp-export', __FILE__)
PER_PAGE = 50
require 'fileutils'
require 'cloudapp_api'
def sanitize_filename(filename)
filename.gsub(/[^0-9A-z.\-]/, '_')
end
CloudApp.authenticate(EMAIL_ADDRESS, PASSWORD)
dirctory = 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 = drop.created_at
# directory = File.join(ROOT, time.year.to_s, time.month.to_s, time.day.to_s)
# FileUtils.mkdir_p(directory)
directory = ROOT
path = File.join(directory, sanitize_filename(drop.name.to_s))
if File.exist?(path)
puts " -> Skipping #{drop.name} (it already exists)"
else
puts " -> Downloading #{drop.name}"
begin
File.open(path, 'w') { |f| f.write(drop.redirect_url ? drop.redirect_url : drop.raw) }
rescue Exception => e
puts "Error: #{e.message}"
end
end
end
page += 1
returned_drops = drops.size
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment