Home > wwdc > Better Session Script
Better Session Script
Posted on Wednesday, May 27, 2009 by android apps market for tablests
Ryan McCuaig sent me a kick-ass re-write of my WWDC session script. This one outputs the information with much, much better formatting.
Here's the very fine script:
Here's the very fine script:
#!/usr/bin/env ruby
#
# This program will download the latest session JSON data
# from the WWDC website and will parse it into a plain
# HTML table so it can be viewed.
#
# Requires one of the following two gems to be installed:
#
# gem install json
# gem install json_pure
#
# Also requires installation of Haml/Sass:
#
# gem install haml
#
# This script was written by Ryan McCuaig, based on a script by Jeff LaMarche
require 'net/http'
require 'open-uri'
require 'rubygems'
require 'json'
require 'haml'
require 'sass'
JSON_FEED = 'http://developer.apple.com/wwdc/data/sessions.json'
class Session
attr_accessor :title,:focus,:start,:description,:type,:identifier, :room
def initialize(array)
@title = array["title"]
@focus = array["focus"]
@type = array["type"]
@start = Time.parse(array["time"][0]["lower"])
@stop = Time.parse(array["time"][0]["upper"])
@description = array["description"]
@identifier = array["id"]
@room = array["room"]
end
def when
start = @start.strftime("%l:%M %p")
stop = @stop.strftime("%l:%M %p")
[start,stop].map{|x| x.strip}.join("-")
end
end
json_data = open(JSON_FEED).read
parsed_data = JSON.parse(json_data)["SessionsData"]
sessions = []
parsed_data.each do |array|
sessions << Session.new(array)
end
sessions.sort! {|x,y| x.start <=> y.start}
class Array
# group_by doesn't exist before Ruby 1.8.7, drat
def group_by
hash = {}
each do |element|
key = yield(element)
if hash.has_key?(key)
hash[key] << element
else
hash[key] = [element]
end
end
hash
end unless [].respond_to?(:group_by)
end
sessions_grouped_by_day = sessions.group_by {|x| x.start.strftime("%A")}
html_template = <<HTML
!!!
%html
%head
%title Session Times
%style= css
%body
%div#content
- %w{Monday Tuesday Wednesday Thursday Friday}.each do |day|
%h1= day
- days[day].each do |session|
%h2
%div#when= session.when
%div
= session.title
%span.type= session.type
%span.focus= session.focus.join(", ")
%span.identifier= session.identifier
%span.room= session.room
%p= session.description
HTML
css_template = <<CSS
!indent = 150px
#content
:width 800px
:margin-left auto
:margin-right auto
h1,
h2,
p
:font-family Helvetica Neue, Helvetica
h1
:font-size 21px
h2
:font-size 16px
:margin-left 0px
div#when
:position relative
:bottom -3px
:width = !indent
:float left
:font
:weight normal
:size 13px
span
:font
:weight normal
:size 13px
:padding 0 0.5em 0 0.5em
&.type
:color red
&.focus
:color green
&.identifier
:color blue
&.room
:font
:weight bold
:size 14px
:color grey
p
:font-size 13px
:line-height 21px
:margin-left = !indent
CSS
html_engine = Haml::Engine.new(html_template)
css_engine = Sass::Engine.new(css_template)
File.open("/tmp/wwdc_sessions.html",'w') do |file|
file.write html_engine.render(Object.new,
:days=>sessions_grouped_by_day,:css=>css_engine.render)
end
`open /tmp/wwdc_sessions.html`Category Article wwdc
Powered by Blogger.
Blog Archive
-
▼
2009
(496)
-
▼
May
(55)
- Another List for WWDC First-Timers
- Nearby Intersections on GOOG-411
- Nearby Intersections on GOOG-411
- Part 6
- WWDC Session Data Now Available at Attendee Site
- WWDC Session Data is Gone
- WWDC JSON Credit
- Another iCal Script
- WWDC Session Times for iCal Import
- Better Session Script
- WWDC Session Times
- Another Party, RSVP Required
- Multitouch on a MacBook
- Yet Another WWDC Party List
- OpenGL ES From the Ground Up, Part 6: Textures and...
- Mini Picture Sudoku Gadget
- Wolf Shirt Update
- Wolf Shirts
- Concurrent Operations (aka Threading)
- Google Sync Beta - Now for S60
- Google Sync Beta - Now for S60
- WWDC Party List
- Device Detection
- Yahoo Limits Mobile Development to One Platform
- iPhone Intelligence Party
- The Iterative Web App - Gmail for Mobile Gets Labels
- The Iterative Web App - Gmail for Mobile Gets Labels
- Nokia N Series: Highly innovated devices
- Meet the Nokia N97 and its smartphone rivals
- Just for the Record
- Feed Changes
- Dick Move - iwyre.net
- Google Product Search for Android now with Barcode...
- Google Product Search for Android now with Barcode...
- WWDC First Timer's Guide Redux
- OpenGL ES From the Ground Up, Part 5: Living in a ...
- Behind the scenes of the NYC - Google mapping part...
- Behind the scenes of the NYC - Google mapping part...
- No Steve-Note
- Sky Map for Android - A Mobile Planetarium
- Sky Map for Android - A Mobile Planetarium
- GoGadget
- Cheeky Quote Gadget
- YouTube uploads and more now available on Android
- YouTube uploads and more now available on Android
- Procedural Spheres in OpenGL ES
- New BlackBerry Enterprise Server Packages for Goog...
- New BlackBerry Enterprise Server Packages for Goog...
- Use Google Apps seamlessly with corporate BlackBer...
- Use Google Apps seamlessly with corporate BlackBer...
- Do more with Google Latitude!
- Do more with Google Latitude!
- OpenGL ES From the Ground Up, Part 1 Addendum: Alp...
- setupView: from Part IV Rewritten
- OpenGL ES From the Ground Up, Part 4: Let There Be...
-
▼
May
(55)