Saturday, August 06, 2011

Flickr interestingness downloader in Ruby

And this time this is the Ruby code using Flickraw gem to download large size versions of Flickr interesting photos.

require 'flickraw'

FlickRaw.api_key="api_key"
FlickRaw.shared_secret="shared_secret"

photos = flickr.interestingness.getList( :per_page => 500 )

frob = flickr.auth.getFrob
auth_url = FlickRaw.auth_url :frob => frob, :perms => 'read'

photos.each do |pic|
photo_info = flickr.photos.getInfo(:photo_id => pic.id)
photo_url = FlickRaw.url_b(photo_info)

puts "Downloading #{photo_url}"

open("flickr/" + pic.id + ".jpg", "wb") { |file|
file.write(Net::HTTP.get_response(URI.parse(photo_url)).body)
}
end
Post a Comment