Wednesday, May 27, 2009

WWDC Session Times for iCal Import

Posted by hiday81 at 12:22 PM
Here's a quick-and-dirty hack of the WWDC session script to create an iCalendar file that can be imported into iCal.
Again, this is public domain, feel free to hack away and improve it.

#!/usr/bin/env ruby
#
# This program will download the latest session JSON data
# from the WWDC website and turn it into an iCal
#
# Sorry about the cheezy HTML formatting; I am not a designer.
# If you'd like to contribute a better looking design, I'll
# incorporate it.
#
# Requires one of the following two gems to be installed:
#
# gem install json
# gem install json_pure
require 'rubygems'
require 'net/http'
require 'open-uri'
require 'json'
require 'date'

output = <<OUTPUT
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//hacksw/handcal//NONSGML v1.0//EN
OUTPUT


r = open("http://developer.apple.com/wwdc/data/sessions.json").read

parsed = JSON.parse r
data = parsed["SessionsData"]

data.each do | oneSession |

upperTime = DateTime.parse(oneSession["time"][0]["upper"])
lowerTime = DateTime.parse(oneSession["time"][0]["lower"])
output << "BEGIN:VEVENT\n"
output << lowerTime.strftime("DTSTART;TZID=US/Pacific:%Y%m%dT%H%M%S\n");
output << upperTime.strftime("DTEND;TZID=US/Pacific:%Y%m%dT%H%M%S\n");
output << "DESCRIPTION:#{oneSession["description"]}\n"
output << "LOCATION:#{oneSession["room"]}\n"
output << "SUMMARY:#{oneSession["title"]} (#{oneSession["id"].to_s})\n"

# output << "<TR>"
# output << "<TD>#{oneSession["id"]}</TD><TD>#{oneSession["title"].to_s}</TD><TD>#{oneSession["focus"].to_s}</TD><TD>#{oneSession["level"].to_s}</TD><TD>#{oneSession["type"].to_s}</TD><TD WIDTH = \"200\">Start: #{lowerTime.to_s} <BR/>End: #{upperTime.to_s}</TD><TD>#{oneSession["room"].to_s}</TD><TD>#{oneSession["description"].to_s}</TD></TR>\n"
#

output << "END:VEVENT\n"
end
output << "END:VCALENDAR"

File.open("sessions.ics", 'w') {|f| f.write(output) }

0 comments:

Post a Comment

Related Post

 

Copyright © 2011 Next Iphone | Store Mobile Phone Store