Skip to content

Instantly share code, notes, and snippets.

@johndbritton
Created October 1, 2012 01:08
Show Gist options
  • Save johndbritton/3808908 to your computer and use it in GitHub Desktop.
Save johndbritton/3808908 to your computer and use it in GitHub Desktop.
Google calendar to KML
source :rubygems
gem 'dotenv', :groups => [:development, :test]
gem "nokogiri"
gem "geocoder"
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