Skip to content

Instantly share code, notes, and snippets.

@tomtaylor
Created September 9, 2008 19:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomtaylor/9738 to your computer and use it in GitHub Desktop.
Save tomtaylor/9738 to your computer and use it in GitHub Desktop.
#!/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