Skip to content

Instantly share code, notes, and snippets.

@visnup
Created August 7, 2010 22:48
Show Gist options
  • Save visnup/513284 to your computer and use it in GitHub Desktop.
Save visnup/513284 to your computer and use it in GitHub Desktop.
def photos_from_flickr
api_key = 'blargh'
url = "http://api.flickr.com/services/rest/?method=flickr.collections.getTree&api_key=#{api_key}&collection_id=20446502-72157624005829771&user_id=20451842%40N05&format=json&nojsoncallback=1"
@sets = open url do |f|
collection = JSON.parse(f.read)['collections']['collection'].first
collection['set'].map do |set|
url = "http://api.flickr.com/services/rest/?method=flickr.photosets.getPhotos&api_key=#{api_key}&photoset_id=#{set['id']}&format=json&nojsoncallback=1"
photos = open(url) { |f| JSON.parse(f.read)['photoset']['photo'] }
photos.each do |p|
p['href'] = "http://www.flickr.com/photos/20451842%40N05/#{p['id']}"
p['src'] = "http://farm#{p['farm']}.static.flickr.com/#{p['server']}/#{p['id']}_#{p['secret']}_s.jpg"
end
{ 'title' => set['title'],
'photos' => photos }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment