tomtaylor (owner)

Revisions

gist: 9738 Download_button fork
public
Public Clone URL: git://gist.github.com/9738.git
Embed All Files: show embed
Text #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/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