Skip to content

Instantly share code, notes, and snippets.

@yoshuki
Created January 21, 2011 17:53
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yoshuki/790081 to your computer and use it in GitHub Desktop.
Save yoshuki/790081 to your computer and use it in GitHub Desktop.
Backup Instagram photos.
require 'fileutils'
require 'net/http'
require 'instagram'
USER_ID = # Your id as integer.
def main
photos = Instagram::by_user(USER_ID)
photos.each do |photo|
photo.images.each do |image_url|
print "#{image_url} ... "
image = URI.parse(image_url.to_s)
image_path = image.path.sub(%r!^/!, '')
image_dir, image_base = File.split(image_path)
FileUtils.mkdir_p(image_dir) unless Dir.exist?(image_dir)
File.open(image_path, 'wb') {|f| f.write(Net::HTTP.get(image)) }
puts 'done.'
end
end
rescue => evar
puts evar.message
end
if $0 == __FILE__
main
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment