Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Simple Ruby script to download images from a Flickr group.
require 'flickraw'
# get your flickr api key here: http://www.flickr.com/services/apps/create/apply
API_KEY = "PUT YOURS HERE"
SECRET = "PUT YOURS HERE"
ACCESS_TOKEN = "PUT YOURS HERE"
ACCESS_SECRET = "PUT YOURS HERE"
gid = "ID of group to download from" # i.e. "16978849@N00" is the blackandwhite group
FlickRaw.api_key = API_KEY
FlickRaw.shared_secret = SECRET
flickr.access_token = ACCESS_TOKEN
flickr.access_secret = ACCESS_SECRET
login = flickr.test.login
def get_page(page, gid)
puts "requesting page: #{page}"
photos = flickr.groups.pools.getPhotos(:group_id => gid, :per_page => 500, :page => page)
photos.each_with_index do |photo, i|
puts "downloading #{i + 1}/#{photos.length}"
begin
sizes = flickr.photos.getSizes(:photo_id => photo["id"])
original = sizes.select{|s| s["label"] == "Original"}.first
`cd images; wget #{original["source"]}`
rescue Exception => e
open("log.txt", "a"){|f| f << "FAIL: photoid: #{photo["id"]}\terror: #{e}\n"}
end
end
if photos.length == 500
get_page( page + 1 )
end
end
get_page(1, gid)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.