Created
January 13, 2013 21:09
-
-
Save atduskgreg/4526232 to your computer and use it in GitHub Desktop.
Simple Ruby script to download images from a Flickr group.
This file contains 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 '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