Download recent flickr pictures with ruby and the flickr api
// Get one here: http://www.flickr.com/services/api/misc.api_keys.html
// Other than that, just plug and chug and have fun!
// The "b" in "wb" in the second open method may not be necessary in
// non-windows environments.
1 2 require 'open-uri' 3 require 'rexml/document' 4 5 open('http://www.flickr.com/services/rest/?method=flickr.photos.getRecent&api_key=YOUR_KEY_HERE') { |f| 6 doc = REXML::Document.new f.read 7 i = 0 8 doc.elements.each("rsp/photos/photo") { |element| 9 if i < 3 10 open("images/file" << i.to_s << ".jpg", "wb"). 11 write(open("http://static.flickr.com/" << \ 12 element.attributes["server"] << "/" << \ 13 element.attributes["id"] << "_" << \ 14 element.attributes["secret"] << "_o.jpg").read) 15 else 16 break 17 end 18 i = i + 1 19 } 20 } 21 22 puts "Done!"