The Shining Path of Least Resistance

LeastResistance.Net

BarCamp Austin Presentation, Part 1

Posted by mattray on March 19, 2008

I recently attended the third Austin BarCamp and gave a brief presentation on “Hacking iCal and Python”. Since I was in the process of learning Python, and there seemed to be a dearth of technical subjects (lots of social media type stuff), I figured I’d look for a presentation subject.

Thursday night before BarCamp (Saturday) I started brainstorming. There it was, the BarCamp Schedule, a wiki of presentations and times, updated regularly with planned presentations. I figured I could write a script to parse it, convert it to iCal format and publish it and everyone would have access to an up-to-date schedule and sync it to their iCal/iPhone/Google calendar. Plus I’d get a presentation that I’d like to see myself.

Coding
So I started cracking on the download and parse section, with preliminary support done that night. The curl call turned into

opener = urllib.FancyURLopener({})
webpage = opener.open("http://barcamp.org/BarCampAustinIIISchedule")
html = webpage.readlines()

Pretty simple. The schedule was broken into sections separated by the name of the rooms, so I simply used the hard-coded room names to find which schedule I was in and keep reading in <li> schedule elements until I found the next room. Look for the string “Page Information” and I knew I was at the end of the schedule block. So far so good.

Parsing the individual lines should have been done with a regex. But I didn’t start on this until Friday afternoon and I had dinner plans and was pretty busy with my day job. So I used a bunch of string operations like split and find and indexes into the string, since I knew all the strings were in the format:

<li>2:00pm - 3:00pm - Twitter - Alex Payne, Blaine Cook, and Ben Fullerton</li>

So I went to dinner the night before BarCamp without having written the iCal export section yet. A couple of margaritas later I found I still had some coding to do, and I didn’t much feel like trying to figure out how the various libraries worked, so I kept googling for “python ical export” and looking for the one with the best documentation and examples (that’s developer laziness for you). The winner was iCalendar, a perfectly functional and well-documented Python library that worked as advertised. I filled in the required fields, tested it with iCal and went to bed.

Bugs
BarCamp started at 10am, so around 9 I figured I’d checkup on my script to put it on a cron job and put it somewhere public. So I kicked it off and refreshed my calendar in iCal. Now there were 2 copies of every entry. That’s not good.

I looked through the RFC 2445 and realized I wasn’t using a unique ID for each calendar event, so I was getting duplicates. No problem, just changed the counter to count by presentation time slots and that cleared it all up. Problem solved! Or so I thought.

9:15
I then noticed that some of the entries had junk HTML formatting in them, since the iCal entries weren’t rendering them. So I googled for “python strip html” and came across this solution, which worked immediately. I don’t know if Python is the right language for everything, but it certainly is one of the easiest to find quick solutions.

9:30
I reran the script and refreshed, only to notice that 80% of the presentations were all in the same room. A quick scan of the page showed that one of the rooms had disappeared (it turned into an iPhone DevCamp overnight). Quickly fixed that, and everything seemed fine. Put the calendar up on a public server, setup a cron job to publish, added it to the schedule and headed off to BarCamp.

…to be continued.

Advertisements

One Response to “BarCamp Austin Presentation, Part 1”

  1. […] by mray on March 27, 2008 Picking up where I left off, my Python screen scraper was working, iCal events were getting published for general consumption […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: