Created
September 9, 2008 19:02
-
-
Save tomtaylor/9738 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'hpricot' | |
require 'open-uri' | |
require 'activesupport' | |
require 'uri' | |
# Set the longitude, latitude and radius of your search in here. And your api key. | |
def get_uri | |
URI::Generic.build( | |
:scheme => "http", | |
:host => "api.flickr.com", | |
:path => "/services/rest/", | |
:query => hash_to_query_string( | |
:method => "flickr.photos.search", | |
:api_key => "APIKEY", | |
:lat => "51.505577", | |
:lon => "-0.075359", | |
:per_page => 5, | |
:radius => "20", | |
:radius_units => "mi", | |
:tags => "cat, cats, kitten, kittens", | |
:tag_mode => "any", | |
:extras => "geo" | |
) | |
).to_s | |
end | |
def hash_to_query_string(args={}) | |
args.map { |k,v| "%s=%s" % [URI.encode(k.to_s), URI.encode(v.to_s)] }.join('&') unless args.blank? | |
end | |
doc = Hpricot(open(get_uri)) | |
photo_elements = doc.search("//photo") | |
photo_elements.each do |element| | |
url = "http://www.flickr.com/photos/#{element[:owner]}/#{element[:id]}" | |
system("open #{url}") | |
# puts element | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment