gist: 4757 Download_button fork
public
Description:
Munge Flickr to find yourself in photos.
Public Clone URL: git://gist.github.com/4757.git
flickr-geo-munge.rb
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/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(from, to)
  URI::Generic.build(
    :scheme => "http",
    :host => "api.flickr.com",
    :path => "/services/rest/",
    :query => hash_to_query_string(
      :method => "flickr.photos.search",
      :api_key => "SET YOUR API KEY",
      :lat => "51.505577",
      :lon => "-0.075359",
      :radius => "0.3",
      :extras => "geo,date_taken",
      :min_taken_date => from.to_s(:db),
      :max_taken_date => to.to_s(:db)
    )
  ).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
 
# from 0 to 300 days ago
(0..300).to_a.reverse.each do |i|
  date = i.days.ago.beginning_of_day
  next if date.wday == 0 or date.wday == 6 # skip weekends
  from = date - 1.day
  to = date
  
  doc = Hpricot(open(get_uri(from, to)))
  photo_elements = doc.search("//photo")
  puts "#{date.to_s} - #{photo_elements.length}"
  
  photo_elements.each do |element|
    datetaken = DateTime.parse(element[:datetaken])
    # between these times
    if (datetaken.hour == 9 and datetaken.min >= 0 and datetaken.min <= 40) or (datetaken.hour == 18 and datetaken.min >= 0 and datetaken.min <= 30)
      url = "http://www.flickr.com/photos/#{element[:owner]}/#{element[:id]}"
      puts "Found! #{url}"
      # open straight in the browser
      `open #{url}`
    end
  end
end
 
 

Owner

tomtaylor

Revisions