Created
January 21, 2011 17:53
-
-
Save yoshuki/790081 to your computer and use it in GitHub Desktop.
Backup Instagram photos.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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