Created
October 1, 2012 01:08
-
-
Save johndbritton/3808908 to your computer and use it in GitHub Desktop.
Google calendar to KML
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
source :rubygems | |
gem 'dotenv', :groups => [:development, :test] | |
gem "nokogiri" | |
gem "geocoder" |
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
require 'dotenv' | |
require 'open-uri' | |
require 'nokogiri' | |
require 'geocoder' | |
def kml_from_xml(google_calendar_xml_url) | |
data = open google_calendar_xml_url | |
feed = Nokogiri::XML data | |
builder = Nokogiri::XML::Builder.new do | |
kml('xmlns' => 'http://www.opengis.net/kml/2.2') do | |
Document do | |
feed.css('entry').each do |event| | |
title = event.css('title').inner_text | |
where = event.css('gd|where').attribute('valueString') | |
geo = Geocoder.search(where).first | |
Placemark do | |
name title | |
description title | |
Point do | |
coordinates "#{geo.coordinates[1]},#{geo.coordinates[0]}" | |
end | |
end | |
end | |
end | |
end | |
end | |
builder.to_xml | |
end | |
Dotenv.load | |
puts kml_from_xml(ENV['CALENDAR_URL']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment