Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
get Roland's Gastown's photos
#!/usr/bin/env ruby
require 'json'
require 'net/http'
require 'pp'
require 'Time'
require 'uri'
require 'parseconfig'
flickr_config = ParseConfig.new('flickr.conf').params
api_key = flickr_config['api_key']
user_id = flickr_config['user_id']
# get photos taken before september 1, 2010
sep12010 = Time.local(2010, 9, 1, 0, 0) # may want Time.utc if you don't want local time
max_taken_date = sep12010.to_i.to_s
woe_id = "26332810" # Gastown http://www.flickr.com/places/info/26332810
tags = "cameraphone%2Cvancouver"
content_type = "1" # photos only
per_page = "250" # geo photos limited by flickr to only 250 per page
extras="original_format,date_taken,geo,tags,o_dims,views,url_sq,url_t,url_s,url_m,url_o" # get all the meta data!
page = 1
def getResponse(url)
http = Net::HTTP.new("api.flickr.com",80)
request = Net::HTTP::Get.new(url)
resp = http.request(request)
if resp.code != "200"
$stderr.puts "Error: #{resp.code} from:#{url}"
raise JSON::ParserError # This is a kludge. Should return a proper exception instead!
end
result = JSON.parse(resp.body)
return result
end
photos_to_retrieve = 250
first_page = true
photos_per_page = 0
while photos_to_retrieve > 0
search_url = "/services/rest/?method=flickr.photos.search&api_key="+api_key+"&format=json&nojsoncallback=1&content_type="+content_type+"&tags="+tags+"&woe_id="+woe_id+"&per_page="+per_page+"&user_id="+user_id+"&extras="+extras+"&max_taken_date="+max_taken_date+"&page="+page.to_s
photos_on_this_page = getResponse(search_url)
if first_page
first_page = false
photos_per_page = photos_on_this_page["photos"]["perpage"].to_i
photos_to_retrieve = photos_on_this_page["photos"]["total"].to_i - photos_per_page
else
photos_to_retrieve -= photos_per_page
end
page += 1
$stderr.puts photos_on_this_page
print JSON.generate(photos_on_this_page)
end
@rtanglao
Owner

you can find the output of this program here:
http://dl.dropbox.com/u/361757/gastownphotos.stdout

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.