Skip to content

Instantly share code, notes, and snippets.

@tomtaylor
Created August 10, 2008 19:17
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/4757 to your computer and use it in GitHub Desktop.
Save tomtaylor/4757 to your computer and use it in GitHub Desktop.
Munge Flickr to find yourself in photos.
#!/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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment