Created
November 16, 2008 16:38
-
-
Save ajturner/25508 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%w{rubygems flickraw yaml}.each {|gem| require gem} | |
options = {:per_page => 100, :tags => "baytobreakers", :woe_id => 2487956, :min_taken_date => "2007-05-20", :max_taken_date => "2007-05-21"} | |
list = flickr.photos.search({:page => 1}.merge(options)) | |
puts list.pages | |
kml = %Q{<?xml version="1.0" encoding="UTF-8"?> | |
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom"> | |
<Document> | |
<name>Bay to Breakers</name> | |
<open>1</open> | |
<Style id="b2bBalloonStyle"> | |
<BalloonStyle> | |
<bgColor>ffffffFF</bgColor> | |
<text><![CDATA[ | |
<img src="$[image_url]" style="float:right;padding:5px" align="right" hspace="5px"/> | |
<b><font color="#FF6600" size="+3">$[name]</font></b> | |
<br/><br/> | |
$[description] | |
<br/><br/> | |
Taken by: $[author] | |
<br/><br/> | |
Taken at: $[taken] | |
<br/><br/> | |
Tags: $[tags] | |
<br/><br/> | |
<a href="\#$[prev]">Previous</a> | |
<a href="\#$[next]">Next</a> | |
]]></text> | |
</BalloonStyle> | |
</Style> | |
} | |
(1..list.pages).each do |page| | |
puts page | |
list = flickr.photos.search({:page => page}.merge(options)) unless page == 0 | |
list.each_with_index do |photo, i| | |
info = flickr.photos.getInfo :photo_id => photo.id, :secret => photo.secret | |
sizes = flickr.photos.getSizes(:photo_id => photo.id) | |
original = sizes.find {|s| s.label == 'Medium' }.source.gsub(/ /,'').gsub(/\\/,'') | |
thumb = sizes.find {|s| s.label == 'Thumbnail' }.source.gsub(/ /,'').gsub(/\\/,'') | |
taken = info.dates.taken.gsub(/ (\d\d): /, 'T\1:').gsub(/ /,'') | |
location = %w{info.location.locality info.location.region info.location.country}.join(", ") if info.respond_to?(:location) | |
kml << %Q{<Placemark id="baytobreakers_#{i}"> | |
<name>#{info.title.gsub(/&/,'&')}</name> | |
<description><![CDATA[#{info.description.gsub(/&/,'&')}]]></description> | |
<Style> | |
<IconStyle> | |
<Icon> | |
<href>#{thumb}</href> | |
</Icon> | |
</IconStyle> | |
</Style> | |
<styleUrl>#b2bBalloonStyle</styleUrl> | |
<Point> | |
<coordinates>#{info.location.longitude},#{info.location.latitude},0</coordinates> | |
</Point> | |
<ExtendedData> | |
<Data name="tags"> | |
<value>#{info.tags.join(", ")}</value> | |
</Data> | |
<Data name="author"> | |
<value>#{info.owner.username}</value> | |
</Data> | |
<Data name="taken"> | |
<value>#{taken}</value> | |
</Data> | |
<Data name="image_url"> | |
<value>#{original}</value> | |
</Data> | |
<Data name="prev"> | |
<value>baytobreakers_#{i-1}</value> | |
</Data> | |
<Data name="next"> | |
<value>baytobreakers_#{i+1}</value> | |
</Data> | |
</ExtendedData> | |
<atom:author> | |
<atom:name>#{info.owner.username}</atom:name> | |
</atom:author> | |
<atom:link href="#{info.urls[0].gsub(/ /,'').gsub(/\\/,'')}" /> | |
<address>#{location}</address> | |
<TimeStamp> | |
<when>#{taken}</when> | |
</TimeStamp> | |
</Placemark> | |
} | |
end | |
end | |
kml << %Q{</Document> | |
</kml>} | |
File.open("baytobreakers.kml", "w") {|file| file << kml } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment