# i needed some sample data for some code for http://everlater.com. # # i needed nice images - interesting ones - and whipped this up to grab them # in batches from flickr # module Flickr require 'open-uri' require 'uri' InterestingImages = [] def interesting_image if InterestingImages.empty? 4.times do |i| begin html = open('http://www.flickr.com/explore/interesting/7days/'){|fd| fd.read} uris = URI.extract(html, 'http') uris.select do |uri| next unless uri =~ /\.jpg$/ InterestingImages.push(uri.gsub(%r/_m/, '')) end break rescue raise if i==3 sleep(rand) end end end InterestingImages.shift end def interesting_images [interesting_image, *InterestingImages] ensure InterestingImages.clear end extend(Flickr) end puts Flickr.interesting_images __END__ sample output: http://farm3.static.flickr.com/2573/4160132171_3c9184e19e.jpg http://farm3.static.flickr.com/2563/4150990118_f2b706da09.jpg http://farm3.static.flickr.com/2542/4166089723_6cd18aae18.jpg http://farm3.static.flickr.com/2679/4161575076_ce6b53761b.jpg http://farm3.static.flickr.com/2788/4156182830_045f9ef127.jpg http://farm3.static.flickr.com/2521/4152135266_bedafaec3c.jpg http://farm3.static.flickr.com/2672/4155815112_7ce5c8c8ab.jpg http://farm3.static.flickr.com/2771/4151792403_73ebc9320c.jpg http://farm3.static.flickr.com/2567/4155299948_47fbe459f5.jpg